Skip to content

Commit 6228bd4

Browse files
fix source mapping in tests (#1891)
1 parent 36b7df9 commit 6228bd4

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,7 @@
20352035
"@types/semver": "^7.7.1",
20362036
"@types/sinon": "^17.0.4",
20372037
"@types/sinon-chai": "^3.2.12",
2038+
"@types/source-map-support": "^0.5.10",
20382039
"@types/svg2ttf": "^5.0.3",
20392040
"@types/svgicons2svgfont": "^10.0.5",
20402041
"@types/ttf2woff": "^2.0.4",

test/common.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,34 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
// Use source-map-support to get better stack traces
15-
import "source-map-support/register";
16-
1714
import * as chai from "chai";
1815
import * as chaiAsPromised from "chai-as-promised";
1916
import * as chaiSubset from "chai-subset";
2017
import * as fs from "fs";
18+
import * as mockFS from "mock-fs";
2119
import * as path from "path";
2220
import * as sinonChai from "sinon-chai";
21+
import * as sourceMapSupport from "source-map-support";
2322
import * as tsConfigPaths from "tsconfig-paths";
2423

2524
import { installTagSupport } from "./tags";
2625

26+
// Use source-map-support to get better stack traces.
27+
//
28+
// We have to override retrieveFile() here because any test that uses mock-fs will break
29+
// source map lookups. This will make sure that, even if mock-fs is in effect, source map
30+
// support can still find the files that it needs to.
31+
sourceMapSupport.install({
32+
retrieveFile(path: string): string | null {
33+
return mockFS.bypass(() => {
34+
if (!fs.existsSync(path)) {
35+
return null;
36+
}
37+
return fs.readFileSync(path, "utf-8");
38+
});
39+
},
40+
});
41+
2742
const tsConfig = JSON.parse(
2843
// __dirname points to dist/test when transpiled, but we need the tsconfig.json in the real test/
2944
fs.readFileSync(path.join(__dirname, "../../test/tsconfig.json"), "utf-8")

0 commit comments

Comments
 (0)