mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* WIP * WIP * Finish combining JIT and AOT plugins Still lots of clean up that can be done in some of the more complex ones, but at least it's one file per plugin now. * Remove unused import * Fix AOT generation bugs * Move corePlugins/index.js to corePlugins.js * Convert JIT files to ESM * Move tests * Reorder core plugins to match JIT order * Update AOT apply tests * Unify utils * Combine plugin lists to one single source of truth * Finish resolving merge conflicts, fix tests Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
import postcss from 'postcss'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
function run(input, config = {}) {
|
|
jest.resetModules()
|
|
const tailwind = require('../../src/jit/index.js').default
|
|
return postcss(tailwind(config)).process(input, {
|
|
from: path.resolve(__filename),
|
|
})
|
|
}
|
|
|
|
function customExtractor(content) {
|
|
const matches = content.match(/class="([^"]+)"/)
|
|
return matches ? matches[1].split(/\s+/) : []
|
|
}
|
|
|
|
const css = `
|
|
@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
`
|
|
const expectedPath = path.resolve(__dirname, './custom-extractors.test.css')
|
|
const expected = fs.readFileSync(expectedPath, 'utf8')
|
|
|
|
test('defaultExtractor', () => {
|
|
let config = {
|
|
mode: 'jit',
|
|
purge: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
options: {
|
|
defaultExtractor: customExtractor,
|
|
},
|
|
},
|
|
corePlugins: { preflight: false },
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
return run(css, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|
|
|
|
test('extractors array', () => {
|
|
let config = {
|
|
purge: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
options: {
|
|
extractors: [
|
|
{
|
|
extractor: customExtractor,
|
|
extensions: ['html'],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
mode: 'jit',
|
|
corePlugins: { preflight: false },
|
|
theme: {},
|
|
plugins: [],
|
|
}
|
|
|
|
return run(css, config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|