diff --git a/package-lock.json b/package-lock.json index b1057c4d4..dcf6b57f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "@types/semver": "^7.7.1", "@types/sinon": "^17.0.4", "@types/sinon-chai": "^3.2.12", + "@types/source-map-support": "^0.5.10", "@types/svg2ttf": "^5.0.3", "@types/svgicons2svgfont": "^10.0.5", "@types/ttf2woff": "^2.0.4", @@ -2370,6 +2371,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/source-map-support": { + "version": "0.5.10", + "resolved": "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.10.tgz", + "integrity": "sha512-tgVP2H469x9zq34Z0m/fgPewGhg/MLClalNOiPIzQlXrSS2YrKu/xCdSCKnEDwkFha51VKEKB6A9wW26/ZNwzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "source-map": "^0.6.0" + } + }, "node_modules/@types/svg2ttf": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/@types/svg2ttf/-/svg2ttf-5.0.3.tgz", @@ -13256,6 +13267,15 @@ "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", "dev": true }, + "@types/source-map-support": { + "version": "0.5.10", + "resolved": "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.10.tgz", + "integrity": "sha512-tgVP2H469x9zq34Z0m/fgPewGhg/MLClalNOiPIzQlXrSS2YrKu/xCdSCKnEDwkFha51VKEKB6A9wW26/ZNwzA==", + "dev": true, + "requires": { + "source-map": "^0.6.0" + } + }, "@types/svg2ttf": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/@types/svg2ttf/-/svg2ttf-5.0.3.tgz", diff --git a/package.json b/package.json index d4dec5478..0f9595da9 100644 --- a/package.json +++ b/package.json @@ -2035,6 +2035,7 @@ "@types/semver": "^7.7.1", "@types/sinon": "^17.0.4", "@types/sinon-chai": "^3.2.12", + "@types/source-map-support": "^0.5.10", "@types/svg2ttf": "^5.0.3", "@types/svgicons2svgfont": "^10.0.5", "@types/ttf2woff": "^2.0.4", diff --git a/test/common.ts b/test/common.ts index 3d8043a31..a966a2828 100644 --- a/test/common.ts +++ b/test/common.ts @@ -11,19 +11,34 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -// Use source-map-support to get better stack traces -import "source-map-support/register"; - import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; import * as chaiSubset from "chai-subset"; import * as fs from "fs"; +import * as mockFS from "mock-fs"; import * as path from "path"; import * as sinonChai from "sinon-chai"; +import * as sourceMapSupport from "source-map-support"; import * as tsConfigPaths from "tsconfig-paths"; import { installTagSupport } from "./tags"; +// Use source-map-support to get better stack traces. +// +// We have to override retrieveFile() here because any test that uses mock-fs will break +// source map lookups. This will make sure that, even if mock-fs is in effect, source map +// support can still find the files that it needs to. +sourceMapSupport.install({ + retrieveFile(path: string): string | null { + return mockFS.bypass(() => { + if (!fs.existsSync(path)) { + return null; + } + return fs.readFileSync(path, "utf-8"); + }); + }, +}); + const tsConfig = JSON.parse( // __dirname points to dist/test when transpiled, but we need the tsconfig.json in the real test/ fs.readFileSync(path.join(__dirname, "../../test/tsconfig.json"), "utf-8")