Skip to content

Commit 4929e5c

Browse files
committed
use snapshots
1 parent 78736c6 commit 4929e5c

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

test/tests/project-ref.test.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
// noinspection ES6UnusedImports
2-
import * as path from "node:path";
2+
import path from "node:path";
33
import { createTsSolutionBuilder, EmittedFiles } from "../utils";
44
import { projectsPaths, ts } from "../config";
55

6-
/* ****************************************************************************************************************** *
7-
* Config
8-
* ****************************************************************************************************************** */
9-
106
/* File Paths */
117
const projectDir = ts.normalizePath(path.join(projectsPaths, "project-ref"));
12-
const indexFile = ts.normalizePath(path.join(projectDir, "lib/b/index.ts"));
138

14-
/* ****************************************************************************************************************** *
15-
* Tests
16-
* ****************************************************************************************************************** */
9+
/**
10+
* @exapmle
11+
* const builder = createTsSolutionBuilder({ tsInstance: ts, projectDir });
12+
* const emittedFiles = getRelativeEmittedFiles(builder.getEmitFiles());
13+
*/
14+
function getRelativeEmittedFiles(pathRecord: EmittedFiles) {
15+
const result = {} as EmittedFiles;
16+
for (const key in pathRecord) {
17+
result[path.relative(projectDir, key)] = pathRecord[key];
18+
}
19+
return result;
20+
}
1721

1822
// see: https://github.com/LeDDGroup/typescript-transform-paths/issues/125
19-
describe(`Project References`, () => {
20-
let emittedFiles: EmittedFiles;
21-
22-
beforeAll(() => {
23-
const builder = createTsSolutionBuilder({ tsInstance: ts, projectDir });
24-
emittedFiles = builder.getEmitFiles();
25-
});
26-
27-
test(`Specifier for referenced project file resolves properly`, () => {
28-
expect(emittedFiles[indexFile].js).toMatch(`export { AReffedConst } from "../a/index"`);
29-
expect(emittedFiles[indexFile].dts).toMatch(`export { AReffedConst } from "../a/index"`);
30-
});
31-
32-
test(`Specifier for local file resolves properly`, () => {
33-
expect(emittedFiles[indexFile].js).toMatch(`export { LocalConst } from "./local/index"`);
34-
expect(emittedFiles[indexFile].dts).toMatch(`export { LocalConst } from "./local/index"`);
35-
});
23+
test("project references", () => {
24+
const builder = createTsSolutionBuilder({ tsInstance: ts, projectDir });
25+
const emittedFiles = getRelativeEmittedFiles(builder.getEmitFiles());
26+
expect(emittedFiles).toMatchInlineSnapshot(`
27+
{
28+
"lib/a/index.ts": {
29+
"dts": "export declare const AReffedConst = 43;
30+
",
31+
"js": "export const AReffedConst = 43;
32+
",
33+
},
34+
"lib/b/index.ts": {
35+
"dts": "export { AReffedConst } from "../a/index";
36+
export { LocalConst } from "./local/index";
37+
",
38+
"js": "export { AReffedConst } from "../a/index";
39+
export { LocalConst } from "./local/index";
40+
",
41+
},
42+
"lib/b/local/index.ts": {
43+
"dts": "export declare const LocalConst = 55;
44+
",
45+
"js": "export const LocalConst = 55;
46+
",
47+
},
48+
}
49+
`);
3650
});

0 commit comments

Comments
 (0)