* run PostCSS relative to test file The PostCSS `from` was always set to the `tests/util/run` file with the current test name as a query param to make it unique. However, that results in issues with relative file paths because they are now relative to this file instead of the actual test file. Luckily, `expect.getState()` exposes the `testPath` value that points to the current test file itself. * add built in `@import` processing + additional features such that you can use `@tailwind` and `@config` directives before the `@import` at rule which isn't normally allowed. However "@tailwind" in a way is an `@import` and `@config` in a way is a `@charset` which can be used before the `@import` at rule. * drop partial normalizeTailwindDirectives when in the Oxide engine This will now be handled by Tailwind from a higher level, so the core doesn't have to worry about normalizing this anymore since it will always be normalized right now. * add `handleImportAtRules` to CLI * update changelog * scope `import processing` to the oxide engine * update Changelog * use direct comparison We don't need the `startsWith` check anymore because the contents of the comment will be the actual value we expect.
94 lines
2.1 KiB
JavaScript
94 lines
2.1 KiB
JavaScript
import path from 'path'
|
|
import postcss from 'postcss'
|
|
import tailwind from '../../src'
|
|
import { env } from '../../src/lib/sharedState'
|
|
|
|
export * from './strings'
|
|
export * from './defaults'
|
|
|
|
export let map = JSON.stringify({
|
|
version: 3,
|
|
file: null,
|
|
sources: [],
|
|
names: [],
|
|
mappings: '',
|
|
})
|
|
|
|
globalThis.__OXIDE__ = env.ENGINE === 'oxide'
|
|
|
|
export function run(input, config, plugin = tailwind) {
|
|
let { currentTestName, testPath } = expect.getState()
|
|
|
|
return postcss(plugin(config)).process(input, {
|
|
from: `${path.resolve(testPath)}?test=${currentTestName}`,
|
|
})
|
|
}
|
|
|
|
export function runWithSourceMaps(input, config, plugin = tailwind) {
|
|
let { currentTestName, testPath } = expect.getState()
|
|
|
|
return postcss(plugin(config)).process(input, {
|
|
from: `${path.resolve(testPath)}?test=${currentTestName}`,
|
|
map: {
|
|
prev: map,
|
|
},
|
|
})
|
|
}
|
|
|
|
let nullTest = Object.assign(function () {}, {
|
|
skip: () => {},
|
|
only: () => {},
|
|
each: () => () => {},
|
|
todo: () => {},
|
|
})
|
|
let nullProxy = new Proxy(
|
|
{
|
|
test: nullTest,
|
|
it: nullTest,
|
|
xit: nullTest.skip,
|
|
fit: nullTest.only,
|
|
xdescribe: nullTest.skip,
|
|
fdescribe: nullTest.only,
|
|
},
|
|
{
|
|
get(target, prop, _receiver) {
|
|
if (prop in target) {
|
|
return target[prop]
|
|
}
|
|
return Object.assign(() => {
|
|
return nullProxy
|
|
}, nullProxy)
|
|
},
|
|
}
|
|
)
|
|
|
|
/**
|
|
* @typedef {object} CrossCheck
|
|
* @property {typeof import('@jest/globals')} oxide
|
|
* @property {typeof import('@jest/globals')} stable
|
|
* @property {object} engine
|
|
* @property {boolean} engine.oxide
|
|
* @property {boolean} engine.stable
|
|
*/
|
|
|
|
/**
|
|
* @param {(data: CrossCheck) => void} fn
|
|
*/
|
|
export function crosscheck(fn) {
|
|
let engines =
|
|
env.ENGINE === 'oxide' ? [{ engine: 'Stable' }, { engine: 'Oxide' }] : [{ engine: 'Stable' }]
|
|
|
|
describe.each(engines)('$engine', ({ engine }) => {
|
|
let engines = {
|
|
oxide: engine === 'Oxide' ? globalThis : nullProxy,
|
|
stable: engine === 'Stable' ? globalThis : nullProxy,
|
|
engine: { oxide: engine === 'Oxide', stable: engine === 'Stable' },
|
|
}
|
|
|
|
beforeEach(() => {
|
|
globalThis.__OXIDE__ = engines.engine.oxide
|
|
})
|
|
|
|
fn(engines)
|
|
})
|
|
}
|