|
11 | 11 | // SPDX-License-Identifier: Apache-2.0 |
12 | 12 | // |
13 | 13 | //===----------------------------------------------------------------------===// |
14 | | -// Use source-map-support to get better stack traces |
15 | | -import "source-map-support/register"; |
16 | | - |
17 | 14 | import * as chai from "chai"; |
18 | 15 | import * as chaiAsPromised from "chai-as-promised"; |
19 | 16 | import * as chaiSubset from "chai-subset"; |
20 | 17 | import * as fs from "fs"; |
| 18 | +import * as mockFS from "mock-fs"; |
21 | 19 | import * as path from "path"; |
22 | 20 | import * as sinonChai from "sinon-chai"; |
| 21 | +import * as sourceMapSupport from "source-map-support"; |
23 | 22 | import * as tsConfigPaths from "tsconfig-paths"; |
24 | 23 |
|
25 | 24 | import { installTagSupport } from "./tags"; |
26 | 25 |
|
| 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 | + |
27 | 42 | const tsConfig = JSON.parse( |
28 | 43 | // __dirname points to dist/test when transpiled, but we need the tsconfig.json in the real test/ |
29 | 44 | fs.readFileSync(path.join(__dirname, "../../test/tsconfig.json"), "utf-8") |
|
0 commit comments