Skip to content

Commit e624028

Browse files
committed
wip
1 parent 4b1bdd7 commit e624028

File tree

1 file changed

+71
-86
lines changed

1 file changed

+71
-86
lines changed

packages/tailwindcss/src/canonicalize-candidates.test.ts

Lines changed: 71 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { CanonicalizeOptions } from './intellisense'
66
import { DefaultMap } from './utils/default-map'
77

88
const css = String.raw
9+
const timeout = 25_000
910
const defaultTheme = fs.readFileSync(path.resolve(__dirname, '../theme.css'), 'utf8')
1011

1112
const designSystems = new DefaultMap((base: string) => {
@@ -261,7 +262,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
261262
['[font-weight:400]', 'font-normal'],
262263
['[line-height:0]', 'leading-0'],
263264
['[border-style:solid]', 'border-solid'],
264-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
265+
])(testName, { timeout }, async (candidate, expected) => {
265266
await expectCanonicalization(
266267
css`
267268
@import 'tailwindcss';
@@ -341,7 +342,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
341342
// Arbitrary percentage value must be a whole number. Should not migrate to
342343
// a bare value.
343344
['from-[2.5%]', 'from-[2.5%]'],
344-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
345+
])(testName, { timeout }, async (candidate, expected) => {
345346
let input = css`
346347
@import 'tailwindcss';
347348
@@ -358,30 +359,26 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
358359
await expectCanonicalization(input, candidate, expected)
359360
})
360361

361-
test(
362-
'migrate with custom static utility `@utility custom {…}`',
363-
{ timeout: 10_000 },
364-
async () => {
365-
let candidate = '[--key:value]'
366-
let expected = 'custom'
362+
test('migrate with custom static utility `@utility custom {…}`', { timeout }, async () => {
363+
let candidate = '[--key:value]'
364+
let expected = 'custom'
367365

368-
let input = css`
369-
@import 'tailwindcss';
370-
@theme {
371-
--*: initial;
372-
}
373-
@utility custom {
374-
--key: value;
375-
}
376-
`
366+
let input = css`
367+
@import 'tailwindcss';
368+
@theme {
369+
--*: initial;
370+
}
371+
@utility custom {
372+
--key: value;
373+
}
374+
`
377375

378-
await expectCanonicalization(input, candidate, expected)
379-
},
380-
)
376+
await expectCanonicalization(input, candidate, expected)
377+
})
381378

382379
test(
383380
'migrate with custom functional utility `@utility custom-* {…}`',
384-
{ timeout: 10_000 },
381+
{ timeout },
385382
async () => {
386383
let candidate = '[--key:value]'
387384
let expected = 'custom-value'
@@ -402,7 +399,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
402399

403400
test(
404401
'migrate with custom functional utility `@utility custom-* {…}` that supports bare values',
405-
{ timeout: 10_000 },
402+
{ timeout },
406403
async () => {
407404
let candidate = '[tab-size:4]'
408405
let expected = 'tab-4'
@@ -476,7 +473,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
476473
['max-w-(--container-3xl)', 'max-w-3xl'],
477474
])(
478475
`migrate arbitrary value to theme value ${testName}`,
479-
{ timeout: 10_000 },
476+
{ timeout },
480477
async (candidate, expected) => {
481478
let input = css`
482479
@import 'tailwindcss';
@@ -494,7 +491,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
494491

495492
test(
496493
'migrate an arbitrary property without spaces, to a theme value with spaces (canonicalization)',
497-
{ timeout: 10_000 },
494+
{ timeout },
498495
async () => {
499496
let candidate = 'font-[foo,bar,baz]'
500497
let expected = 'font-example'
@@ -523,22 +520,18 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
523520
// Custom pixel based spacing scale
524521
['w-[123px]', 'w-123', '1px'],
525522
['w-[256px]', 'w-128', '2px'],
526-
])(
527-
`${testName} (spacing = \`%s\`)`,
528-
{ timeout: 10_000 },
529-
async (candidate, expected, spacing) => {
530-
let input = css`
531-
@import 'tailwindcss';
523+
])(`${testName} (spacing = \`%s\`)`, { timeout }, async (candidate, expected, spacing) => {
524+
let input = css`
525+
@import 'tailwindcss';
532526
533-
@theme {
534-
--*: initial;
535-
--spacing: ${spacing};
536-
}
537-
`
527+
@theme {
528+
--*: initial;
529+
--spacing: ${spacing};
530+
}
531+
`
538532

539-
await expectCanonicalization(input, candidate, expected)
540-
},
541-
)
533+
await expectCanonicalization(input, candidate, expected)
534+
})
542535
})
543536

544537
describe('bare values', () => {
@@ -562,13 +555,13 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
562555

563556
// Custom utility with bare value integer
564557
['tab-8', 'tab-github'],
565-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
558+
])(testName, { timeout }, async (candidate, expected) => {
566559
await expectCanonicalization(input, candidate, expected)
567560
})
568561
})
569562

570563
describe('deprecated utilities', () => {
571-
test('`order-none` → `order-0`', { timeout: 10_000 }, async () => {
564+
test('`order-none` → `order-0`', { timeout }, async () => {
572565
let candidate = 'order-none'
573566
let expected = 'order-0'
574567

@@ -579,26 +572,22 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
579572
await expectCanonicalization(input, candidate, expected)
580573
})
581574

582-
test(
583-
'`order-none` → `order-none` with custom implementation',
584-
{ timeout: 10_000 },
585-
async () => {
586-
let candidate = 'order-none'
587-
let expected = 'order-none'
575+
test('`order-none` → `order-none` with custom implementation', { timeout }, async () => {
576+
let candidate = 'order-none'
577+
let expected = 'order-none'
588578

589-
let input = css`
590-
@import 'tailwindcss';
579+
let input = css`
580+
@import 'tailwindcss';
591581
592-
@utility order-none {
593-
order: none; /* imagine this exists */
594-
}
595-
`
582+
@utility order-none {
583+
order: none; /* imagine this exists */
584+
}
585+
`
596586

597-
await expectCanonicalization(input, candidate, expected)
598-
},
599-
)
587+
await expectCanonicalization(input, candidate, expected)
588+
})
600589

601-
test('`break-words` → `wrap-break-word`', { timeout: 10_000 }, async () => {
590+
test('`break-words` → `wrap-break-word`', { timeout }, async () => {
602591
let candidate = 'break-words'
603592
let expected = 'wrap-break-word'
604593

@@ -609,7 +598,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
609598
await expectCanonicalization(input, candidate, expected)
610599
})
611600

612-
test('`[overflow-wrap:break-word]` → `wrap-break-word`', { timeout: 10_000 }, async () => {
601+
test('`[overflow-wrap:break-word]` → `wrap-break-word`', { timeout }, async () => {
613602
let candidate = '[overflow-wrap:break-word]'
614603
let expected = 'wrap-break-word'
615604

@@ -620,24 +609,20 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
620609
await expectCanonicalization(input, candidate, expected)
621610
})
622611

623-
test(
624-
'`break-words` → `break-words` with custom implementation',
625-
{ timeout: 10_000 },
626-
async () => {
627-
let candidate = 'break-words'
628-
let expected = 'break-words'
612+
test('`break-words` → `break-words` with custom implementation', { timeout }, async () => {
613+
let candidate = 'break-words'
614+
let expected = 'break-words'
629615

630-
let input = css`
631-
@import 'tailwindcss';
616+
let input = css`
617+
@import 'tailwindcss';
632618
633-
@utility break-words {
634-
break: words; /* imagine this exists */
635-
}
636-
`
619+
@utility break-words {
620+
break: words; /* imagine this exists */
621+
}
622+
`
637623

638-
await expectCanonicalization(input, candidate, expected)
639-
},
640-
)
624+
await expectCanonicalization(input, candidate, expected)
625+
})
641626
})
642627

643628
describe('arbitrary variants', () => {
@@ -667,11 +652,11 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
667652
['group-[&:focus]:flex', 'group-focus:flex'],
668653
['peer-[&:focus]:flex', 'peer-focus:flex'],
669654
['in-[&:focus]:flex', 'in-focus:flex'],
670-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
655+
])(testName, { timeout }, async (candidate, expected) => {
671656
await expectCanonicalization(input, candidate, expected)
672657
})
673658

674-
test('unsafe migrations keep the candidate as-is', { timeout: 10_000 }, async () => {
659+
test('unsafe migrations keep the candidate as-is', { timeout }, async () => {
675660
// `hover:` also includes an `@media` query in addition to the `&:hover`
676661
// state. Migration is not safe because the functionality would be different.
677662
let candidate = '[&:hover]:flex'
@@ -686,7 +671,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
686671
await expectCanonicalization(input, candidate, expected)
687672
})
688673

689-
test('make unsafe migration safe (1)', { timeout: 10_000 }, async () => {
674+
test('make unsafe migration safe (1)', { timeout }, async () => {
690675
// Overriding the `hover:` variant to only use a selector will make the
691676
// migration safe.
692677
let candidate = '[&:hover]:flex'
@@ -702,7 +687,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
702687
await expectCanonicalization(input, candidate, expected)
703688
})
704689

705-
test('make unsafe migration safe (2)', { timeout: 10_000 }, async () => {
690+
test('make unsafe migration safe (2)', { timeout }, async () => {
706691
// Overriding the `hover:` variant to only use a selector will make the
707692
// migration safe. This time with the long-hand `@variant` syntax.
708693
let candidate = '[&:hover]:flex'
@@ -722,7 +707,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
722707
await expectCanonicalization(input, candidate, expected)
723708
})
724709

725-
test('custom selector-based variants', { timeout: 10_000 }, async () => {
710+
test('custom selector-based variants', { timeout }, async () => {
726711
let candidate = '[&.macos]:flex'
727712
let expected = 'is-macos:flex'
728713
let input = css`
@@ -736,7 +721,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
736721
await expectCanonicalization(input, candidate, expected)
737722
})
738723

739-
test('custom @media-based variants', { timeout: 10_000 }, async () => {
724+
test('custom @media-based variants', { timeout }, async () => {
740725
let candidate = '[@media(prefers-reduced-transparency:reduce)]:flex'
741726
let expected = 'transparency-safe:flex'
742727
let input = css`
@@ -773,7 +758,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
773758

774759
// A color with a known theme variable migrates to the full utility
775760
['bg-(color:--color-red-500)', 'bg-red-500'],
776-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
761+
])(testName, { timeout }, async (candidate, expected) => {
777762
await expectCanonicalization(input, candidate, expected)
778763
})
779764
})
@@ -860,7 +845,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
860845
'data-[selected]:aria-[selected="true"]:aspect-[12/34]',
861846
'data-selected:aria-selected:aspect-12/34',
862847
],
863-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
848+
])(testName, { timeout }, async (candidate, expected) => {
864849
let input = css`
865850
@import 'tailwindcss';
866851
`
@@ -967,7 +952,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
967952
['has-[[aria-visible]]:flex', 'has-aria-[visible]:flex'],
968953

969954
['has-[&:not(:nth-child(even))]:flex', 'has-odd:flex'],
970-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
955+
])(testName, { timeout }, async (candidate, expected) => {
971956
let input = css`
972957
@import 'tailwindcss';
973958
`
@@ -1000,7 +985,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
1000985

1001986
// Keep modifiers on classes that don't _really_ exist
1002987
['group/name', 'group/name'],
1003-
])(testName, { timeout: 10_000 }, async (candidate, expected) => {
988+
])(testName, { timeout }, async (candidate, expected) => {
1004989
await expectCanonicalization(input, candidate, expected)
1005990
})
1006991
})
@@ -1028,7 +1013,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
10281013
['[font-size:14px] [line-height:1.625]', 'text-sm/relaxed'],
10291014
])(
10301015
'should canonicalize multiple classes `%s` into a shorthand `%s`',
1031-
{ timeout: 10_000 },
1016+
{ timeout },
10321017
async (candidates, expected) => {
10331018
let input = css`
10341019
@import 'tailwindcss';
@@ -1039,7 +1024,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
10391024
})
10401025

10411026
describe('theme to var', () => {
1042-
test('extended space scale converts to var or calc', { timeout: 10_000 }, async () => {
1027+
test('extended space scale converts to var or calc', { timeout }, async () => {
10431028
let designSystem = await __unstable__loadDesignSystem(
10441029
css`
10451030
@tailwind utilities;
@@ -1066,7 +1051,7 @@ describe('theme to var', () => {
10661051
])
10671052
})
10681053

1069-
test('custom space scale converts to var', { timeout: 10_000 }, async () => {
1054+
test('custom space scale converts to var', { timeout }, async () => {
10701055
let designSystem = await __unstable__loadDesignSystem(
10711056
css`
10721057
@tailwind utilities;
@@ -1093,7 +1078,7 @@ describe('theme to var', () => {
10931078
})
10941079

10951080
describe('options', () => {
1096-
test('normalize `rem` units to `px`', { timeout: 10_000 }, async () => {
1081+
test('normalize `rem` units to `px`', { timeout }, async () => {
10971082
let designSystem = await __unstable__loadDesignSystem(
10981083
css`
10991084
@tailwind utilities;

0 commit comments

Comments
 (0)