-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspec-tests.test.ts
47 lines (43 loc) · 1.92 KB
/
spec-tests.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
import assert from "node:assert";
import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from 'node:url';
import validateSourceMap from "./index.js";
import sourceMapSpecTests from "../source-map-tests/source-map-spec-tests.json" assert { type: "json" };
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const specResourcesBaseDir = path.resolve(__dirname, "../../source-map-tests/resources");
// These tests are known failures that aren't easily fixed at the moment.
const knownFailures = [
// Source maps library does not consider this a parse error.
"invalidMappingSegmentWithZeroFields",
// Source maps library ignores the sign bit in the size limit.
"invalidMappingSegmentWithColumnExceeding32Bits",
// This one has a valid format, but out of range values for the source.
"validMappingFieldsWith32BitMaxValues",
// Source maps library errors on this.
"validMappingLargeVLQ",
];
test.describe("runSourceMapSpecTests", () => {
sourceMapSpecTests.tests.forEach((testCase) => {
test(`The source map spec test case "${testCase.name}" has ${testCase.sourceMapIsValid ? "a valid" : "an invalid"} source map`, async (t) => {
if (knownFailures.includes(testCase.name)) {
t.todo("This test has a known failure and doesn't fail the test suite");
}
const result = await validateSourceMap([
"--sourceMap",
`${specResourcesBaseDir}/${testCase.sourceMapFile}`,
"--generatedFile",
`${specResourcesBaseDir}/${testCase.baseFile}`,
"--originalFolder",
`${specResourcesBaseDir}`,
]);
if (testCase.sourceMapIsValid)
assert.deepEqual(result, { isValid: true }, "expected source map to be valid");
else {
assert.equal(result.isValid, false, "expected source map to be invalid");
if (!result.isValid && result.errors[0])
t.diagnostic(result.errors[0].message);
}
});
});
});