Skip to content

Commit

Permalink
chore: logs
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Apr 11, 2024
1 parent 773ca39 commit 6f7bfdb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
main:
runs-on: macos-14
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: 'yarn'
- run: yarn install
- run: yarn build-storybook
- run: yarn install --frozen-lockfile
- run: yarn test
- run: yarn build-storybook
# semantic-release skips not configured branches(see: release.config.js) or pull-requests
- run: yarn release
env:
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Canvas } from '@react-three/fiber'
import { Sphere, Environment, CameraControls } from '@react-three/drei' // eslint-disable-line import/no-unresolved

function App() {
console.log('App')

return (
<Canvas camera={{ position: [1, 1, 1] }} style={{ width: 300, height: 150, background: 'white' }}>
<Suspense fallback={null}>
Expand All @@ -16,6 +18,8 @@ function App() {

function Scene() {
useEffect(() => {
console.log('useEffect')

document.dispatchEvent(new Event('puppeteer:r3f'))
}, [])

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ appname=viteapp
appdir="$tmp/$appname"

# create app
(cd $tmp; npm create vite@latest $appname -- --template react)
(cd $tmp; npm create -y vite@latest $appname -- --template react)

# drei
(cd $appdir; npm i; npm i $TGZ)
Expand Down
50 changes: 37 additions & 13 deletions test/e2e/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ expect.extend({ toMatchImageSnapshot })

const host = 'http://localhost:5188/'

const TIMEOUT = 10000

async function waitForEvent(page, eventName) {
await page.evaluate(
(eventName) => new Promise((resolve) => document.addEventListener(eventName, resolve, { once: true })),
Expand All @@ -31,26 +33,48 @@ describe('snapshot', () => {
let page
beforeAll(async () => {
await waitForServer()
console.log('server ok')

const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH
console.log('executablePath', executablePath)

const args = ['--hide-scrollbars', '--enable-gpu']

browser = await puppeteer.launch({
headless: 'new',
executablePath: process.env.CHROMEWEBDRIVER,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
executablePath,
args,
})
console.log('browser ok')

page = await browser.newPage()
}, 30000)
console.log('page ok')

it('should match previous one', async () => {
// ⏳ "r3f" event
await page.goto(host)
await waitForEvent(page, 'puppeteer:r3f')
page.on('console', (message) => console.log(`Page log: ${message.text()}`))
}, TIMEOUT)

// 📸 <canvas>
const $canvas = await page.$('canvas[data-engine]')
const image = await $canvas.screenshot()
it(
'should match previous one',
async () => {
// ⏳ "r3f" event
await page.goto(host)
console.log('goto ok')

// compare
expect(image).toMatchImageSnapshot({})
}, 30000)
await waitForEvent(page, 'puppeteer:r3f')
console.log('event ok')

// 📸 <canvas>
const $canvas = await page.$('canvas[data-engine]')
const image = await $canvas.screenshot()

// compare
expect(image).toMatchImageSnapshot({
// failureThreshold: 1,
// failureThresholdType: 'percent',
})
},
TIMEOUT
)

afterAll(async () => {
await browser?.close()
Expand Down

0 comments on commit 6f7bfdb

Please sign in to comment.