-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathrun.js
92 lines (80 loc) · 2.07 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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: '',
})
export function run(input, config, plugin = tailwind) {
let { currentTestName } = expect.getState()
return postcss(plugin(config)).process(input, {
from: `${path.resolve(__filename)}?test=${currentTestName}`,
})
}
export function runWithSourceMaps(input, config, plugin = tailwind) {
let { currentTestName } = expect.getState()
return postcss(plugin(config)).process(input, {
from: `${path.resolve(__filename)}?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(() => {
env.OXIDE = engines.engine.oxide
})
fn(engines)
})
}