/
entry-point.test.ts
141 lines (123 loc) · 4.02 KB
/
entry-point.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { tempdirProject } from "@typestrong/fs-fixture-builder";
import { deepStrictEqual as equal, ok } from "assert";
import { join } from "path";
import { tmpdir } from "os";
import { Application, EntryPointStrategy, TSConfigReader } from "../..";
const fixture = tempdirProject();
fixture.addJsonFile("tsconfig.json", {
include: ["."],
});
fixture.addJsonFile("package.json", {
main: "index.ts",
});
fixture.addFile("index.ts", "export function fromIndex() {}");
fixture.addFile("extra.ts", "export function extra() {}");
describe("Entry Points", () => {
beforeEach(() => {
fixture.write();
});
afterEach(() => {
fixture.rm();
});
const app = new Application();
const tsconfig = join(fixture.cwd, "tsconfig.json");
app.options.addReader(new TSConfigReader());
it("Supports expanding existing paths", () => {
app.bootstrap({
tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Expand,
});
const entryPoints = app.getEntryPoints();
ok(entryPoints);
equal(
entryPoints.length,
2,
"There are two files, so both should be expanded"
);
});
it("Supports expanding globs in paths", () => {
app.bootstrap({
tsconfig,
entryPoints: [`${fixture.cwd}/*.ts`],
entryPointStrategy: EntryPointStrategy.Expand,
});
const entryPoints = app.getEntryPoints();
ok(entryPoints);
equal(
entryPoints.length,
2,
"There are two files, so both should be expanded"
);
});
it("Supports resolving directories", () => {
app.bootstrap({
tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Resolve,
});
const entryPoints = app.getEntryPoints();
ok(entryPoints);
equal(
entryPoints.length,
1,
"entry-points/index.ts should have been the sole entry point"
);
});
it("Supports resolving packages", () => {
app.bootstrap({
tsconfig: tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Packages,
});
const entryPoints = app.getEntryPoints();
ok(entryPoints);
equal(entryPoints.length, 1);
equal(entryPoints[0].version, void 0);
});
it("Supports resolving packages outside of cwd", () => {
const fixture = tempdirProject({ rootDir: tmpdir() });
fixture.addJsonFile("tsconfig.json", {
include: ["."],
});
fixture.addJsonFile("package.json", {
main: "index.ts",
});
fixture.addFile("index.ts", "export function fromIndex() {}");
fixture.write();
app.bootstrap({
tsconfig: tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Packages,
});
const entryPoints = app.getEntryPoints();
fixture.rm();
ok(entryPoints);
equal(entryPoints.length, 1);
equal(entryPoints[0].version, void 0);
});
it("Supports custom tsconfig files #2061", () => {
const fixture = tempdirProject({ rootDir: tmpdir() });
fixture.addJsonFile("tsconfig.lib.json", {
include: ["."],
});
fixture.addJsonFile("package.json", {
main: "index.ts",
typedoc: {
tsconfig: "tsconfig.lib.json",
},
});
fixture.addFile("index.ts", "export function fromIndex() {}");
fixture.write();
app.bootstrap({
tsconfig: tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Packages,
});
const entryPoints = app.getEntryPoints();
fixture.rm();
ok(entryPoints);
equal(entryPoints.length, 1);
equal(entryPoints[0].version, void 0);
});
});