Skip to content

Commit 669bb61

Browse files
committed
feat(ChromeTestConductor): execute tests in hidden documents
1 parent 6228dd6 commit 669bb61

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/conductor/ChromeTestConductor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export class ChromeTestConductor extends TestConductor {
2222
}),
2323
) {
2424
super(title, setupFiles, coverageVar)
25+
26+
this.defaultPage = browser.then(b => b.newPage())
2527
}
28+
protected defaultPage
2629

2730
readonly reporterServer = new HttpReporterServer()
2831

@@ -92,6 +95,8 @@ await new TestRunner(
9295
)
9396
`
9497

98+
await (await this.defaultPage).bringToFront()
99+
95100
await page.setContent(`<html><head><script type="module">${childCode}</script>`)
96101

97102
await donePromise

test/conductor/ChromeTestConductor.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test('conduct test', async () => {
4747
expect(getTestFunction(suite, 2)).toHaveProperty('title', 'failing test')
4848
expect(getTestFunction(suite, 2).result.get()).toHaveProperty('type', 'fail')
4949

50-
expect((await (await conductor.browser).pages()).length).toBe(0)
50+
expect((await (await conductor.browser).pages()).length).toBe(1)
5151
}, generousTimeout)
5252

5353
test('abort test', async () => {
@@ -73,3 +73,19 @@ test('abort test', async () => {
7373
expect(getTestFunction(suite, 1).result.get()).toHaveProperty('type', 'success')
7474
expect(getTestFunction(suite, 2).result.get()).toBe(undefined)
7575
}, generousTimeout)
76+
77+
test('document is hidden', async () => {
78+
const {conductor, fileServer} = await setupConductor()
79+
fileServer.provider.files.set('checkVisibility.js', Promise.resolve({content: `
80+
if (document.visibilityState !== 'hidden') {
81+
throw new Error('document.visibilityState is: ' + document.visibilityState)
82+
}
83+
`}))
84+
const suiteUrl = String(await fileServer.url) + 'checkVisibility.js'
85+
const run = createTestRun([conductor], [{url: suiteUrl, title: 'visibilityState'}])
86+
const suite = run.runs.get(conductor)!.suites.get(suiteUrl)!
87+
88+
await suite.exec().catch(() => void 0)
89+
90+
expect(suite.errors[Symbol.iterator]().next().value?.message).toBe(undefined)
91+
})

0 commit comments

Comments
 (0)