Skip to content

Commit f028eae

Browse files
Integration tests: Move all file writes into retry block (#14350)
There are still instances in which CI is flaky after #14332. This PR applies the same fix (that is, moving the file write into the retrying block) to all `retryAssertion` callbacks.
1 parent 7f06777 commit f028eae

File tree

5 files changed

+142
-132
lines changed

5 files changed

+142
-132
lines changed

integrations/postcss/next.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ test(
135135
expect(css).toContain(candidate`underline`)
136136
})
137137

138-
await fs.write(
139-
'app/page.js',
140-
js`
141-
export default function Page() {
142-
return <h1 className="underline text-red-500">Hello, Next.js!</h1>
143-
}
144-
`,
145-
)
146-
147138
await retryAssertion(async () => {
139+
await fs.write(
140+
'app/page.js',
141+
js`
142+
export default function Page() {
143+
return <h1 className="underline text-red-500">Hello, Next.js!</h1>
144+
}
145+
`,
146+
)
147+
148148
let css = await fetchStyles(port)
149149
expect(css).toContain(candidate`underline`)
150150
expect(css).toContain(candidate`text-red-500`)

integrations/vite/astro.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@ test(
4444
expect(css).toContain(candidate`underline`)
4545
})
4646

47-
await fs.write(
48-
'src/pages/index.astro',
49-
html`
50-
<div class="underline font-bold">Hello, world!</div>
47+
await retryAssertion(async () => {
48+
await fs.write(
49+
'src/pages/index.astro',
50+
html`
51+
<div class="underline font-bold">Hello, world!</div>
5152
52-
<style is:global>
53-
@import 'tailwindcss';
54-
</style>
53+
<style is:global>
54+
@import 'tailwindcss';
55+
</style>
5556
`,
56-
)
57-
await retryAssertion(async () => {
57+
)
58+
5859
let css = await fetchStyles(port)
5960
expect(css).toContain(candidate`underline`)
6061
expect(css).toContain(candidate`font-bold`)

integrations/vite/config.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ test(
191191
expect(css).toContain('color: blue')
192192
})
193193

194-
await fs.write('my-color.cjs', js`module.exports = 'red'`)
195194
await retryAssertion(async () => {
195+
await fs.write('my-color.cjs', js`module.exports = 'red'`)
196+
196197
let css = await fetchStyles(port, '/index.html')
197198
expect(css).toContain(candidate`text-primary`)
198199
expect(css).toContain('color: red')
@@ -262,8 +263,9 @@ test(
262263
expect(css).toContain('color: blue')
263264
})
264265

265-
await fs.write('my-color.mjs', js`export default 'red'`)
266266
await retryAssertion(async () => {
267+
await fs.write('my-color.mjs', js`export default 'red'`)
268+
267269
let css = await fetchStyles(port, '/index.html')
268270
expect(css).toContain(candidate`text-primary`)
269271
expect(css).toContain('color: red')

integrations/vite/index.test.ts

Lines changed: 110 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -171,78 +171,81 @@ for (let transformer of ['postcss', 'lightningcss']) {
171171
// Candidates are resolved lazily, so the first visit of index.html
172172
// will only have candidates from this file.
173173
await retryAssertion(async () => {
174-
let css = await fetchStyles(port, '/index.html')
175-
expect(css).toContain(candidate`underline`)
176-
expect(css).toContain(candidate`flex`)
177-
expect(css).not.toContain(candidate`font-bold`)
174+
let styles = await fetchStyles(port, '/index.html')
175+
expect(styles).toContain(candidate`underline`)
176+
expect(styles).toContain(candidate`flex`)
177+
expect(styles).not.toContain(candidate`font-bold`)
178178
})
179179

180180
// Going to about.html will extend the candidate list to include
181181
// candidates from about.html.
182182
await retryAssertion(async () => {
183-
let css = await fetchStyles(port, '/about.html')
184-
expect(css).toContain(candidate`underline`)
185-
expect(css).toContain(candidate`flex`)
186-
expect(css).toContain(candidate`font-bold`)
183+
let styles = await fetchStyles(port, '/about.html')
184+
expect(styles).toContain(candidate`underline`)
185+
expect(styles).toContain(candidate`flex`)
186+
expect(styles).toContain(candidate`font-bold`)
187187
})
188188

189-
// Updates are additive and cause new candidates to be added.
190-
await fs.write(
191-
'project-a/index.html',
192-
html`
193-
<head>
194-
<link rel="stylesheet" href="./src/index.css" />
195-
</head>
196-
<body>
197-
<div class="underline m-2">Hello, world!</div>
198-
</body>
199-
`,
200-
)
201189
await retryAssertion(async () => {
202-
let css = await fetchStyles(port)
203-
expect(css).toContain(candidate`underline`)
204-
expect(css).toContain(candidate`flex`)
205-
expect(css).toContain(candidate`font-bold`)
206-
expect(css).toContain(candidate`m-2`)
190+
// Updates are additive and cause new candidates to be added.
191+
await fs.write(
192+
'project-a/index.html',
193+
html`
194+
<head>
195+
<link rel="stylesheet" href="./src/index.css" />
196+
</head>
197+
<body>
198+
<div class="underline m-2">Hello, world!</div>
199+
</body>
200+
`,
201+
)
202+
203+
let styles = await fetchStyles(port)
204+
expect(styles).toContain(candidate`underline`)
205+
expect(styles).toContain(candidate`flex`)
206+
expect(styles).toContain(candidate`font-bold`)
207+
expect(styles).toContain(candidate`m-2`)
207208
})
208209

209-
// Manually added `@source`s are watched and trigger a rebuild
210-
await fs.write(
211-
'project-b/src/index.js',
212-
js`
213-
const className = "[.changed_&]:content-['project-b/src/index.js']"
214-
module.exports = { className }
215-
`,
216-
)
217210
await retryAssertion(async () => {
218-
let css = await fetchStyles(port)
219-
expect(css).toContain(candidate`underline`)
220-
expect(css).toContain(candidate`flex`)
221-
expect(css).toContain(candidate`font-bold`)
222-
expect(css).toContain(candidate`m-2`)
223-
expect(css).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
224-
})
211+
// Manually added `@source`s are watched and trigger a rebuild
212+
await fs.write(
213+
'project-b/src/index.js',
214+
js`
215+
const className = "[.changed_&]:content-['project-b/src/index.js']"
216+
module.exports = { className }
217+
`,
218+
)
225219

226-
// After updates to the CSS file, all previous candidates should still be in
227-
// the generated CSS
228-
await fs.write(
229-
'project-a/src/index.css',
230-
css`
231-
${await fs.read('project-a/src/index.css')}
220+
let styles = await fetchStyles(port)
221+
expect(styles).toContain(candidate`underline`)
222+
expect(styles).toContain(candidate`flex`)
223+
expect(styles).toContain(candidate`font-bold`)
224+
expect(styles).toContain(candidate`m-2`)
225+
expect(styles).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
226+
})
232227

