|
| 1 | +import postcss from 'postcss' |
| 2 | +import path from 'path' |
| 3 | +import tailwind from '../../src/jit/index.js' |
| 4 | +import { transformAllSelectors, updateAllClasses } from '../../src/util/pluginUtils.js' |
| 5 | + |
| 6 | +function run(input, config = {}) { |
| 7 | + const { currentTestName } = expect.getState() |
| 8 | + |
| 9 | + return postcss(tailwind(config)).process(input, { |
| 10 | + from: `${path.resolve(__filename)}?test=${currentTestName}`, |
| 11 | + }) |
| 12 | +} |
| 13 | + |
| 14 | +test('basic parallel variants', async () => { |
| 15 | + let config = { |
| 16 | + mode: 'jit', |
| 17 | + purge: [ |
| 18 | + { |
| 19 | + raw: '<div class="font-normal hover:test:font-black test:font-bold test:font-medium"></div>', |
| 20 | + }, |
| 21 | + ], |
| 22 | + theme: {}, |
| 23 | + plugins: [ |
| 24 | + function test({ addVariant, config }) { |
| 25 | + addVariant('test', [ |
| 26 | + transformAllSelectors((selector) => { |
| 27 | + let variantSelector = updateAllClasses(selector, (className) => { |
| 28 | + return `test${config('separator')}${className}` |
| 29 | + }) |
| 30 | + |
| 31 | + return `${variantSelector} *::test` |
| 32 | + }), |
| 33 | + transformAllSelectors((selector) => { |
| 34 | + return updateAllClasses(selector, (className, { withPseudo }) => { |
| 35 | + return withPseudo(`test${config('separator')}${className}`, '::test') |
| 36 | + }) |
| 37 | + }), |
| 38 | + ]) |
| 39 | + }, |
| 40 | + ], |
| 41 | + } |
| 42 | + |
| 43 | + let css = `@tailwind utilities` |
| 44 | + |
| 45 | + return run(css, config).then((result) => { |
| 46 | + expect(result.css).toMatchFormattedCss(` |
| 47 | + .font-normal { |
| 48 | + font-weight: 400; |
| 49 | + } |
| 50 | + .test\\:font-bold *::test { |
| 51 | + font-weight: 700; |
| 52 | + } |
| 53 | + .test\\:font-medium *::test { |
| 54 | + font-weight: 500; |
| 55 | + } |
| 56 | + .hover\\:test\\:font-black:hover *::test { |
| 57 | + font-weight: 900; |
| 58 | + } |
| 59 | + .test\\:font-bold::test { |
| 60 | + font-weight: 700; |
| 61 | + } |
| 62 | + .test\\:font-medium::test { |
| 63 | + font-weight: 500; |
| 64 | + } |
| 65 | + .hover\\:test\\:font-black:hover::test { |
| 66 | + font-weight: 900; |
| 67 | + } |
| 68 | + `) |
| 69 | + }) |
| 70 | +}) |
0 commit comments