cloudflare--workers-sdk
70bf21e064
Prerelease / build (push) Has been skipped
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
95 行
2.4 KiB
TypeScript
95 行
2.4 KiB
TypeScript
import { execFileSync } from "child_process";
|
|
import { mkdtempSync, readFileSync } from "fs";
|
|
import { tmpdir } from "os";
|
|
import { join, resolve } from "path";
|
|
import { beforeEach, describe, it } from "vitest";
|
|
import { wranglerEntryPath } from "../../shared/src/run-wrangler-long-lived";
|
|
|
|
const basePath = resolve(__dirname, "..");
|
|
|
|
describe("'wrangler dev' with WRANGLER_BUILD_CONDITIONS", () => {
|
|
let tempDir: string;
|
|
|
|
beforeEach(() => {
|
|
tempDir = mkdtempSync(join(tmpdir(), "c3-wrangler-init--from-dash-"));
|
|
});
|
|
|
|
it("should import from the `other` package export if that is in the conditions", async ({
|
|
expect,
|
|
}) => {
|
|
execFileSync(
|
|
"node",
|
|
[wranglerEntryPath, "deploy", "--dry-run", `--outdir=${tempDir}`],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
WRANGLER_BUILD_CONDITIONS: "other,node,browser",
|
|
},
|
|
cwd: basePath,
|
|
}
|
|
);
|
|
expect(readFileSync(resolve(tempDir, "index.js"), "utf8")).toContain(
|
|
"isomorphic-random-example/src/other.js"
|
|
);
|
|
});
|
|
|
|
it("should import from the `default` package export if the conditions are explicitly empty", async ({
|
|
expect,
|
|
}) => {
|
|
execFileSync(
|
|
"node",
|
|
[wranglerEntryPath, "deploy", "--dry-run", `--outdir=${tempDir}`],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
WRANGLER_BUILD_CONDITIONS: "",
|
|
},
|
|
cwd: basePath,
|
|
}
|
|
);
|
|
expect(readFileSync(resolve(tempDir, "index.js"), "utf8")).toContain(
|
|
"isomorphic-random-example/src/default.js"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("'wrangler build' with WRANGLER_BUILD_PLATFORM", () => {
|
|
it("should import from node imports if platform is set to 'node'", ({
|
|
expect,
|
|
}) => {
|
|
execFileSync(
|
|
"node",
|
|
[wranglerEntryPath, "deploy", "--dry-run", "--outdir=dist/node"],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
WRANGLER_BUILD_PLATFORM: "node",
|
|
},
|
|
cwd: basePath,
|
|
}
|
|
);
|
|
expect(
|
|
readFileSync(resolve(__dirname, "../dist/node/index.js"), "utf8")
|
|
).toContain("isomorphic-random-example/src/node.js");
|
|
});
|
|
|
|
it("should import from node imports if platform is set to 'browser'", ({
|
|
expect,
|
|
}) => {
|
|
execFileSync(
|
|
"node",
|
|
[wranglerEntryPath, "deploy", "--dry-run", "--outdir=dist/browser"],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
WRANGLER_BUILD_PLATFORM: "browser",
|
|
},
|
|
cwd: basePath,
|
|
}
|
|
);
|
|
expect(
|
|
readFileSync(resolve(__dirname, "../dist/browser/index.js"), "utf8")
|
|
).toContain("../isomorphic-random-example/src/workerd.mjs");
|
|
});
|
|
});
|