forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-entry.test.ts
143 lines (130 loc) · 2.99 KB
/
get-entry.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
142
143
import path from "path";
import dedent from "ts-dedent";
import { defaultWranglerConfig } from "../config/config";
import { getEntry } from "../deployment-bundle/entry";
import { mockConsoleMethods } from "./helpers/mock-console";
import { runInTempDir } from "./helpers/run-in-tmp";
import { seed } from "./helpers/seed";
import type { Entry } from "../deployment-bundle/entry";
function normalize(entry: Entry): Entry {
const tmpDir = process.cwd();
const tmpDirName = path.basename(tmpDir);
return Object.fromEntries(
Object.entries(entry).map(([k, v]) => [
k,
typeof v === "string"
? v
.replaceAll("\\", "/")
.replace(new RegExp(`(.*${tmpDirName})`), `/tmp/dir`)
: v,
])
) as Entry;
}
describe("getEntry()", () => {
runInTempDir();
mockConsoleMethods();
it("--script index.ts", async () => {
await seed({
"index.ts": dedent/* javascript */ `
export default {
fetch() {
}
}
`,
});
const entry = await getEntry(
{ script: "index.ts" },
defaultWranglerConfig,
"deploy"
);
expect(normalize(entry)).toMatchObject({
projectRoot: "/tmp/dir",
file: "/tmp/dir/index.ts",
moduleRoot: "/tmp/dir",
});
});
it("--script src/index.ts", async () => {
await seed({
"src/index.ts": dedent/* javascript */ `
export default {
fetch() {
}
}
`,
});
const entry = await getEntry(
{ script: "src/index.ts" },
defaultWranglerConfig,
"deploy"
);
expect(normalize(entry)).toMatchObject({
projectRoot: "/tmp/dir",
file: "/tmp/dir/src/index.ts",
moduleRoot: "/tmp/dir/src",
});
});
it("main = index.ts", async () => {
await seed({
"index.ts": dedent/* javascript */ `
export default {
fetch() {
}
}
`,
});
const entry = await getEntry(
{},
{ ...defaultWranglerConfig, main: "index.ts" },
"deploy"
);
expect(normalize(entry)).toMatchObject({
projectRoot: "/tmp/dir",
file: "/tmp/dir/index.ts",
moduleRoot: "/tmp/dir",
});
});
it("main = src/index.ts", async () => {
await seed({
"src/index.ts": dedent/* javascript */ `
export default {
fetch() {
}
}
`,
});
const entry = await getEntry(
{},
{ ...defaultWranglerConfig, main: "src/index.ts" },
"deploy"
);
expect(normalize(entry)).toMatchObject({
projectRoot: "/tmp/dir",
file: "/tmp/dir/src/index.ts",
moduleRoot: "/tmp/dir/src",
});
});
it("main = src/index.ts w/ configPath", async () => {
await seed({
"other-worker/src/index.ts": dedent/* javascript */ `
export default {
fetch() {
}
}
`,
});
const entry = await getEntry(
{},
{
...defaultWranglerConfig,
main: "src/index.ts",
configPath: "other-worker/wrangler.toml",
},
"deploy"
);
expect(normalize(entry)).toMatchObject({
projectRoot: "/tmp/dir/other-worker",
file: "/tmp/dir/other-worker/src/index.ts",
moduleRoot: "/tmp/dir/other-worker/src",
});
});
});