123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838 |
- import { run, html, css, defaults } from './util/run'
- import { flagEnabled } from '../src/featureFlags'
- test('all plugins are executed that match a candidate', () => {
- let config = {
- content: [{ raw: html`<div class="bg-green-light bg-green"></div>` }],
- theme: {
- colors: {
- green: {
- light: 'green',
- },
- },
- },
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- .bg-green {
- /* Empty on purpose */
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .bg-green-light {
- --tw-bg-opacity: 1;
- background-color: rgb(0 128 0 / var(--tw-bg-opacity));
- }
- `)
- })
- })
- test('per-plugin colors with the same key can differ when using a custom colors object', () => {
- let config = {
- content: [
- {
- raw: html`
- <div class="bg-theme text-theme">This should be green text on red background.</div>
- `,
- },
- ],
- theme: {
- // colors & theme MUST be plain objects
- // If they're functions here the test passes regardless
- colors: {
- theme: {
- bg: 'red',
- text: 'green',
- },
- },
- extend: {
- textColor: {
- theme: {
- DEFAULT: 'green',
- },
- },
- backgroundColor: {
- theme: {
- DEFAULT: 'red',
- },
- },
- },
- },
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .bg-theme {
- --tw-bg-opacity: 1;
- background-color: rgb(255 0 0 / var(--tw-bg-opacity));
- }
- .text-theme {
- --tw-text-opacity: 1;
- color: rgb(0 128 0 / var(--tw-text-opacity));
- }
- `)
- })
- })
- test('default ring color can be a function', () => {
- function color(variable) {
- return function ({ opacityVariable, opacityValue }) {
- if (opacityValue !== undefined) {
- return `rgba(${variable}, ${opacityValue})`
- }
- if (opacityVariable !== undefined) {
- return `rgba(${variable}, var(${opacityVariable}, 1))`
- }
- return `rgb(${variable})`
- }
- }
- let config = {
- content: [
- {
- raw: html` <div class="ring"></div> `,
- },
- ],
- theme: {
- extend: {
- ringColor: {
- DEFAULT: color('var(--red)'),
- },
- },
- },
- plugins: [],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: 'rgba(var(--red), 0.5)' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('falsy config values still work', () => {
- let config = {
- content: [{ raw: html`<div class="inset-0"></div>` }],
- theme: {
- inset: {
- 0: 0,
- },
- },
- plugins: [],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .inset-0 {
- inset: 0;
- }
- `)
- })
- })
- it('shadows support values without a leading zero', () => {
- let config = {
- content: [{ raw: html`<div class="shadow-one shadow-two"></div>` }],
- theme: {
- boxShadow: {
- one: '0.5rem 0.5rem 0.5rem #0005',
- two: '.5rem .5rem .5rem #0005',
- },
- },
- plugins: [],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .shadow-one,
- .shadow-two {
- --tw-shadow: 0.5rem 0.5rem 0.5rem #0005;
- --tw-shadow-colored: 0.5rem 0.5rem 0.5rem var(--tw-shadow-color);
- box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
- var(--tw-shadow);
- }
- `)
- })
- })
- it('can scan extremely long classes without crashing', () => {
- let val = 'cols-' + '-a'.repeat(65536)
- let config = {
- content: [{ raw: html`<div class="${val}"></div>` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css``)
- })
- })
- it('does not produce duplicate output when seeing variants preceding a wildcard (*)', () => {
- let config = {
- content: [{ raw: html`underline focus:*` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind base;
- @tailwind components;
- @tailwind utilities;
- * {
- color: red;
- }
- .combined,
- * {
- text-align: center;
- }
- @layer base {
- * {
- color: blue;
- }
- .combined,
- * {
- color: red;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .combined,
- * {
- color: red;
- }
- ${defaults}
- .underline {
- text-decoration-line: underline;
- }
- * {
- color: red;
- }
- .combined,
- * {
- text-align: center;
- }
- `)
- })
- })
- it('can parse box shadows with variables', () => {
- let config = {
- content: [{ raw: html`<div class="shadow-lg"></div>` }],
- theme: {
- boxShadow: {
- lg: 'var(--a, 0 35px 60px -15px rgba(0, 0, 0)), 0 0 1px rgb(0, 0, 0)',
- },
- },
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .shadow-lg {
- --tw-shadow: var(--a, 0 35px 60px -15px #000), 0 0 1px #000;
- --tw-shadow-colored: 0 35px 60px -15px var(--tw-shadow-color),
- 0 0 1px var(--tw-shadow-color);
- box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
- var(--tw-shadow);
- }
- `)
- })
- })
- it('should generate styles using :not(.unknown-class) even if `.unknown-class` does not exist', () => {
- let config = {
- content: [{ raw: html`<div></div>` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind components;
- @layer components {
- div:not(.unknown-class) {
- color: red;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- div:not(.unknown-class) {
- color: red;
- }
- `)
- })
- })
- it('supports multiple backgrounds as arbitrary values even if only some are quoted', () => {
- let config = {
- content: [
- {
- raw: html`<div
- class="bg-[url('/images/one-two-three.png'),linear-gradient(to_right,_#eeeeee,_#000000)]"
- ></div>`,
- },
- ],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .bg-\[url\(\'\/images\/one-two-three\.png\'\)\,linear-gradient\(to_right\,_\#eeeeee\,_\#000000\)\] {
- background-image: url('/images/one-two-three.png'), linear-gradient(to right, #eee, #000);
- }
- `)
- })
- })
- it('The "default" ring opacity is used by the default ring color when not using respectDefaultRingColorOpacity (1)', () => {
- let config = {
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#3b82f680' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('The "default" ring opacity is used by the default ring color when not using respectDefaultRingColorOpacity (2)', () => {
- let config = {
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringOpacity: {
- DEFAULT: 0.75,
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#3b82f6bf' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('Customizing the default ring color uses the "default" opacity when not using respectDefaultRingColorOpacity (1)', () => {
- let config = {
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringColor: {
- DEFAULT: '#ff7f7f',
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#ff7f7f80' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('Customizing the default ring color uses the "default" opacity when not using respectDefaultRingColorOpacity (2)', () => {
- let config = {
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringColor: {
- DEFAULT: '#ff7f7f00',
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#ff7f7f80' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('The "default" ring color ignores the default opacity when using respectDefaultRingColorOpacity (1)', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#3b82f67f' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('The "default" ring color ignores the default opacity when using respectDefaultRingColorOpacity (2)', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringOpacity: {
- DEFAULT: 0.75,
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#3b82f67f' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('Customizing the default ring color preserves its opacity when using respectDefaultRingColorOpacity (1)', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringColor: {
- DEFAULT: '#ff7f7f',
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#ff7f7f' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('Customizing the default ring color preserves its opacity when using respectDefaultRingColorOpacity (2)', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringColor: {
- DEFAULT: '#ff7f7f00',
- },
- },
- }
- let input = css`
- @tailwind base;
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- ${defaults({ defaultRingColor: '#ff7f7f00' })}
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- `)
- })
- })
- it('A bare ring-opacity utility is not supported when not using respectDefaultRingColorOpacity', () => {
- let config = {
- content: [{ raw: html`<div class="ring-opacity"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringOpacity: {
- DEFAULT: '0.33',
- },
- },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css``)
- })
- })
- test('A bare ring-opacity utility is supported when using respectDefaultRingColorOpacity', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring-opacity"></div>` }],
- corePlugins: { preflight: false },
- theme: {
- ringOpacity: {
- DEFAULT: '0.33',
- },
- },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .ring-opacity {
- --tw-ring-opacity: 0.33;
- }
- `)
- })
- })
- it('Ring color utilities are generated when using respectDefaultRingColorOpacity', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [{ raw: html`<div class="ring ring-blue-500"></div>` }],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .ring {
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
- var(--tw-ring-offset-color);
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
- var(--tw-ring-color);
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
- }
- .ring-blue-500 {
- --tw-ring-opacity: 1;
- --tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
- }
- `)
- })
- })
- test('should not crash when group names contain special characters', () => {
- let config = {
- future: { respectDefaultRingColorOpacity: true },
- content: [
- {
- raw: '<div class="group/${id}"><div class="group-hover/${id}:visible"></div></div>',
- },
- ],
- corePlugins: { preflight: false },
- }
- let input = css`
- @tailwind utilities;
- `
- return run(input, config).then((result) => {
- if (flagEnabled(config, 'oxideParser')) {
- expect(result.css).toMatchFormattedCss(css``)
- } else {
- expect(result.css).toMatchFormattedCss(css`
- .group\/\$\{id\}:hover .group-hover\/\$\{id\}\:visible {
- visibility: visible;
- }
- `)
- }
- })
- })
- it('should not crash when matching variants where utility classes are doubled up', () => {
- let config = {
- content: [
- {
- raw: '<div class="hover:foo"></div>',
- },
- ],
- }
- let input = css`
- @tailwind utilities;
- @layer utilities {
- .foo.foo {
- text-decoration-line: underline;
- }
- }
- `
- return run(input, config).then((result) => {
- expect(result.css).toMatchFormattedCss(css`
- .hover\:foo:hover.hover\:foo:hover {
- text-decoration-line: underline;
- }
- `)
- })
- })
- test('detects quoted arbitrary values containing a slash', async () => {
- let config = {
- content: [
- {
- raw: html`<div class="group-[[href^='/']]:hidden"></div>`,
- },
- ],
- }
- let input = css`
- @tailwind utilities;
- `
- let result = await run(input, config)
- expect(result.css).toMatchFormattedCss(
- flagEnabled(config, 'oxideParser')
- ? css`
- .group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
- display: none;
- }
- `
- : css`
- .hidden,
- .group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
- display: none;
- }
- `
- )
- })
- test('handled quoted arbitrary values containing escaped spaces', async () => {
- let config = {
- content: [
- {
- raw: html`<div class="group-[[href^='_bar']]:hidden"></div>`,
- },
- ],
- }
- let input = css`
- @tailwind utilities;
- `
- let result = await run(input, config)
- expect(result.css).toMatchFormattedCss(
- flagEnabled(config, 'oxideParser')
- ? css`
- .group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
- display: none;
- }
- `
- : css`
- .hidden,
- .group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
- display: none;
- }
- `
- )
- })
- test('Skips classes inside :not() when nested inside an at-rule', async () => {
- let config = {
- content: [
- {
- raw: html` <div class="disabled !disabled"></div> `,
- },
- ],
- corePlugins: { preflight: false },
- plugins: [
- function ({ addUtilities }) {
- addUtilities({
- '.hand:not(.disabled)': {
- '@supports (cursor: pointer)': {
- cursor: 'pointer',
- },
- },
- })
- },
- ],
- }
- let input = css`
- @tailwind utilities;
- `
- // We didn't find the hand class therefore
- // nothing should be generated
- let result = await run(input, config)
- expect(result.css).toMatchFormattedCss(css``)
- })
- test('Irrelevant rules are removed when applying variants', async () => {
- let config = {
- content: [
- {
- raw: html` <div class="md:w-full"></div> `,
- },
- ],
- corePlugins: { preflight: false },
- plugins: [
- function ({ addUtilities }) {
- addUtilities({
- '@supports (foo: bar)': {
- // This doesn't contain `w-full` so it should not exist in the output
- '.outer': { color: 'red' },
- '.outer:is(.w-full)': { color: 'green' },
- },
- })
- },
- ],
- }
- let input = css`
- @tailwind utilities;
- `
- // We didn't find the hand class therefore
- // nothing should be generated
- let result = await run(input, config)
- expect(result.css).toMatchFormattedCss(css`
- @media (min-width: 768px) {
- .md\:w-full {
- width: 100%;
- }
- @supports (foo: bar) {
- .outer.md\:w-full {
- color: green;
- }
- }
- }
- `)
- })
|