one
Version:
One is a new React Framework that makes Vite serve both native and web.
121 lines (119 loc) • 5.44 kB
JavaScript
"use strict";
var import_fs = require("fs");
var import_os = require("os");
var import_path = require("path");
var import_vitest = require("vitest");
var import_cloudflareWranglerConfig = require("./cloudflareWranglerConfig.native.js");
(0, import_vitest.describe)("createCloudflareWranglerConfig", function () {
(0, import_vitest.it)("synthesizes a worker config when no user wrangler file exists", function () {
var config = (0, import_cloudflareWranglerConfig.createCloudflareWranglerConfig)("my-app");
(0, import_vitest.expect)(config.name).toBe("my-app");
(0, import_vitest.expect)(config.main).toBe("worker.js");
(0, import_vitest.expect)(config.compatibility_flags).toEqual(["nodejs_compat"]);
(0, import_vitest.expect)(config.find_additional_modules).toBe(true);
(0, import_vitest.expect)(config.assets).toEqual({
directory: "client",
binding: "ASSETS",
run_worker_first: true
});
});
(0, import_vitest.it)("merges user wrangler.jsonc the same way the cloudflare build does", function () {
var config = (0, import_cloudflareWranglerConfig.createCloudflareWranglerConfig)("generated-name", {
name: "test-cloudflare-user-config",
compatibility_date: "2025-01-01",
compatibility_flags: ["nodejs_als"],
vars: {
CUSTOM_VALUE: "from-root-config"
},
assets: {
html_handling: "auto-trailing-slash"
},
rules: [{
type: "ESModule",
globs: ["./extra/**/*.js"],
fallthrough: true
}]
});
(0, import_vitest.expect)(config.name).toBe("test-cloudflare-user-config");
(0, import_vitest.expect)(config.main).toBe("worker.js");
(0, import_vitest.expect)(config.compatibility_date).toBe("2025-01-01");
(0, import_vitest.expect)(config.compatibility_flags).toEqual(["nodejs_compat", "nodejs_als"]);
(0, import_vitest.expect)(config.vars).toEqual({
CUSTOM_VALUE: "from-root-config"
});
(0, import_vitest.expect)(config.assets).toEqual({
html_handling: "auto-trailing-slash",
directory: "client",
binding: "ASSETS",
run_worker_first: true
});
(0, import_vitest.expect)(config.rules).toEqual([{
type: "ESModule",
globs: ["./server/**/*.js"],
fallthrough: true
}, {
type: "ESModule",
globs: ["./api/**/*.js"],
fallthrough: true
}, {
type: "ESModule",
globs: ["./middlewares/**/*.js"],
fallthrough: true
}, {
type: "ESModule",
globs: ["./assets/**/*.js"],
fallthrough: true
}, {
type: "ESModule",
globs: ["./extra/**/*.js"],
fallthrough: true
}]);
});
});
(0, import_vitest.describe)("shouldEnableWorkerdDev", function () {
var previous = process.env.ONE_EXPERIMENTAL_WORKER_DEV;
(0, import_vitest.afterEach)(function () {
if (previous === void 0) delete process.env.ONE_EXPERIMENTAL_WORKER_DEV;else process.env.ONE_EXPERIMENTAL_WORKER_DEV = previous;
});
(0, import_vitest.it)("is off when the flag is unset", function () {
delete process.env.ONE_EXPERIMENTAL_WORKER_DEV;
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.isExperimentalWorkerDevEnabled)()).toBe(false);
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)("cloudflare", "/tmp")).toBe(false);
});
(0, import_vitest.it)("is off when the flag is on but the app has no cloudflare target or wrangler file", function () {
process.env.ONE_EXPERIMENTAL_WORKER_DEV = "1";
var root = (0, import_fs.mkdtempSync)((0, import_path.join)((0, import_os.tmpdir)(), "one-workerd-flag-"));
try {
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)(void 0, root)).toBe(false);
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)("node", root)).toBe(false);
} finally {
(0, import_fs.rmSync)(root, {
recursive: true,
force: true
});
}
});
(0, import_vitest.it)("is on when the flag is set and deploy is cloudflare", function () {
process.env.ONE_EXPERIMENTAL_WORKER_DEV = "1";
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)("cloudflare", "/tmp-does-not-exist")).toBe(true);
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)({
target: "cloudflare"
}, "/tmp-does-not-exist")).toBe(true);
});
(0, import_vitest.it)("is on when the flag is set and wrangler.jsonc exists", function () {
process.env.ONE_EXPERIMENTAL_WORKER_DEV = "1";
var root = (0, import_fs.mkdtempSync)((0, import_path.join)((0, import_os.tmpdir)(), "one-workerd-wrangler-"));
try {
var _loadUserWranglerConfigSync;
(0, import_fs.writeFileSync)((0, import_path.join)(root, "wrangler.jsonc"), '{ "name": "from-file" }\n');
(0, import_vitest.expect)((0, import_cloudflareWranglerConfig.shouldEnableWorkerdDev)(void 0, root)).toBe(true);
(0, import_vitest.expect)((_loadUserWranglerConfigSync = (0, import_cloudflareWranglerConfig.loadUserWranglerConfigSync)(root)) === null || _loadUserWranglerConfigSync === void 0 ? void 0 : _loadUserWranglerConfigSync.config.name).toBe("from-file");
} finally {
(0, import_fs.rmSync)(root, {
recursive: true,
force: true
});
}
});
});
//# sourceMappingURL=cloudflareWranglerConfig.test.native.js.map