-
Notifications
You must be signed in to change notification settings - Fork 17
/
regression.test.ts
48 lines (34 loc) · 1.48 KB
/
regression.test.ts
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
import fs from 'node:fs'
import fg from 'fast-glob';
import path from 'node:path';
import {Problem, Config, Linter} from '../src/index'
const pattern = "./regression-tests/general/*.yaml"
const yamlfiles = fg.globSync(pattern)
const customconfig = "./regression-tests/customconfig/*.yaml"
describe("Default Config Regression Tests",()=>{
test.each(yamlfiles)("%s",async (yamlSrcPath)=>{
const cfg: Config = Config.getDefaultConfig()
cfg.globs=[yamlSrcPath]
const problems: Problem[] = await Linter.run(cfg)
const expectedPath =`${yamlSrcPath}.expect.json`
if (!fs.existsSync(expectedPath)){
fs.writeFileSync(expectedPath, JSON.stringify(problems))
}
const expected = JSON.parse(fs.readFileSync(expectedPath,'utf-8'))
expect(problems).toMatchObject(expected)
})
})
describe("Custom Config Regression Tests",()=>{
test.each(fg.globSync(customconfig))("%s", async (yamlSrcPath)=>{
const cfgPath = path.resolve(path.dirname(yamlSrcPath))
const cfg: Config = Config.getConfig(cfgPath);
cfg.globs=[yamlSrcPath]
const problems: Problem[] = await Linter.run(cfg)
const expectedPath =`${yamlSrcPath}.expect.json`
if (!fs.existsSync(expectedPath)){
fs.writeFileSync(expectedPath, JSON.stringify(problems))
}
const expected = JSON.parse(fs.readFileSync(expectedPath,'utf-8'))
expect(problems).toMatchObject(expected)
})
})