-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathoutput.test.mjs
More file actions
33 lines (30 loc) · 1.23 KB
/
output.test.mjs
File metadata and controls
33 lines (30 loc) · 1.23 KB
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
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Blaze } from './index.mjs';
import { compileSchema } from './compile.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const SUITE_DIR = join(__dirname, '..', '..', 'test', 'output');
function runSuite(suiteName, fileName, format) {
const filePath = join(SUITE_DIR, fileName);
const tests = JSON.parse(readFileSync(filePath, 'utf8'), Blaze.reviver);
describe(suiteName, () => {
for (const [ index, testCase ] of tests.entries()) {
for (const mode of [ 'fast', 'exhaustive' ]) {
it(`${testCase.description}_${mode}`, () => {
const template = compileSchema(filePath, {
mode,
path: `/${index}/schema`
});
const evaluator = new Blaze(template);
const actual = evaluator.validate(testCase.instance, format);
assert.deepStrictEqual(actual, testCase[mode]);
});
}
}
});
}
runSuite('output_standard_flag', 'output_standard_flag.json', 'flag');
runSuite('output_standard_basic', 'output_standard_basic.json', 'basic');