tailwindcss/tests/custom-extractors.test.js
Robin Malfait b643d399db
use oxide
- Setup the codebase to be able to use the Rust parts based on an
  environment variable: `OXIDE=1`.
- Setup some tests that run both the non-Rust and Rust version in the
  same test.
- Sort the candidates in a consistent way, to guarantee the order for
  now (especially in tests).
- Reflect sorting related changes in tests.
- Ensure tests run in both the Rust and non-Rust version. (Some tests
  are explicitly skipped when using the Rust version since we haven't
  implemented those features yet. These include: custom prefix,
  transformers and extractors).
  - `jest`
  -`OXIDE=1 jest`
2023-01-05 16:01:11 +01:00

122 lines
2.9 KiB
JavaScript

import fs from 'fs'
import path from 'path'
import { run, css } from './util/run'
import { env } from '../src/lib/sharedState'
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')
let group = env.OXIDE ? describe.skip : describe
group('modern', () => {
test('extract.DEFAULT', () => {
let config = {
content: {
files: [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: {
files: [path.resolve(__dirname, './custom-extractors.test.html')],
extract: {
html: customExtractor,
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(expected)
})
})
test('extract function', () => {
let config = {
content: {
files: [path.resolve(__dirname, './custom-extractors.test.html')],
extract: customExtractor,
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(expected)
})
})
test('raw content with extension', () => {
let config = {
content: {
files: [
{
raw: fs.readFileSync(path.resolve(__dirname, './raw-content.test.html'), 'utf8'),
extension: 'html',
},
],
extract: {
html: () => ['invisible'],
},
},
corePlugins: { preflight: false },
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.invisible {
visibility: hidden;
}
`)
})
})
})
group('legacy', () => {
test('defaultExtractor', () => {
let config = {
content: {
files: [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: {
files: [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)
})
})
})