Skip to content

Commit 9893b6e

Browse files
committed
Increase timeout for flaky tests
1 parent 8de880f commit 9893b6e

File tree

6 files changed

+118
-86
lines changed

6 files changed

+118
-86
lines changed

programs/develop/__spec__/build.spec.ts

Lines changed: 89 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -81,95 +81,105 @@ describe('extension build', () => {
8181
...ALL_TEMPLATES.filter(
8282
(t) => !t.name.includes('tailwind') && !t.name.includes('custom-font')
8383
)
84-
])(`builds an extension created via "$name" template`, async (template) => {
85-
const templatePath = path.resolve(repoRoot, 'examples', template.name)
84+
])(
85+
`builds an extension created via "$name" template`,
86+
async (template) => {
87+
const templatePath = path.resolve(repoRoot, 'examples', template.name)
8688

87-
// Ensure a clean dist before building this template in case of prior runs
88-
await removeDir(path.join(templatePath, 'dist'))
89-
await extensionBuild(templatePath, {
90-
browser: SUPPORTED_BROWSERS[0] as 'chrome'
91-
})
89+
// Ensure a clean dist before building this template in case of prior runs
90+
await removeDir(path.join(templatePath, 'dist'))
91+
await extensionBuild(templatePath, {
92+
browser: SUPPORTED_BROWSERS[0] as 'chrome'
93+
})
9294

93-
{
94-
const manifestPath = path.join(
95-
templatePath,
96-
'dist',
97-
SUPPORTED_BROWSERS[0],
98-
'manifest.json'
99-
)
100-
// Retry a few times in case of slow FS writes
101-
let exists = fs.existsSync(manifestPath)
102-
if (!exists) {
103-
for (let i = 0; i < 5 && !exists; i++) {
104-
await new Promise((r) => setTimeout(r, 50))
105-
exists = fs.existsSync(manifestPath)
95+
{
96+
const manifestPath = path.join(
97+
templatePath,
98+
'dist',
99+
SUPPORTED_BROWSERS[0],
100+
'manifest.json'
101+
)
102+
// Retry for up to ~10s in case of slow FS writes
103+
let exists = fs.existsSync(manifestPath)
104+
if (!exists) {
105+
const start = Date.now()
106+
while (!exists && Date.now() - start < 10000) {
107+
await new Promise((r) => setTimeout(r, 50))
108+
exists = fs.existsSync(manifestPath)
109+
}
106110
}
111+
expect(exists).toBeTruthy()
107112
}
108-
expect(exists).toBeTruthy()
109-
}
110-
111-
const manifestText = fs.readFileSync(
112-
path.join(templatePath, 'dist', SUPPORTED_BROWSERS[0], 'manifest.json'),
113-
'utf-8'
114-
)
115113

116-
const manifest: Manifest = JSON.parse(manifestText)
117-
expect(manifest.name).toBeTruthy()
118-
expect(manifest.version).toBeTruthy()
119-
expect(manifest.manifest_version).toBeTruthy()
120-
121-
// Validate expected HTML entry points when declared in manifest
122-
const distDir = path.join(templatePath, 'dist', SUPPORTED_BROWSERS[0])
123-
const ensureFile = (relPath: string | undefined) => {
124-
if (!relPath) return
125-
const absPath = path.join(distDir, relPath)
126-
expect(fs.existsSync(absPath)).toBeTruthy()
127-
}
128-
// action popup
129-
ensureFile((manifest as any).action?.default_popup)
130-
// options ui (v3) / options page (v2)
131-
ensureFile((manifest as any).options_ui?.page)
132-
ensureFile((manifest as any).options_page)
133-
// devtools
134-
ensureFile((manifest as any).devtools_page)
135-
// chrome_url_overrides
136-
const overrides = (manifest as any).chrome_url_overrides
137-
if (overrides) {
138-
ensureFile(overrides.newtab)
139-
ensureFile(overrides.history)
140-
ensureFile(overrides.bookmarks)
141-
}
142-
// sandbox pages
143-
const sandboxPages: string[] | undefined = (manifest as any).sandbox
144-
?.pages
145-
if (Array.isArray(sandboxPages) && sandboxPages.length > 0) {
146-
ensureFile(sandboxPages[0])
147-
}
148-
149-
if (template.name.includes('content')) {
150-
expect(manifest.content_scripts![0].js![0]).toEqual(
151-
'content_scripts/content-0.js'
114+
const manifestText = fs.readFileSync(
115+
path.join(
116+
templatePath,
117+
'dist',
118+
SUPPORTED_BROWSERS[0],
119+
'manifest.json'
120+
),
121+
'utf-8'
152122
)
153123

154-
expect(
155-
distFileExists(
156-
template.name,
157-
SUPPORTED_BROWSERS[0],
124+
const manifest: Manifest = JSON.parse(manifestText)
125+
expect(manifest.name).toBeTruthy()
126+
expect(manifest.version).toBeTruthy()
127+
expect(manifest.manifest_version).toBeTruthy()
128+
129+
// Validate expected HTML entry points when declared in manifest
130+
const distDir = path.join(templatePath, 'dist', SUPPORTED_BROWSERS[0])
131+
const ensureFile = (relPath: string | undefined) => {
132+
if (!relPath) return
133+
const absPath = path.join(distDir, relPath)
134+
expect(fs.existsSync(absPath)).toBeTruthy()
135+
}
136+
// action popup
137+
ensureFile((manifest as any).action?.default_popup)
138+
// options ui (v3) / options page (v2)
139+
ensureFile((manifest as any).options_ui?.page)
140+
ensureFile((manifest as any).options_page)
141+
// devtools
142+
ensureFile((manifest as any).devtools_page)
143+
// chrome_url_overrides
144+
const overrides = (manifest as any).chrome_url_overrides
145+
if (overrides) {
146+
ensureFile(overrides.newtab)
147+
ensureFile(overrides.history)
148+
ensureFile(overrides.bookmarks)
149+
}
150+
// sandbox pages
151+
const sandboxPages: string[] | undefined = (manifest as any).sandbox
152+
?.pages
153+
if (Array.isArray(sandboxPages) && sandboxPages.length > 0) {
154+
ensureFile(sandboxPages[0])
155+
}
156+
157+
if (template.name.includes('content')) {
158+
expect(manifest.content_scripts![0].js![0]).toEqual(
158159
'content_scripts/content-0.js'
159160
)
160-
).toBeTruthy()
161-
}
162161

163-
// Basic asset sanity: icons and optional assets folder when present
164-
expect(fs.existsSync(path.join(distDir, 'icons'))).toBeTruthy()
165-
// When assets exist, ensure at least one file is emitted
166-
const assetsDir = path.join(distDir, 'assets')
167-
if (fs.existsSync(assetsDir)) {
168-
const assets = fs.readdirSync(assetsDir)
169-
expect(Array.isArray(assets)).toBe(true)
170-
expect(assets.length).toBeGreaterThan(0)
171-
}
172-
})
162+
expect(
163+
distFileExists(
164+
template.name,
165+
SUPPORTED_BROWSERS[0],
166+
'content_scripts/content-0.js'
167+
)
168+
).toBeTruthy()
169+
}
170+
171+
// Basic asset sanity: icons and optional assets folder when present
172+
expect(fs.existsSync(path.join(distDir, 'icons'))).toBeTruthy()
173+
// When assets exist, ensure at least one file is emitted
174+
const assetsDir = path.join(distDir, 'assets')
175+
if (fs.existsSync(assetsDir)) {
176+
const assets = fs.readdirSync(assetsDir)
177+
expect(Array.isArray(assets)).toBe(true)
178+
expect(assets.length).toBeGreaterThan(0)
179+
}
180+
},
181+
30000
182+
)
173183
})
174184