233-
.red {
234-
color: red;
235-
}
236-
`,
237-
)
238228
await retryAssertion(async () => {
239-
let css = await fetchStyles(port)
240-
expect(css).toContain(candidate`red`)
241-
expect(css).toContain(candidate`flex`)
242-
expect(css).toContain(candidate`m-2`)
243-
expect(css).toContain(candidate`underline`)
244-
expect(css).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
245-
expect(css).toContain(candidate`font-bold`)
229+
// After updates to the CSS file, all previous candidates should still be in
230+
// the generated CSS
231+
await fs.write(
232+
'project-a/src/index.css',
233+
css`
234+
${await fs.read('project-a/src/index.css')}
235+
236+
.red {
237+
color: red;
238+
}
239+
`,
240+
)
241+
242+
let styles = await fetchStyles(port)
243+
expect(styles).toContain(candidate`red`)
244+
expect(styles).toContain(candidate`flex`)
245+
expect(styles).toContain(candidate`m-2`)
246+
expect(styles).toContain(candidate`underline`)
247+
expect(styles).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
248+
expect(styles).toContain(candidate`font-bold`)
246249
})
247250
},
248251
)
@@ -337,51 +340,53 @@ for (let transformer of ['postcss', 'lightningcss']) {
337340

338341
let files = await fs.glob('project-a/dist/**/*.css')
339342
expect(files).toHaveLength(1)
340-
let [, css] = files[0]
341-
expect(css).toContain(candidate`underline`)
342-
expect(css).toContain(candidate`flex`)
343-
expect(css).toContain(candidate`m-2`)
343+
let [, styles] = files[0]
344+
expect(styles).toContain(candidate`underline`)
345+
expect(styles).toContain(candidate`flex`)
346+
expect(styles).toContain(candidate`m-2`)
344347
})
345348

346-
// Manually added `@source`s are watched and trigger a rebuild
347-
await fs.write(
348-
'project-b/src/index.js',
349-
js`
350-
const className = "[.changed_&]:content-['project-b/src/index.js']"
351-
module.exports = { className }
352-
`,
353-
)
354349
await retryAssertion(async () => {
350+
// Manually added `@source`s are watched and trigger a rebuild
351+
await fs.write(
352+
'project-b/src/index.js',
353+
js`
354+
const className = "[.changed_&]:content-['project-b/src/index.js']"
355+
module.exports = { className }
356+
`,
357+
)
358+
355359
let files = await fs.glob('project-a/dist/**/*.css')
356360
expect(files).toHaveLength(1)
357-
let [, css] = files[0]
358-
expect(css).toContain(candidate`underline`)
359-
expect(css).toContain(candidate`flex`)
360-
expect(css).toContain(candidate`m-2`)
361-
expect(css).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
361+
let [, styles] = files[0]
362+
expect(styles).toContain(candidate`underline`)
363+
expect(styles).toContain(candidate`flex`)
364+
expect(styles).toContain(candidate`m-2`)
365+
expect(styles).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
362366
})
363367

364-
// After updates to the CSS file, all previous candidates should still be in
365-
// the generated CSS
366-
await fs.write(
367-
'project-a/src/index.css',
368-
css`
369-
${await fs.read('project-a/src/index.css')}
370-
371-
.red {
372-
color: red;
373-
}
374-
`,
375-
)
376368
await retryAssertion(async () => {
369+
// After updates to the CSS file, all previous candidates should still be in
370+
// the generated CSS
371+
await fs.write(
372+
'project-a/src/index.css',
373+
css`
374+
${await fs.read('project-a/src/index.css')}
375+
376+
.red {
377+
color: red;
378+
}
379+
`,
380+
)
381+
377382
let files = await fs.glob('project-a/dist/**/*.css')
378383
expect(files).toHaveLength(1)
379-
let [, css] = files[0]
380-
expect(css).toContain(candidate`underline`)
381-
expect(css).toContain(candidate`flex`)
382-
expect(css).toContain(candidate`m-2`)
383-
expect(css).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
384-
expect(css).toContain(candidate`red`)
384+
let [, styles] = files[0]
385+
expect(styles).toContain(candidate`underline`)
386+
expect(styles).toContain(candidate`flex`)
387+
expect(styles).toContain(candidate`m-2`)
388+
expect(styles).toContain(candidate`[.changed_&]:content-['project-b/src/index.js']`)
389+
expect(styles).toContain(candidate`red`)
385390
})
386391
},
387392
)
@@ -439,25 +444,26 @@ test(
439444
// Candidates are resolved lazily, so the first visit of index.html
440445
// will only have candidates from this file.
441446
await retryAssertion(async () => {
442-
let css = await fetchStyles(port, '/index.html')
443-
expect(css).toContain(candidate`underline`)
444-
expect(css).not.toContain(candidate`font-bold`)
447+
let styles = await fetchStyles(port, '/index.html')
448+
expect(styles).toContain(candidate`underline`)
449+
expect(styles).not.toContain(candidate`font-bold`)
445450
})
446451

447452
// Going to about.html will extend the candidate list to include
448453
// candidates from about.html.
449454
await retryAssertion(async () => {
450-
let css = await fetchStyles(port, '/about.html')
451-
expect(css).toContain(candidate`underline`)
452-
expect(css).toContain(candidate`font-bold`)
455+
let styles = await fetchStyles(port, '/about.html')
456+
expect(styles).toContain(candidate`underline`)
457+
expect(styles).toContain(candidate`font-bold`)
453458
})
454459

455-
// We change the CSS file so it is no longer a valid Tailwind root.
456-
await fs.write('src/index.css', css`@import 'tailwindcss';`)
457460
await retryAssertion(async () => {
458-
let css = await fetchStyles(port)
459-
expect(css).toContain(candidate`underline`)
460-
expect(css).toContain(candidate`font-bold`)
461+
// We change the CSS file so it is no longer a valid Tailwind root.
462+
await fs.write('src/index.css', css`@import 'tailwindcss';`)
463+
464+
let styles = await fetchStyles(port)
465+
expect(styles).toContain(candidate`underline`)
466+
expect(styles).toContain(candidate`font-bold`)
461467
})
462468
},
463469
)

integrations/vite/nuxt.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ test(
4747
expect(css).toContain(candidate`underline`)
4848
})
4949

50-
await fs.write(
51-
'app.vue',
52-
html`
53-
<template>
54-
<div class="underline font-bold">Hello world!</div>
55-
</template>
56-
`,
57-
)
5850
await retryAssertion(async () => {
51+
await fs.write(
52+
'app.vue',
53+
html`
54+
<template>
55+
<div class="underline font-bold">Hello world!</div>
56+
</template>
57+
`,
58+
)
59+
5960
let css = await fetchStyles(port)
6061
expect(css).toContain(candidate`underline`)
6162
expect(css).toContain(candidate`font-bold`)

0 commit comments

Comments
 (0)