mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* move `./tests/jit` to `./tests` * make tests consistent Abstracted a `run` function and some syntax highlighting helpers for `html`, `css` and `javascript`.
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
import { run } from './util/run'
|
|
|
|
function customExtractor(content) {
|
|
let matches = content.match(/class="([^"]+)"/)
|
|
return matches ? matches[1].split(/\s+/) : []
|
|
}
|
|
|
|
let expectedPath = path.resolve(__dirname, './custom-extractors.test.css')
|
|
let expected = fs.readFileSync(expectedPath, 'utf8')
|
|
|
|
test('defaultExtractor', () => {
|
|
let config = {
|
|
content: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
options: {
|
|
defaultExtractor: customExtractor,
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|
|
|
|
test('extractors array', () => {
|
|
let config = {
|
|
content: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
options: {
|
|
extractors: [
|
|
{
|
|
extractor: customExtractor,
|
|
extensions: ['html'],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|
|
|
|
test('extract function', () => {
|
|
let config = {
|
|
content: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
extract: customExtractor,
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|
|
|
|
test('extract.DEFAULT', () => {
|
|
let config = {
|
|
content: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
extract: {
|
|
DEFAULT: customExtractor,
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|
|
|
|
test('extract.{extension}', () => {
|
|
let config = {
|
|
content: {
|
|
content: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
extract: {
|
|
html: customExtractor,
|
|
},
|
|
},
|
|
}
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
})
|
|
})
|