175185
afterEach(async () => {

programs/develop/webpack/plugin-extension/feature-manifest/__spec__/integration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const getFixturesPath = (demoDir: string) => {
1919

2020
async function waitForFile(
2121
filePath: string,
22-
timeoutMs: number = 2000,
22+
timeoutMs: number = 10000,
2323
intervalMs: number = 50
2424
) {
2525
const start = Date.now()

programs/develop/webpack/plugin-extension/feature-scripts/__spec__/index.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ const getFixturesPath = (demoDir: string) => {
1818
}
1919

2020
const assertFileIsEmitted = async (filePath: string) => {
21-
const fileIsEmitted = await fs.promises.access(filePath, fs.constants.F_OK)
22-
return expect(fileIsEmitted).toBeUndefined()
21+
const start = Date.now()
22+
const timeoutMs = 10000
23+
const intervalMs = 50
24+
while (Date.now() - start < timeoutMs) {
25+
try {
26+
await fs.promises.access(filePath, fs.constants.F_OK)
27+
return expect(undefined).toBeUndefined()
28+
} catch {
29+
// keep waiting
30+
}
31+
await new Promise((r) => setTimeout(r, intervalMs))
32+
}
33+
throw new Error(`File not found in time: ${filePath}`)
2334
}
2435

2536
describe('ScriptsPlugin (default behavior)', () => {

programs/develop/webpack/plugin-extension/feature-scripts/__spec__/integration-service-worker.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fx = (demo: string) =>
88

99
async function waitForFile(
1010
filePath: string,
11-
timeoutMs: number = 2000,
11+
timeoutMs: number = 10000,
1212
intervalMs: number = 50
1313
) {
1414
const start = Date.now()

programs/develop/webpack/plugin-extension/feature-special-folders/__spec__/index.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ const getFixturesPath = (demoDir: string) => {
1818
}
1919

2020
const assertFileIsEmitted = async (filePath: string) => {
21-
const fileIsEmitted = await fs.promises.access(filePath, fs.constants.F_OK)
22-
return expect(fileIsEmitted).toBeUndefined()
21+
const start = Date.now()
22+
const timeoutMs = 10000
23+
const intervalMs = 50
24+
while (Date.now() - start < timeoutMs) {
25+
try {
26+
await fs.promises.access(filePath, fs.constants.F_OK)
27+
return expect(undefined).toBeUndefined()
28+
} catch {
29+
// keep waiting
30+
}
31+
await new Promise((r) => setTimeout(r, intervalMs))
32+
}
33+
throw new Error(`File not found in time: ${filePath}`)
2334
}
2435

2536
describe('SpecialFoldersPlugin', () => {

programs/develop/webpack/plugin-extension/feature-web-resources/__spec__/integration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const getFixturesPath = (demoDir: string) => {
1919

2020
async function waitForFile(
2121
filePath: string,
22-
timeoutMs: number = 2000,
22+
timeoutMs: number = 10000,
2323
intervalMs: number = 50
2424
) {
2525
const start = Date.now()

0 commit comments

Comments
 (0)