Skip to content

Commit 7a79881

Browse files
committed
Added more in-project dependency checks to sourceDir test
1 parent c080110 commit 7a79881

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

test/transpile/module-resolution.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,33 @@ describe("basic module resolution", () => {
8484

8585
describe("module resolution with chained dependencies", () => {
8686
const projectPath = path.resolve(__dirname, "module-resolution", "project-with-dependency-chain");
87+
const expectedResult = { result: "dependency3" };
8788

8889
test("can resolve dependencies in chain", () => {
8990
util.testProject(path.join(projectPath, "tsconfig.json"))
9091
.setMainFileName(path.join(projectPath, "main.ts"))
91-
.expectToEqual({ result: "dependency3" });
92+
.expectToEqual(expectedResult);
9293
});
9394

9495
test("resolved package dependency included in bundle", () => {
9596
const mainFile = path.join(projectPath, "main.ts");
9697
util.testProject(path.join(projectPath, "tsconfig.json"))
9798
.setMainFileName(mainFile)
9899
.setOptions({ luaBundle: "bundle.lua", luaBundleEntry: mainFile })
99-
.expectToEqual({ result: "dependency3" });
100+
.expectToEqual(expectedResult);
100101
});
101102
});
102103

103104
describe("module resolution with outDir", () => {
104105
const projectPath = path.resolve(__dirname, "module-resolution", "project-with-dependency-chain");
106+
const expectedResult = { result: "dependency3" };
105107

106108
test("emits files in outDir", () => {
107109
const builder = util
108110
.testProject(path.join(projectPath, "tsconfig.json"))
109111
.setMainFileName(path.join(projectPath, "main.ts"))
110112
.setOptions({ outDir: "tstl-out" })
111-
.expectToEqual({ result: "dependency3" });
113+
.expectToEqual(expectedResult);
112114

113115
// Get the output paths relative to the project path
114116
const outPaths = builder.getLuaResult().transpiledFiles.map(f => path.relative(projectPath, f.outPath));
@@ -126,7 +128,7 @@ describe("module resolution with outDir", () => {
126128
.testProject(path.join(projectPath, "tsconfig.json"))
127129
.setMainFileName(mainFile)
128130
.setOptions({ outDir: "tstl-out", luaBundle: "bundle.lua", luaBundleEntry: mainFile })
129-
.expectToEqual({ result: "dependency3" });
131+
.expectToEqual(expectedResult);
130132

131133
// Get the output paths relative to the project path
132134
const outPaths = builder.getLuaResult().transpiledFiles.map(f => path.relative(projectPath, f.outPath));
@@ -137,19 +139,26 @@ describe("module resolution with outDir", () => {
137139

138140
describe("module resolution with sourceDir", () => {
139141
const projectPath = path.resolve(__dirname, "module-resolution", "project-with-sourceDir");
142+
const expectedResult = {
143+
result: "dependency3",
144+
functionInSubDir: "non-node_modules import",
145+
functionReExportedFromSubDir: "nested func result",
146+
nestedFunctionInSubDirOfSubDir: "nested func result",
147+
nestedFunctionUsingFunctionFromParentDir: "nested func: non-node_modules import 2",
148+
};
140149

141150
test("can resolve dependencies with sourceDir", () => {
142151
util.testProject(path.join(projectPath, "tsconfig.json"))
143152
.setMainFileName(path.join(projectPath, "src", "main.ts"))
144153
.setOptions({ outDir: "tstl-out" })
145-
.expectToEqual({ result: "dependency3", result2: "non-node_modules import" });
154+
.expectToEqual(expectedResult);
146155
});
147156

148157
test("can resolve dependencies and bundle files with sourceDir", () => {
149158
const mainFile = path.join(projectPath, "src", "main.ts");
150159
util.testProject(path.join(projectPath, "tsconfig.json"))
151160
.setMainFileName(mainFile)
152161
.setOptions({ luaBundle: "bundle.lua", luaBundleEntry: mainFile })
153-
.expectToEqual({ result: "dependency3", result2: "non-node_modules import" });
162+
.expectToEqual(expectedResult);
154163
});
155164
});
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as dependency1 from "dependency1";
2-
import { func } from "./subdir/otherfile";
2+
import { func, nestedFunc } from "./subdir/otherfile";
3+
import { nestedFunc as nestedFuncOriginal, nestedFuncUsingParent } from "./subdir/subdirofsubdir/nestedfile";
34

45
export const result = dependency1.f1();
5-
export const result2 = func();
6+
export const functionInSubDir = func();
7+
export const functionReExportedFromSubDir = nestedFunc();
8+
export const nestedFunctionInSubDirOfSubDir = nestedFuncOriginal();
9+
export const nestedFunctionUsingFunctionFromParentDir = nestedFuncUsingParent();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export function func() {
22
return "non-node_modules import";
33
}
4+
5+
export { nestedFunc } from "./subdirofsubdir/nestedfile";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function func2() {
2+
return "non-node_modules import 2";
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { func2 } from "../otherfile2";
2+
3+
export function nestedFunc() {
4+
return "nested func result";
5+
}
6+
7+
export function nestedFuncUsingParent() {
8+
return `nested func: ${func2()}`;
9+
}

0 commit comments

Comments
 (0)