Skip to content

Commit 52f94c7

Browse files
authored
Improve codebase quality (#19999)
Small PR that improves the overall quality of the codebase. It's a bit of everything: 1. Using correct variants for the variants we are testing 2. Use `@reference` instead of `@import` in a test, testing the `@reference` according to the test name 3. Use `using` for Vitest related mocks. They have a `Symbol.dispose` implemented, so we can don't have to restore mocks ourselves (right now, some of them are not cleaned up at all). 4. Updated deprecated `.toThrowError` with `.toThrow` APIs ## Test plan Everything still passes. [ci-all]
1 parent 0db856f commit 52f94c7

9 files changed

Lines changed: 26 additions & 26 deletions

File tree

integrations/postcss/core-as-postcss-plugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe.each(Object.keys(variantConfig))('%s', (variant) => {
5050
async ({ exec, expect }) => {
5151
await expect(
5252
exec('pnpm postcss src/index.css --output dist/out.css', undefined, { ignoreStdErr: true }),
53-
).rejects.toThrowError(
53+
).rejects.toThrow(
5454
`It looks like you're trying to use \`tailwindcss\` directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install \`@tailwindcss/postcss\` and update your PostCSS configuration.`,
5555
)
5656
},

integrations/vite/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
836836
async ({ root, fs, exec, expect }) => {
837837
await expect(() =>
838838
exec('pnpm vite build', { cwd: path.join(root, 'project-a') }, { ignoreStdErr: true }),
839-
).rejects.toThrowError('The `source(../i-do-not-exist)` does not exist')
839+
).rejects.toThrow('The `source(../i-do-not-exist)` does not exist')
840840

841841
let files = await fs.glob('project-a/dist/**/*.css')
842842
expect(files).toHaveLength(0)

packages/@tailwindcss-postcss/src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('processing without specifying a base path', () => {
120120
afterEach(() => unlink(filepath))
121121

122122
test('the current working directory is used by default', async () => {
123-
const spy = vi.spyOn(process, 'cwd')
123+
using spy = vi.spyOn(process, 'cwd')
124124
spy.mockReturnValue(dir)
125125

126126
let processor = postcss([tailwindcss({ optimize: { minify: false } })])
@@ -389,7 +389,7 @@ describe('concurrent builds', () => {
389389
afterEach(() => rm(dir, { recursive: true, force: true }))
390390

391391
test('does experience a race-condition when calling the plugin two times for the same change', async () => {
392-
const spy = vi.spyOn(process, 'cwd')
392+
using spy = vi.spyOn(process, 'cwd')
393393
spy.mockReturnValue(dir)
394394

395395
let from = path.join(dir, 'index.css')

packages/tailwindcss/src/at-import.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ test('updates the base when loading modules inside nested files', async () => {
445445
base: '/root/foo',
446446
path: '',
447447
})
448-
let loadModule = vi.fn().mockResolvedValue({ base: '', path: '', module: () => {} })
448+
using loadModule = vi.fn().mockResolvedValue({ base: '', path: '', module: () => {} })
449449

450450
expect(
451451
(
@@ -500,7 +500,7 @@ test('emits the right base for @source found inside JS configs and plugins from
500500
base: '/root/foo',
501501
path: '',
502502
})
503-
let loadModule = vi.fn().mockImplementation((id: string) => {
503+
using loadModule = vi.fn().mockImplementation((id: string) => {
504504
let base = id.includes('nested') ? '/root/foo' : '/root'
505505
if (id.includes('config')) {
506506
let glob = id.includes('nested') ? './nested-config/*.html' : './root-config/*.html'

packages/tailwindcss/src/compat/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ test('blocklisted candidates cannot be used with `@apply`', async () => {
15131513
})
15141514

15151515
test('old theme values are merged with their renamed counterparts in the CSS theme', async () => {
1516-
let didCallPluginFn = vi.fn()
1516+
using didCallPluginFn = vi.fn()
15171517

15181518
await compile(
15191519
css`

packages/tailwindcss/src/compat/plugin-api.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ describe('theme', async () => {
667667
}
668668
`
669669

670-
let fn = vi.fn()
670+
using fn = vi.fn()
671671

672672
await compile(input, {
673673
loadModule: async (id, base) => {
@@ -951,7 +951,7 @@ describe('theme', async () => {
951951
}
952952
`
953953

954-
let fn = vi.fn()
954+
using fn = vi.fn()
955955

956956
await compile(input, {
957957
loadModule: async (id, base) => {
@@ -994,7 +994,7 @@ describe('theme', async () => {
994994
}
995995
`
996996

997-
let fn = vi.fn()
997+
using fn = vi.fn()
998998

999999
await compile(input, {
10001000
loadModule: async (id, base) => {
@@ -1026,7 +1026,7 @@ describe('theme', async () => {
10261026
}
10271027
`
10281028

1029-
let fn = vi.fn()
1029+
using fn = vi.fn()
10301030

10311031
await compile(input, {
10321032
loadModule: async (id, base) => {
@@ -1055,7 +1055,7 @@ describe('theme', async () => {
10551055
@plugin "my-plugin";
10561056
`
10571057

1058-
let fn = vi.fn()
1058+
using fn = vi.fn()
10591059

10601060
await compile(input, {
10611061
loadModule: async (id, base) => {
@@ -3133,7 +3133,7 @@ describe('addUtilities()', () => {
31333133
},
31343134
},
31353135
)
3136-
}).rejects.toThrowError(/invalid utility selector/)
3136+
}).rejects.toThrow(/invalid utility selector/)
31373137
})
31383138

31393139
test('supports multiple selector names', async () => {
@@ -4305,7 +4305,7 @@ describe('matchUtilities()', () => {
43054305
},
43064306
},
43074307
)
4308-
}).rejects.toThrowError(/invalid utility name/)
4308+
}).rejects.toThrow(/invalid utility name/)
43094309
})
43104310

43114311
test('replaces the class name with variants in nested selectors', async () => {
@@ -4494,7 +4494,7 @@ describe('matchComponents()', () => {
44944494

44954495
describe('prefix()', () => {
44964496
test('is an identity function', async () => {
4497-
let fn = vi.fn()
4497+
using fn = vi.fn()
44984498
await compile(
44994499
css`
45004500
@plugin "my-plugin";
@@ -4518,7 +4518,7 @@ describe('prefix()', () => {
45184518

45194519
describe('config()', () => {
45204520
test('can return the resolved config when passed no arguments', async () => {
4521-
let fn = vi.fn()
4521+
using fn = vi.fn()
45224522
await compile(
45234523
css`
45244524
@plugin "my-plugin";
@@ -4546,7 +4546,7 @@ describe('config()', () => {
45464546
})
45474547

45484548
test('can return part of the config', async () => {
4549-
let fn = vi.fn()
4549+
using fn = vi.fn()
45504550
await compile(
45514551
css`
45524552
@plugin "my-plugin";
@@ -4572,7 +4572,7 @@ describe('config()', () => {
45724572
})
45734573

45744574
test('falls back to default value if requested path does not exist', async () => {
4575-
let fn = vi.fn()
4575+
using fn = vi.fn()
45764576
await compile(
45774577
css`
45784578
@plugin "my-plugin";

packages/tailwindcss/src/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,10 +3888,10 @@ describe('@custom-variant', () => {
38883888
[`@custom-variant foo_ (&);`],
38893889
[`@custom-variant foo__ (&);`],
38903890
])('@custom-variant must have a valid name', (input) => {
3891-
return expect(compileCss(input)).rejects.toThrowError()
3891+
return expect(compileCss(input)).rejects.toThrow()
38923892
})
38933893

3894-
test('@custom-variant must not container special characters', () => {
3894+
test('@custom-variant must not contain special characters', () => {
38953895
return expect(
38963896
compileCss(css`
38973897
.foo {
@@ -6612,7 +6612,7 @@ describe('feature detection', () => {
66126612
test('using `@reference`', async () => {
66136613
let compiler = await compile(
66146614
css`
6615-
@import 'tailwindcss/preflight';
6615+
@reference 'tailwindcss/preflight';
66166616
`,
66176617
{ loadStylesheet: async (_, base) => ({ base, path: '', content: '' }) },
66186618
)

packages/tailwindcss/src/utilities.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28693,23 +28693,23 @@ describe('custom utilities', () => {
2869328693
right: 100%;
2869428694
}
2869528695
`),
28696-
).rejects.toThrowError(/should be alphanumeric/)
28696+
).rejects.toThrow(/should be alphanumeric/)
2869728697

2869828698
await expect(() =>
2869928699
compile(css`
2870028700
@utility ~push {
2870128701
right: 100%;
2870228702
}
2870328703
`),
28704-
).rejects.toThrowError(/should be alphanumeric/)
28704+
).rejects.toThrow(/should be alphanumeric/)
2870528705

2870628706
await expect(() =>
2870728707
compile(css`
2870828708
@utility @push {
2870928709
right: 100%;
2871028710
}
2871128711
`),
28712-
).rejects.toThrowError(/should be alphanumeric/)
28712+
).rejects.toThrow(/should be alphanumeric/)
2871328713
})
2871428714

2871528715
test('custom utilities work with `@apply`', async () => {
@@ -29043,7 +29043,7 @@ describe('custom utilities', () => {
2904329043
})
2904429044

2904529045
test('bare values with unsupported data types should result in a warning', async () => {
29046-
let spy = vi.spyOn(console, 'warn').mockImplementation(() => {})
29046+
using spy = vi.spyOn(console, 'warn').mockImplementation(() => {})
2904729047
let input = css`
2904829048
@utility paint-* {
2904929049
paint: --value([color], color);

packages/tailwindcss/src/variants.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ test('user-invalid', async () => {
388388
display: flex;
389389
}"
390390
`)
391-
expect(await run(['invalid/foo:flex'])).toEqual('')
391+
expect(await run(['user-invalid/foo:flex'])).toEqual('')
392392
})
393393

394394
test('in-range', async () => {

0 commit comments

Comments
 (0)