Skip to content

Commit 754e751

Browse files
authored
Use non-existing example in tests (#20021)
This PR makes a small change to the tests. In some cases, where we test `@utility` functionality we use `tab-*` utilities. But there is a possibility that we will add this as an actual utility, so instead let's use a much more generic `example-*` utility. Then we can read from the `--example` theme value, and use `--resolved-value: …;` and `--resolved-modifier: …;` values. It's admittedly more vague, but chances of conflicts go way down. Until CSS or Tailwind CSS introduces an `example-*` utility... ## Test plan 1. Only tests changed, and all of them still pass
1 parent 12eb5ae commit 754e751

3 files changed

Lines changed: 347 additions & 385 deletions

File tree

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -520,16 +520,16 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
520520
'migrate with custom functional utility `@utility custom-* {…}` that supports bare values',
521521
{ timeout },
522522
async () => {
523-
let candidate = '[tab-size:4]'
524-
let expected = 'tab-4'
523+
let candidate = '[--resolved-value:4]'
524+
let expected = 'example-4'
525525

526526
let input = css`
527527
@import 'tailwindcss';
528528
@theme {
529529
--*: initial;
530530
}
531-
@utility tab-* {
532-
tab-size: --value(integer);
531+
@utility example-* {
532+
--resolved-value: --value(integer);
533533
}
534534
`
535535

@@ -538,24 +538,24 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
538538
)
539539

540540
test.each([
541-
['[tab-size:0]', 'tab-0'],
542-
['[tab-size:4]', 'tab-4'],
543-
['[tab-size:8]', 'tab-github'],
544-
['tab-[0]', 'tab-0'],
545-
['tab-[4]', 'tab-4'],
546-
['tab-[8]', 'tab-github'],
541+
['[--resolved-value:0]', 'example-0'],
542+
['[--resolved-value:4]', 'example-4'],
543+
['[--resolved-value:8]', 'example-a'],
544+
['example-[0]', 'example-0'],
545+
['example-[4]', 'example-4'],
546+
['example-[8]', 'example-a'],
547547
])(
548548
'migrate custom @utility from arbitrary values to bare values and named values (based on theme)',
549549
async (candidate, expected) => {
550550
let input = css`
551551
@import 'tailwindcss';
552552
@theme {
553553
--*: initial;
554-
--tab-size-github: 8;
554+
--example-a: 8;
555555
}
556556
557-
@utility tab-* {
558-
tab-size: --value(--tab-size, integer, [integer]);
557+
@utility example-* {
558+
--resolved-value: --value(--example, integer, [integer]);
559559
}
560560
`
561561

@@ -676,11 +676,11 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
676676
--*: initial;
677677
--spacing: 0.25rem;
678678
--aspect-video: 16 / 9;
679-
--tab-size-github: 8;
679+
--example-a: 8;
680680
}
681681
682-
@utility tab-* {
683-
tab-size: --value(--tab-size, integer);
682+
@utility example-* {
683+
--resolved-value: --value(--example, integer);
684684
}
685685
`
686686

@@ -689,7 +689,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
689689
['aspect-16/9', 'aspect-video'],
690690

691691
// Custom utility with bare value integer
692-
['tab-8', 'tab-github'],
692+
['example-8', 'example-a'],
693693
])(testName, { timeout }, async (candidate, expected) => {
694694
await expectCanonicalization(input, candidate, expected)
695695
})

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,6 @@ test('Custom functional @utility', async () => {
497497
@import 'tailwindcss/utilities';
498498
499499
@theme reference {
500-
--tab-size-1: 1;
501-
--tab-size-2: 2;
502-
--tab-size-4: 4;
503-
--tab-size-github: 8;
504-
505500
--text-xs: 0.75rem;
506501
--text-xs--line-height: calc(1 / 0.75);
507502
@@ -510,10 +505,11 @@ test('Custom functional @utility', async () => {
510505
511506
--spacing: 0.25rem;
512507
--spacing-custom: 123px;
513-
}
514508
515-
@utility tab-* {
516-
tab-size: --value(--tab-size, 'revert', 'initial');
509+
--negative-1: 1;
510+
--negative-2: 2;
511+
--negative-4: 4;
512+
--negative-a: 8;
517513
}
518514
519515
@utility example-* {
@@ -535,7 +531,7 @@ test('Custom functional @utility', async () => {
535531
}
536532
537533
@utility -negative-* {
538-
margin: --value(--tab-size-*);
534+
margin: --value(--negative-*);
539535
}
540536
`
541537

@@ -550,18 +546,6 @@ test('Custom functional @utility', async () => {
550546
let classMap = new Map(design.getClassList())
551547
let classNames = Array.from(classMap.keys())
552548

553-
expect(classNames).toContain('tab-1')
554-
expect(classNames).toContain('tab-2')
555-
expect(classNames).toContain('tab-4')
556-
expect(classNames).toContain('tab-github')
557-
expect(classNames).toContain('tab-revert')
558-
expect(classNames).toContain('tab-initial')
559-
560-
expect(classNames).not.toContain('-tab-1')
561-
expect(classNames).not.toContain('-tab-2')
562-
expect(classNames).not.toContain('-tab-4')
563-
expect(classNames).not.toContain('-tab-github')
564-
565549
expect(classNames).toContain('with-custom-spacing-custom')
566550
expect(classNames).not.toContain('with-custom-spacing-0')
567551
expect(classNames).not.toContain('with-custom-spacing-0.5')
@@ -583,12 +567,12 @@ test('Custom functional @utility', async () => {
583567
expect(classNames).toContain('-negative-1')
584568
expect(classNames).toContain('-negative-2')
585569
expect(classNames).toContain('-negative-4')
586-
expect(classNames).toContain('-negative-github')
570+
expect(classNames).toContain('-negative-a')
587571

588572
expect(classNames).not.toContain('--negative-1')
589573
expect(classNames).not.toContain('--negative-2')
590574
expect(classNames).not.toContain('--negative-4')
591-
expect(classNames).not.toContain('--negative-github')
575+
expect(classNames).not.toContain('--negative-a')
592576

593577
expect(classNames).toContain('example-xs')
594578
expect(classMap.get('example-xs')?.modifiers).toEqual(['normal', 'foo', 'bar'])

0 commit comments

Comments
 (0)