2021-04-30 16:58:40 +02:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import path from 'path'
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2021-09-03 13:48:16 +02:00
|
|
|
import { run } from './util/run'
|
2021-04-02 11:16:15 -04:00
|
|
|
|
|
|
|
|
function customExtractor(content) {
|
2021-09-03 13:48:16 +02:00
|
|
|
let matches = content.match(/class="([^"]+)"/)
|
2021-04-02 11:16:15 -04:00
|
|
|
return matches ? matches[1].split(/\s+/) : []
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 13:48:16 +02:00
|
|
|
let expectedPath = path.resolve(__dirname, './custom-extractors.test.css')
|
|
|
|
|
let expected = fs.readFileSync(expectedPath, 'utf8')
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
describe('modern', () => {
|
|
|
|
|
test('extract.DEFAULT', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: {
|
|
|
|
|
files: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
|
|
|
extract: {
|
|
|
|
|
DEFAULT: customExtractor,
|
|
|
|
|
},
|
2021-04-02 11:16:15 -04:00
|
|
|
},
|
2021-10-01 12:56:54 +02:00
|
|
|
}
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
|
|
|
})
|
2021-04-02 11:16:15 -04:00
|
|
|
})
|
|
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
test('extract.{extension}', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: {
|
|
|
|
|
files: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
|
|
|
extract: {
|
|
|
|
|
html: customExtractor,
|
|
|
|
|
},
|
2021-04-02 11:16:15 -04:00
|
|
|
},
|
2021-10-01 12:56:54 +02:00
|
|
|
}
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
|
|
|
})
|
2021-04-02 11:16:15 -04:00
|
|
|
})
|
2021-05-26 14:04:28 +01:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
test('extract function', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: {
|
|
|
|
|
files: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
|
|
|
extract: customExtractor,
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-05-26 14:04:28 +01:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
|
|
|
})
|
2021-05-26 14:04:28 +01:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
describe('legacy', () => {
|
|
|
|
|
test('defaultExtractor', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: {
|
|
|
|
|
files: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
|
|
|
options: {
|
|
|
|
|
defaultExtractor: customExtractor,
|
|
|
|
|
},
|
2021-05-26 14:04:28 +01:00
|
|
|
},
|
2021-10-01 12:56:54 +02:00
|
|
|
}
|
2021-05-26 14:04:28 +01:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
|
|
|
})
|
2021-05-26 14:04:28 +01:00
|
|
|
})
|
|
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
test('extractors array', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: {
|
|
|
|
|
files: [path.resolve(__dirname, './custom-extractors.test.html')],
|
|
|
|
|
options: {
|
|
|
|
|
extractors: [
|
|
|
|
|
{
|
|
|
|
|
extractor: customExtractor,
|
|
|
|
|
extensions: ['html'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2021-05-26 14:04:28 +01:00
|
|
|
},
|
2021-10-01 12:56:54 +02:00
|
|
|
}
|
2021-05-26 14:04:28 +01:00
|
|
|
|
2021-10-01 12:56:54 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
|
|
|
|
})
|
2021-05-26 14:04:28 +01:00
|
|
|
})
|
|
|
|
|
})
|