|
1
|
|
|
import {readFileSync} from 'fs' |
|
2
|
|
|
import type { Options } from './src/options.types' |
|
3
|
|
|
import postcss7 = require("postcss") |
|
4
|
|
|
import creator7 = require("./src/7") |
|
5
|
|
|
import postcss8 from 'postcss8' |
|
6
|
|
|
import creator8 = require("./src") |
|
7
|
|
|
|
|
8
|
|
|
export type RunOpts = Partial<{ |
|
9
|
|
|
from: string |
|
10
|
|
|
input: string |
|
11
|
|
|
output: string[] |
|
12
|
|
|
errorsCount: number |
|
13
|
|
|
}> |
|
14
|
|
|
|
|
15
|
|
|
const {parse: $parse} = JSON |
|
16
|
|
|
, launcher7 = (opts?: Options) => postcss7([creator7(opts)]) |
|
17
|
|
|
, launcher8 = (opts?: Options) => postcss8([creator8(opts)]) |
|
18
|
|
|
, launchers = [launcher7, launcher8] |
|
19
|
|
|
|
|
20
|
|
|
export default run |
|
21
|
|
|
export { |
|
22
|
|
|
rfs, rfsl, readOpts, suiteName |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
async function run(runOpts: RunOpts, opts?: Options) { |
|
26
|
|
|
const { |
|
27
|
|
|
errorsCount = 0, |
|
28
|
|
|
from, |
|
29
|
|
|
input = from && rfs(from), |
|
30
|
|
|
} = runOpts |
|
31
|
|
|
if (!input) |
|
32
|
|
|
throw Error("no test input") |
|
33
|
|
|
|
|
34
|
|
|
for (let i = 0; i < launchers.length; i++) { |
|
35
|
|
|
const result = await launchers[i](opts).process(input, { from }) |
|
36
|
|
|
, { |
|
37
|
|
|
//TODO propagate modality with opts |
|
38
|
|
|
output = from && rfsl(`${from.replace(/\.css$/, '')}.SHOULD.d.ts`) |
|
39
|
|
|
} = runOpts |
|
40
|
|
|
|
|
41
|
|
|
expect(result.warnings()).toHaveLength(errorsCount) |
|
42
|
|
|
|
|
43
|
|
|
output && expect(rfsl(`${from}.d.ts`)).toStrictEqual(output) |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function rfs(path: string) { |
|
48
|
|
|
return readFileSync(path).toString() |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function rfsl(path: string) { |
|
52
|
|
|
return rfs(path).split('\n') |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function readOpts(path: string) { |
|
56
|
|
|
return $parse(rfs(path)) as Options |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function suiteName(path: string) { |
|
60
|
|
|
return path |
|
61
|
|
|
.replace(/^.*[\/\\]/, '') |
|
62
|
|
|
.replace(/\..*$/, '') |
|
63
|
|
|
} |
|
64
|
|
|
|