|
1 | 1 | import * as path from "path"; |
2 | 2 | import * as util from "../util"; |
3 | 3 |
|
4 | | -const projectPath = path.resolve(__dirname, "module-resolution", "project-with-node-modules"); |
| 4 | +describe("basic module resolution", () => { |
| 5 | + const projectPath = path.resolve(__dirname, "module-resolution", "project-with-node-modules"); |
5 | 6 |
|
6 | | -const projectWithNodeModules = util |
7 | | - .testProject(path.join(projectPath, "tsconfig.json")) |
8 | | - .setMainFileName(path.join(projectPath, "main.ts")); |
| 7 | + const projectWithNodeModules = util |
| 8 | + .testProject(path.join(projectPath, "tsconfig.json")) |
| 9 | + .setMainFileName(path.join(projectPath, "main.ts")); |
9 | 10 |
|
10 | | -test("can resolve global dependencies with declarations", () => { |
11 | | - // Declarations in the node_modules directory |
12 | | - expect(projectWithNodeModules.getLuaExecutionResult().globalWithDeclarationsResults).toEqual({ |
13 | | - foo: "foo from lua global with decls", |
14 | | - bar: "bar from lua global with decls: global with declarations!", |
15 | | - baz: "baz from lua global with decls", |
| 11 | + test("can resolve global dependencies with declarations", () => { |
| 12 | + // Declarations in the node_modules directory |
| 13 | + expect(projectWithNodeModules.getLuaExecutionResult().globalWithDeclarationsResults).toEqual({ |
| 14 | + foo: "foo from lua global with decls", |
| 15 | + bar: "bar from lua global with decls: global with declarations!", |
| 16 | + baz: "baz from lua global with decls", |
| 17 | + }); |
16 | 18 | }); |
17 | | -}); |
18 | 19 |
|
19 | | -test("can resolve global dependencies with hand-written declarations", () => { |
20 | | - // No declarations in the node_modules directory, but written by hand in project dir |
21 | | - expect(projectWithNodeModules.getLuaExecutionResult().globalWithoutDeclarationsResults).toEqual({ |
22 | | - foo: "foo from lua global without decls", |
23 | | - bar: "bar from lua global without decls: global without declarations!", |
24 | | - baz: "baz from lua global without decls", |
| 20 | + test("can resolve global dependencies with hand-written declarations", () => { |
| 21 | + // No declarations in the node_modules directory, but written by hand in project dir |
| 22 | + expect(projectWithNodeModules.getLuaExecutionResult().globalWithoutDeclarationsResults).toEqual({ |
| 23 | + foo: "foo from lua global without decls", |
| 24 | + bar: "bar from lua global without decls: global without declarations!", |
| 25 | + baz: "baz from lua global without decls", |
| 26 | + }); |
25 | 27 | }); |
26 | | -}); |
27 | 28 |
|
28 | | -test("can resolve module dependencies with declarations", () => { |
29 | | - // Declarations in the node_modules directory |
30 | | - expect(projectWithNodeModules.getLuaExecutionResult().moduleWithDeclarationsResults).toEqual({ |
31 | | - foo: "foo from lua module with decls", |
32 | | - bar: "bar from lua module with decls: module with declarations!", |
33 | | - baz: "baz from lua module with decls", |
| 29 | + test("can resolve module dependencies with declarations", () => { |
| 30 | + // Declarations in the node_modules directory |
| 31 | + expect(projectWithNodeModules.getLuaExecutionResult().moduleWithDeclarationsResults).toEqual({ |
| 32 | + foo: "foo from lua module with decls", |
| 33 | + bar: "bar from lua module with decls: module with declarations!", |
| 34 | + baz: "baz from lua module with decls", |
| 35 | + }); |
34 | 36 | }); |
35 | | -}); |
36 | 37 |
|
37 | | -test("can resolve module dependencies with hand-written declarations", () => { |
38 | | - // Declarations in the node_modules directory |
39 | | - expect(projectWithNodeModules.getLuaExecutionResult().moduleWithoutDeclarationsResults).toEqual({ |
40 | | - foo: "foo from lua module without decls", |
41 | | - bar: "bar from lua module without decls: module without declarations!", |
42 | | - baz: "baz from lua module without decls", |
| 38 | + test("can resolve module dependencies with hand-written declarations", () => { |
| 39 | + // Declarations in the node_modules directory |
| 40 | + expect(projectWithNodeModules.getLuaExecutionResult().moduleWithoutDeclarationsResults).toEqual({ |
| 41 | + foo: "foo from lua module without decls", |
| 42 | + bar: "bar from lua module without decls: module without declarations!", |
| 43 | + baz: "baz from lua module without decls", |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + test("can resolve package depencency with a dependency on another package", () => { |
| 48 | + // Declarations in the node_modules directory |
| 49 | + expect(projectWithNodeModules.getLuaExecutionResult().moduleWithDependencyResult).toEqual( |
| 50 | + "Calling dependency: foo from lua module with decls" |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + test("resolved package dependency included in bundle", () => { |
| 55 | + const mainFile = path.join(projectPath, "main.ts"); |
| 56 | + util.testProject(path.join(projectPath, "tsconfig.json")) |
| 57 | + .setMainFileName(mainFile) |
| 58 | + .setOptions({ luaBundle: "bundle.lua", luaBundleEntry: mainFile }) |
| 59 | + .expectToEqual({ |
| 60 | + globalWithDeclarationsResults: { |
| 61 | + foo: "foo from lua global with decls", |
| 62 | + bar: "bar from lua global with decls: global with declarations!", |
| 63 | + baz: "baz from lua global with decls", |
| 64 | + }, |
| 65 | + globalWithoutDeclarationsResults: { |
| 66 | + foo: "foo from lua global without decls", |
| 67 | + bar: "bar from lua global without decls: global without declarations!", |
| 68 | + baz: "baz from lua global without decls", |
| 69 | + }, |
| 70 | + moduleWithDeclarationsResults: { |
| 71 | + foo: "foo from lua module with decls", |
| 72 | + bar: "bar from lua module with decls: module with declarations!", |
| 73 | + baz: "baz from lua module with decls", |
| 74 | + }, |
| 75 | + moduleWithDependencyResult: "Calling dependency: foo from lua module with decls", |
| 76 | + moduleWithoutDeclarationsResults: { |
| 77 | + foo: "foo from lua module without decls", |
| 78 | + bar: "bar from lua module without decls: module without declarations!", |
| 79 | + baz: "baz from lua module without decls", |
| 80 | + }, |
| 81 | + }); |
43 | 82 | }); |
44 | 83 | }); |
45 | 84 |
|
46 | | -test("can resolve package depencency with a dependency on another package", () => { |
47 | | - // Declarations in the node_modules directory |
48 | | - expect(projectWithNodeModules.getLuaExecutionResult().moduleWithDependencyResult).toEqual( |
49 | | - "Calling dependency: foo from lua module with decls" |
50 | | - ); |
| 85 | +describe("module resolution with chained dependencies", () => { |
| 86 | + const projectPath = path.resolve(__dirname, "module-resolution", "project-with-dependency-chain"); |
| 87 | + |
| 88 | + test("can resolve dependencies in chain", () => { |
| 89 | + util.testProject(path.join(projectPath, "tsconfig.json")) |
| 90 | + .setMainFileName(path.join(projectPath, "main.ts")) |
| 91 | + .expectToEqual({}); |
| 92 | + }); |
| 93 | + |
| 94 | + test.only("resolved package dependency included in bundle", () => { |
| 95 | + const mainFile = path.join(projectPath, "main.ts"); |
| 96 | + util.testProject(path.join(projectPath, "tsconfig.json")) |
| 97 | + .setMainFileName(mainFile) |
| 98 | + .setOptions({ luaBundle: "bundle.lua", luaBundleEntry: mainFile }) |
| 99 | + .debug() |
| 100 | + .expectToEqual({}); |
| 101 | + }); |
51 | 102 | }); |
0 commit comments