|
1 | 1 | import fs from 'fs'
|
2 | 2 | import path from 'path'
|
3 |
| -import type { Page } from 'playwright-chromium' |
4 | 3 | import { isBuild, page, testDir, untilUpdated } from '~utils'
|
5 | 4 |
|
6 | 5 | test('normal', async () => {
|
7 |
| - await page.click('.ping') |
8 |
| - await untilUpdated(() => page.textContent('.pong'), 'pong') |
| 6 | + await untilUpdated(() => page.textContent('.pong'), 'pong', true) |
9 | 7 | await untilUpdated(
|
10 | 8 | () => page.textContent('.mode'),
|
11 |
| - process.env.NODE_ENV // match workerImport.js |
| 9 | + process.env.NODE_ENV, |
| 10 | + true |
12 | 11 | )
|
13 | 12 | await untilUpdated(
|
14 | 13 | () => page.textContent('.bundle-with-plugin'),
|
15 |
| - 'worker bundle with plugin success!' |
| 14 | + 'worker bundle with plugin success!', |
| 15 | + true |
16 | 16 | )
|
17 | 17 | })
|
18 | 18 |
|
19 | 19 | test('TS output', async () => {
|
20 |
| - await page.click('.ping-ts-output') |
21 |
| - await untilUpdated(() => page.textContent('.pong-ts-output'), 'pong') |
| 20 | + await untilUpdated(() => page.textContent('.pong-ts-output'), 'pong', true) |
22 | 21 | })
|
23 | 22 |
|
24 | 23 | test('inlined', async () => {
|
25 |
| - await page.click('.ping-inline') |
26 |
| - await untilUpdated(() => page.textContent('.pong-inline'), 'pong') |
| 24 | + await untilUpdated(() => page.textContent('.pong-inline'), 'pong', true) |
27 | 25 | })
|
28 | 26 |
|
29 |
| -const waitSharedWorkerTick = ( |
30 |
| - (resolvedSharedWorkerCount: number) => async (page: Page) => { |
31 |
| - await untilUpdated(async () => { |
32 |
| - const count = await page.textContent('.tick-count') |
33 |
| - // ignore the initial 0 |
34 |
| - return count === '1' ? 'page loaded' : '' |
35 |
| - }, 'page loaded') |
36 |
| - // test.concurrent sequential is not guaranteed |
37 |
| - // force page to wait to ensure two pages overlap in time |
38 |
| - resolvedSharedWorkerCount++ |
39 |
| - if (resolvedSharedWorkerCount < 2) return |
40 |
| - |
41 |
| - await untilUpdated(() => { |
42 |
| - return resolvedSharedWorkerCount === 2 ? 'all pages loaded' : '' |
43 |
| - }, 'all pages loaded') |
44 |
| - } |
45 |
| -)(0) |
46 |
| - |
47 |
| -test.each([[true], [false]])('shared worker', async (doTick) => { |
48 |
| - if (doTick) { |
49 |
| - await page.click('.tick-shared') |
50 |
| - } |
51 |
| - await waitSharedWorkerTick(page) |
| 27 | +test('shared worker', async () => { |
| 28 | + await untilUpdated(() => page.textContent('.tick-count'), 'pong', true) |
52 | 29 | })
|
53 | 30 |
|
54 | 31 | test('worker emitted and import.meta.url in nested worker (serve)', async () => {
|
55 |
| - expect(await page.textContent('.nested-worker')).toMatch( |
56 |
| - 'worker-nested-worker' |
| 32 | + await untilUpdated( |
| 33 | + () => page.textContent('.nested-worker'), |
| 34 | + 'worker-nested-worker', |
| 35 | + true |
57 | 36 | )
|
58 |
| - expect(await page.textContent('.nested-worker-module')).toMatch('sub-worker') |
59 |
| - expect(await page.textContent('.nested-worker-constructor')).toMatch( |
60 |
| - '"type":"constructor"' |
| 37 | + await untilUpdated( |
| 38 | + () => page.textContent('.nested-worker-module'), |
| 39 | + 'sub-worker', |
| 40 | + true |
| 41 | + ) |
| 42 | + await untilUpdated( |
| 43 | + () => page.textContent('.nested-worker-constructor'), |
| 44 | + '"type":"constructor"', |
| 45 | + true |
61 | 46 | )
|
62 | 47 | })
|
63 | 48 |
|
@@ -87,45 +72,73 @@ describe.runIf(isBuild)('build', () => {
|
87 | 72 | })
|
88 | 73 |
|
89 | 74 | test('worker emitted and import.meta.url in nested worker (build)', async () => {
|
90 |
| - expect(await page.textContent('.nested-worker-module')).toMatch( |
91 |
| - '"type":"module"' |
| 75 | + await untilUpdated( |
| 76 | + () => page.textContent('.nested-worker-module'), |
| 77 | + '"type":"module"', |
| 78 | + true |
92 | 79 | )
|
93 |
| - expect(await page.textContent('.nested-worker-constructor')).toMatch( |
94 |
| - '"type":"constructor"' |
| 80 | + await untilUpdated( |
| 81 | + () => page.textContent('.nested-worker-constructor'), |
| 82 | + '"type":"constructor"', |
| 83 | + true |
95 | 84 | )
|
96 | 85 | })
|
97 | 86 | })
|
98 | 87 |
|
99 | 88 | test('module worker', async () => {
|
100 |
| - expect(await page.textContent('.shared-worker-import-meta-url')).toMatch( |
101 |
| - 'A string' |
| 89 | + await untilUpdated( |
| 90 | + () => page.textContent('.shared-worker-import-meta-url'), |
| 91 | + 'A string', |
| 92 | + true |
102 | 93 | )
|
103 | 94 | })
|
104 | 95 |
|
105 | 96 | test('classic worker', async () => {
|
106 |
| - expect(await page.textContent('.classic-worker')).toMatch('A classic') |
107 |
| - expect(await page.textContent('.classic-shared-worker')).toMatch('A classic') |
| 97 | + await untilUpdated( |
| 98 | + () => page.textContent('.classic-worker'), |
| 99 | + 'A classic', |
| 100 | + true |
| 101 | + ) |
| 102 | + await untilUpdated( |
| 103 | + () => page.textContent('.classic-shared-worker'), |
| 104 | + 'A classic', |
| 105 | + true |
| 106 | + ) |
108 | 107 | })
|
109 | 108 |
|
110 | 109 | test('emit chunk', async () => {
|
111 |
| - expect(await page.textContent('.emit-chunk-worker')).toMatch( |
112 |
| - '["A string",{"type":"emit-chunk-sub-worker","data":"A string"},{"type":"module-and-worker:worker","data":"A string"},{"type":"module-and-worker:module","data":"module and worker"},{"type":"emit-chunk-sub-worker","data":{"module":"module and worker","msg1":"module1","msg2":"module2","msg3":"module3"}}]' |
| 110 | + await untilUpdated( |
| 111 | + () => page.textContent('.emit-chunk-worker'), |
| 112 | + '["A string",{"type":"emit-chunk-sub-worker","data":"A string"},{"type":"module-and-worker:worker","data":"A string"},{"type":"module-and-worker:module","data":"module and worker"},{"type":"emit-chunk-sub-worker","data":{"module":"module and worker","msg1":"module1","msg2":"module2","msg3":"module3"}}]', |
| 113 | + true |
113 | 114 | )
|
114 |
| - expect(await page.textContent('.emit-chunk-dynamic-import-worker')).toMatch( |
115 |
| - '"A string/es/"' |
| 115 | + await untilUpdated( |
| 116 | + () => page.textContent('.emit-chunk-dynamic-import-worker'), |
| 117 | + '"A string/es/"', |
| 118 | + true |
116 | 119 | )
|
117 | 120 | })
|
118 | 121 |
|
119 | 122 | test('url query worker', async () => {
|
120 |
| - expect(await page.textContent('.simple-worker-url')).toMatch( |
121 |
| - 'Hello from simple worker!' |
| 123 | + await untilUpdated( |
| 124 | + () => page.textContent('.simple-worker-url'), |
| 125 | + 'Hello from simple worker!', |
| 126 | + true |
122 | 127 | )
|
123 | 128 | })
|
124 | 129 |
|
125 | 130 | test('import.meta.glob in worker', async () => {
|
126 |
| - expect(await page.textContent('.importMetaGlob-worker')).toMatch('["') |
| 131 | + await untilUpdated( |
| 132 | + () => page.textContent('.importMetaGlob-worker'), |
| 133 | + '["', |
| 134 | + true |
| 135 | + ) |
127 | 136 | })
|
128 | 137 |
|
129 | 138 | test('import.meta.glob with eager in worker', async () => {
|
130 |
| - expect(await page.textContent('.importMetaGlobEager-worker')).toMatch('["') |
| 139 | + await untilUpdated( |
| 140 | + () => page.textContent('.importMetaGlobEager-worker'), |
| 141 | + '["', |
| 142 | + true |
| 143 | + ) |
131 | 144 | })
|
0 commit comments