|
1 | 1 | // noinspection ES6UnusedImports
|
2 |
| -import * as path from "node:path"; |
| 2 | +import path from "node:path"; |
3 | 3 | import { createTsSolutionBuilder, EmittedFiles } from "../utils";
|
4 | 4 | import { projectsPaths, ts } from "../config";
|
5 | 5 |
|
6 |
| -/* ****************************************************************************************************************** * |
7 |
| - * Config |
8 |
| - * ****************************************************************************************************************** */ |
9 |
| - |
10 | 6 | /* File Paths */
|
11 | 7 | const projectDir = ts.normalizePath(path.join(projectsPaths, "project-ref"));
|
12 |
| -const indexFile = ts.normalizePath(path.join(projectDir, "lib/b/index.ts")); |
13 | 8 |
|
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 | +} |
17 | 21 |
|
18 | 22 | // 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 | +`); |
36 | 50 | });
|
0 commit comments