-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { writeFile } from "fs/promises"; | ||
Check failure on line 1 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import path from "path"; | ||
Check failure on line 2 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import dedent from "ts-dedent"; | ||
import { Config } from "../config"; | ||
Check failure on line 4 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import { defaultWranglerConfig } from "../config/config"; | ||
import { Entry, getEntry } from "../deployment-bundle/entry"; | ||
import guessWorkerFormat from "../deployment-bundle/guess-worker-format"; | ||
Check failure on line 7 in packages/wrangler/src/__tests__/get-entry.test.ts GitHub Actions / Checks
|
||
import { mockConsoleMethods } from "./helpers/mock-console"; | ||
import { runInTempDir } from "./helpers/run-in-tmp"; | ||
import { seed } from "./helpers/seed"; | ||
|
||
function normalize(entry: Entry): Entry { | ||
return JSON.parse( | ||
JSON.stringify(entry).replaceAll(process.cwd(), "/tmp/dir") | ||
); | ||
} | ||
describe("getEntry()", () => { | ||
runInTempDir(); | ||
mockConsoleMethods(); | ||
it.each([ | ||
[ | ||
"--script index.ts", | ||
{ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}, | ||
{ script: "index.ts" }, | ||
{}, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}, | ||
], | ||
[ | ||
"--script src/index.ts", | ||
{ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}, | ||
{ script: "src/index.ts" }, | ||
{}, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}, | ||
], | ||
[ | ||
"main = index.ts", | ||
{ | ||
"index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ main: "index.ts" }, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/index.ts", | ||
moduleRoot: "/tmp/dir", | ||
}, | ||
], | ||
[ | ||
"main = src/index.ts", | ||
{ | ||
"src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ main: "src/index.ts" }, | ||
{ | ||
directory: "/tmp/dir", | ||
file: "/tmp/dir/src/index.ts", | ||
moduleRoot: "/tmp/dir/src", | ||
}, | ||
], | ||
[ | ||
"main = src/index.ts w/ configPath", | ||
{ | ||
"other-worker/src/index.ts": dedent/* javascript */ ` | ||
export default { | ||
fetch() { | ||
} | ||
} | ||
`, | ||
}, | ||
{}, | ||
{ | ||
main: "src/index.ts", | ||
configPath: "other-worker/wrangler.toml", | ||
}, | ||
{ | ||
directory: "/tmp/dir/other-worker", | ||
file: "/tmp/dir/other-worker/src/index.ts", | ||
moduleRoot: "/tmp/dir/other-worker/src", | ||
}, | ||
], | ||
])("%s", async (_name, files, args, config, result) => { | ||
await seed(files); | ||
const entry = await getEntry( | ||
args, | ||
{ ...defaultWranglerConfig, ...config }, | ||
"deploy" | ||
); | ||
expect(normalize(entry)).toMatchObject(result); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters