70bf21e064
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
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { readJSON, readToml } from "helpers/files";
|
|
import { beforeAll, describe } from "vitest";
|
|
import { deleteWorker } from "../../../scripts/common";
|
|
import {
|
|
isWindows,
|
|
TEST_TIMEOUT,
|
|
workerTemplateToTest,
|
|
} from "../../helpers/constants";
|
|
import { debuglog } from "../../helpers/debuglog";
|
|
import { test } from "../../helpers/index";
|
|
import { recreateLogFolder } from "../../helpers/log-stream";
|
|
import {
|
|
runC3ForWorkerTest,
|
|
verifyDeployment,
|
|
verifyLocalDev,
|
|
verifyTestScript,
|
|
} from "../../helpers/workers-helpers";
|
|
import { getWorkerTests } from "./test-config";
|
|
import type { RunnerTestSuite } from "vitest";
|
|
|
|
const workerTests = getWorkerTests();
|
|
|
|
describe
|
|
.skipIf(workerTests.length === 0 || isWindows)
|
|
.concurrent(`E2E: Workers templates`, () => {
|
|
// eslint-disable-next-line no-empty-pattern -- Vitest requires the 1st argument to use object destructuring
|
|
beforeAll(({}, ctx) => {
|
|
recreateLogFolder(ctx as RunnerTestSuite);
|
|
|
|
if (workerTemplateToTest) {
|
|
debuglog("Running worker tests with filter:", workerTemplateToTest);
|
|
workerTests.forEach((testConfig) => {
|
|
debuglog(` - ${testConfig.name ?? testConfig.template}`);
|
|
});
|
|
}
|
|
});
|
|
|
|
workerTests.forEach((testConfig) => {
|
|
const name = testConfig.name ?? testConfig.template;
|
|
test(
|
|
name,
|
|
{ retry: 1, timeout: testConfig.timeout || TEST_TIMEOUT },
|
|
async ({ expect, project, logStream }) => {
|
|
try {
|
|
const deployedUrl = await runC3ForWorkerTest(
|
|
expect,
|
|
testConfig,
|
|
project.path,
|
|
logStream
|
|
);
|
|
|
|
// Relevant project files should have been created
|
|
expect(project.path).toExist();
|
|
|
|
const pkgJsonPath = join(project.path, "package.json");
|
|
expect(pkgJsonPath).toExist();
|
|
|
|
const wranglerPath = join(project.path, "node_modules/wrangler");
|
|
expect(wranglerPath).toExist();
|
|
|
|
const tomlPath = join(project.path, "wrangler.toml");
|
|
const jsoncPath = join(project.path, "wrangler.jsonc");
|
|
|
|
if (existsSync(jsoncPath)) {
|
|
const config = readJSON(jsoncPath) as { main?: string };
|
|
if (config.main) {
|
|
expect(join(project.path, config.main)).toExist();
|
|
}
|
|
} else if (existsSync(tomlPath)) {
|
|
const config = readToml(tomlPath) as { main?: string };
|
|
if (config.main) {
|
|
expect(join(project.path, config.main)).toExist();
|
|
}
|
|
} else {
|
|
expect.fail(
|
|
`Expected at least one of "${jsoncPath}" or "${tomlPath}" to exist.`
|
|
);
|
|
}
|
|
|
|
const { verifyDeploy, verifyTest } = testConfig;
|
|
if (verifyDeploy) {
|
|
if (deployedUrl) {
|
|
await verifyDeployment(deployedUrl, verifyDeploy);
|
|
} else {
|
|
await verifyLocalDev(
|
|
expect,
|
|
testConfig,
|
|
project.path,
|
|
logStream
|
|
);
|
|
}
|
|
}
|
|
|
|
if (verifyTest) {
|
|
await verifyTestScript(project.path, logStream);
|
|
}
|
|
} finally {
|
|
await deleteWorker(project.name);
|
|
}
|
|
}
|
|
);
|
|
});
|
|
});
|