Skip to content

Commit 479b725

Browse files
Bump Vitest to v4 (#19216)
This PR bumps Vitest from v2 to v4. As far as I know we don't use any Vitest specific features in our tests, but had to upgrade the `vitest.workspace.ts` file to a `vitest.config.ts` file instead. The only features we use are the typical `describe`, `it`, `test`, and `expect` functions. The only other part we use is `vi.spyOn` and `vi.fn` but those didn't change in API either. The test shards were removed to prevent errors. Not all suites have enough files / tests to be broken up into 3 parts so Vitest now errors when that happens. ### Test plan 1. All tests should pass in CI. 2. All integration tests should pass in CI. --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 642b9b8 commit 479b725

File tree

10 files changed

+340
-559
lines changed

10 files changed

+340
-559
lines changed

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,8 @@ jobs:
103103
CARGO_PROFILE_RELEASE_LTO: 'off'
104104
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: 'lld-link'
105105

106-
- name: Test ${{ matrix.integration }} 1/3
107-
run: pnpm run test:integrations ./integrations/${{ matrix.integration }} --shard 1/3
108-
env:
109-
GITHUB_WORKSPACE: ${{ github.workspace }}
110-
111-
- name: Test ${{ matrix.integration }} 2/3
112-
run: pnpm run test:integrations ./integrations/${{ matrix.integration }} --shard 2/3
113-
env:
114-
GITHUB_WORKSPACE: ${{ github.workspace }}
115-
116-
- name: Test ${{ matrix.integration }} 3/3
117-
run: pnpm run test:integrations ./integrations/${{ matrix.integration }} --shard 3/3
106+
- name: Test ${{ matrix.integration }}
107+
run: pnpm run test:integrations ./integrations/${{ matrix.integration }}
118108
env:
119109
GITHUB_WORKSPACE: ${{ github.workspace }}
120110

integrations/upgrade/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ test(
174174
test(
175175
`upgrades a v3 project with prefixes to v4`,
176176
{
177+
// Somehow this test takes *way* longer than the rest (but not always?)
178+
timeout: 120_000,
177179
fs: {
178180
'package.json': json`
179181
{

integrations/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface TestConfig {
3737
[filePath: string]: string | Uint8Array
3838
}
3939

40+
timeout?: number
4041
installDependencies?: boolean
4142
}
4243
interface TestContext {
@@ -86,7 +87,7 @@ export function test(
8687
return defaultTest(
8788
name,
8889
{
89-
timeout: TEST_TIMEOUT,
90+
timeout: config.timeout ?? TEST_TIMEOUT,
9091
retry: process.env.CI ? 2 : 0,
9192
only: only || (!process.env.CI && debug),
9293
skip,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"tsup": "^8.5.1",
5959
"turbo": "^2.6.1",
6060
"typescript": "^5.5.4",
61-
"vitest": "^2.0.5"
61+
"vitest": "^4.0.3"
6262
},
6363
"packageManager": "[email protected]",
6464
"pnpm": {

packages/@tailwindcss-upgrade/src/codemods/css/migrate-at-apply.test.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ async function migrate(input: string, config: Config = {}) {
1313
let designSystem = await __unstable__loadDesignSystem(
1414
css`
1515
@import 'tailwindcss';
16+
17+
/* TODO(perf): Only here to speed up the tests */
18+
@theme {
19+
--*: initial;
20+
}
1621
`,
1722
{ base: __dirname },
1823
)
@@ -85,35 +90,44 @@ it('should move the legacy `!` prefix, to the new `!` postfix notation', async (
8590
`)
8691
})
8792

88-
it('should apply all candidate migration when migrating with a config', async () => {
89-
async function migrateWithPrefix(input: string) {
90-
return postcss()
91-
.use(
92-
migrateAtApply({
93-
designSystem: await __unstable__loadDesignSystem(
94-
css`
95-
@import 'tailwindcss' prefix(tw);
96-
`,
97-
{ base: __dirname },
98-
),
99-
userConfig: {
100-
prefix: 'tw_',
101-
},
102-
}),
103-
)
104-
.process(input, { from: expect.getState().testPath })
105-
.then((result) => result.css)
106-
}
93+
it(
94+
'should apply all candidate migration when migrating with a config',
95+
{ timeout: 10_000 },
96+
async () => {
97+
async function migrateWithPrefix(input: string) {
98+
return postcss()
99+
.use(
100+
migrateAtApply({
101+
designSystem: await __unstable__loadDesignSystem(
102+
css`
103+
@import 'tailwindcss' prefix(tw);
107104
108-
expect(
109-
await migrateWithPrefix(css`
110-
.foo {
111-
@apply !tw_flex [color:--my-color] tw_bg-gradient-to-t;
112-
}
113-
`),
114-
).toMatchInlineSnapshot(`
105+
/* TODO(perf): Only here to speed up the tests */
106+
@theme {
107+
--*: initial;
108+
}
109+
`,
110+
{ base: __dirname },
111+
),
112+
userConfig: {
113+
prefix: 'tw_',
114+
},
115+
}),
116+
)
117+
.process(input, { from: expect.getState().testPath })
118+
.then((result) => result.css)
119+
}
120+
121+
expect(
122+
await migrateWithPrefix(css`
123+
.foo {
124+
@apply !tw_flex [color:--my-color] tw_bg-gradient-to-t;
125+
}
126+
`),
127+
).toMatchInlineSnapshot(`
115128
".foo {
116129
@apply tw:flex! tw:text-(--my-color) tw:bg-linear-to-t;
117130
}"
118131
`)
119-
})
132+
},
133+
)

packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ import * as versions from '../../utils/version'
44
import { migrateCandidate } from './migrate'
55
vi.spyOn(versions, 'isMajor').mockReturnValue(true)
66

7+
const css = String.raw
8+
79
describe('is-safe-migration', async () => {
8-
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
9-
base: __dirname,
10-
})
10+
let designSystem = await __unstable__loadDesignSystem(
11+
css`
12+
@import 'tailwindcss';
13+
14+
/* TODO(perf): Only here to speed up the tests */
15+
@theme {
16+
--*: initial;
17+
--shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
18+
--shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
19+
}
20+
`,
21+
{ base: __dirname },
22+
)
1123

1224
test.each([
1325
[`let notBorder = !border \n`, '!border'],

0 commit comments

Comments
 (0)