-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from pixijs/511-setup-e2e-testing
Setup e2e testing
- Loading branch information
Showing
13 changed files
with
10,390 additions
and
7,738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { ReactNode } from 'react' | ||
import { | ||
describe, | ||
expect, | ||
it, | ||
} from 'vitest'; | ||
import { | ||
render, | ||
renderHook, | ||
} from '@testing-library/react' | ||
import { Application as PixiApplication } from 'pixi.js'; | ||
|
||
import { Application } from '../../../src/components/Application.ts' | ||
import { useApplication } from '../../../src/hooks/useApplication.ts' | ||
|
||
describe('useApplication', () => | ||
{ | ||
it('returns the nearest application', async () => | ||
{ | ||
let initApp: PixiApplication | null = null | ||
let testApp: PixiApplication | null = null | ||
|
||
const TestComponentWrapper = (props: { | ||
children?: ReactNode, | ||
}) => { | ||
const { children } = props | ||
|
||
const handleInit = (app: PixiApplication) => (initApp = app) | ||
|
||
return ( | ||
<Application onInit={handleInit}> | ||
{children} | ||
</Application> | ||
) | ||
} | ||
|
||
const TestComponent = () => { | ||
const { app } = useApplication() | ||
|
||
if (app) { | ||
testApp = app | ||
} | ||
|
||
return null | ||
} | ||
|
||
render(<TestComponent />, { | ||
wrapper: TestComponentWrapper, | ||
}) | ||
|
||
await new Promise<void>(resolve => { | ||
let intervalID = setInterval(() => { | ||
if (initApp) { | ||
clearInterval(intervalID) | ||
setTimeout(resolve, 10) | ||
} | ||
}, 10) | ||
}) | ||
|
||
expect(testApp).to.equal(initApp) | ||
}) | ||
|
||
it('throws when not in a React Pixi tree', () => | ||
{ | ||
expect(() => renderHook(() => useApplication())).to.throw(Error, /no context found/i) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
describe, | ||
expect, | ||
it, | ||
vi, | ||
} from 'vitest'; | ||
import { | ||
render, | ||
renderHook, | ||
} from '@testing-library/react' | ||
import { Ticker } from 'pixi.js'; | ||
|
||
import { Application } from '../../../src/components/Application' | ||
import { useTick } from '../../../src/hooks/useTick' | ||
import { wait } from '../../utils/wait' | ||
|
||
describe('useTick', () => | ||
{ | ||
describe('with a function', () => { | ||
it('runs the callback', async () => { | ||
const useTickSpy = vi.fn() | ||
|
||
const TestComponent = () => { | ||
useTick(useTickSpy) | ||
|
||
return null | ||
} | ||
|
||
render(<TestComponent />, { wrapper: Application }) | ||
|
||
await wait(100) | ||
|
||
expect(useTickSpy.mock.lastCall?.[0]).to.be.instanceOf(Ticker) | ||
}); | ||
}) | ||
|
||
describe('with an options hash', () => { | ||
it('runs the callback', async () => { | ||
const useTickSpy = vi.fn() | ||
|
||
const TestComponent = () => { | ||
useTick({ callback: useTickSpy }) | ||
|
||
return null | ||
} | ||
|
||
render(<TestComponent />, { wrapper: Application }) | ||
|
||
await wait(100) | ||
|
||
expect(useTickSpy.mock.lastCall?.[0]).to.be.instanceOf(Ticker) | ||
}); | ||
}) | ||
|
||
it('throws when not in a React Pixi tree', () => | ||
{ | ||
const result = () => renderHook(() => useTick(() => {})) | ||
|
||
expect(result).to.throw(Error, /no context found/i) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function wait(waitMS: number, rejectOnComplete: boolean = false) | ||
{ | ||
return new Promise((resolve, reject) => | ||
{ | ||
setTimeout(rejectOnComplete ? reject : resolve, waitMS); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { afterEach } from 'vitest'; | ||
import '@testing-library/jest-dom/vitest'; | ||
import { cleanup } from '@testing-library/react'; | ||
|
||
afterEach(() => | ||
{ | ||
cleanup(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
import { defineWorkspace } from 'vitest/config'; | ||
import react from '@vitejs/plugin-react'; | ||
|
||
export default defineWorkspace([ | ||
{ | ||
plugins: [react()], | ||
test: { | ||
environment: 'jsdom', | ||
include: ['test/unit/**/*.test.ts?(x)'], | ||
pool: 'forks', | ||
}, | ||
}, | ||
{ | ||
plugins: [react()], | ||
test: { | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
provider: 'playwright', | ||
}, | ||
globals: true, | ||
include: ['test/e2e/**/*.test.ts(x)'], | ||
setupFiles: [ | ||
'./vitest.setup.ts' | ||
], | ||
}, | ||
}, | ||
]); |