-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(unenv-preset): move tests from nodejs-hybrid-app
- Loading branch information
Showing
7 changed files
with
191 additions
and
92 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
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
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,66 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { platform } from "node:process"; | ||
import { fileURLToPath } from "node:url"; | ||
import { fetch } from "undici"; | ||
import { afterAll, beforeAll, describe, expect, test } from "vitest"; | ||
import { runWranglerDev } from "../../../fixtures/shared/src/run-wrangler-long-lived"; | ||
import { TESTS } from "./worker/index"; | ||
|
||
// Root of the current package | ||
const pkgDir = path.resolve(fileURLToPath(import.meta.url), "../.."); | ||
// workerd binary | ||
const localWorkerdPath = path.join(pkgDir, "node_modules/.bin/", "workerd"); | ||
// Base path for resolving `@cloudflare/unenv-preset` files | ||
const localPresetResolveBaseDir = path.join(pkgDir, "package.json"); | ||
// Base path for resolving `unjs/unenv` files | ||
const localUnenvResolveBaseDir = path.join( | ||
pkgDir, | ||
"node_modules/unenv/package.json" | ||
); | ||
|
||
// `runWranglerDev` + `MINIFLARE_WORKERD_PATH` is not supported on Windows | ||
// See https://github.com/nodejs/node/issues/52554 | ||
describe.skipIf(platform === "win32")( | ||
`@cloudflare/unenv-preset ${platform} ${localWorkerdPath} ${fs.existsSync(localWorkerdPath)}`, | ||
() => { | ||
let wrangler: Awaited<ReturnType<typeof runWranglerDev>> | undefined; | ||
|
||
beforeAll(async () => { | ||
// Use workerd binary install in `@cloudflare/unenv-preset` | ||
// rather than the one bundled with wrangler. | ||
const MINIFLARE_WORKERD_PATH = localWorkerdPath; | ||
|
||
// Use the preset from the local `@cloudflare/unenv-preset` and `unjs/unenv` | ||
// rather than the one bundled with wrangler. | ||
const WRANGLER_UNENV_RESOLVE_PATHS = [ | ||
localPresetResolveBaseDir, | ||
localUnenvResolveBaseDir, | ||
].join(","); | ||
|
||
console.log({ MINIFLARE_WORKERD_PATH, WRANGLER_UNENV_RESOLVE_PATHS }); | ||
|
||
wrangler = await runWranglerDev( | ||
path.join(__dirname, "worker"), | ||
["--port=0", "--inspector-port=0"], | ||
{ | ||
MINIFLARE_WORKERD_PATH, | ||
WRANGLER_UNENV_RESOLVE_PATHS, | ||
} | ||
); | ||
}, 30000); | ||
|
||
afterAll(async () => { | ||
await wrangler?.stop(); | ||
wrangler = undefined; | ||
}); | ||
|
||
test.for(Object.keys(TESTS))("%s", async (testName) => { | ||
expect(wrangler).toBeDefined(); | ||
const { ip, port } = wrangler!; | ||
const response = await fetch(`http://${ip}:${port}/${testName}`); | ||
const body = await response.text(); | ||
expect(body).toMatch("OK!"); | ||
}); | ||
} | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "cloudflare-unenv-preset-test", | ||
"main": "./index.ts", | ||
"compatibility_date": "2024-12-16", | ||
"compatibility_flags": ["nodejs_compat"] | ||
} |
Oops, something went wrong.