Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix tests
Browse files Browse the repository at this point in the history
penalosa committed Jan 27, 2025
1 parent c0679f6 commit 8897415
Showing 4 changed files with 20 additions and 8 deletions.
13 changes: 8 additions & 5 deletions packages/create-cloudflare/e2e-tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import type {
SpawnOptionsWithoutStdio,
} from "child_process";
import type { Writable } from "stream";
import type { RunnerTestCase, Suite, Test } from "vitest";
import type { RunnerTask, RunnerTestSuite } from "vitest";

export const C3_E2E_PREFIX = "tmp-e2e-c3";

@@ -325,7 +325,7 @@ export const waitForExit = async (

export const createTestLogStream = (
opts: { experimental: boolean },
task: RunnerTestCase,
task: RunnerTask,
) => {
// The .ansi extension allows for editor extensions that format ansi terminal codes
const fileName = `${normalizeTestName(task)}.ansi`;
@@ -337,7 +337,7 @@ export const createTestLogStream = (

export const recreateLogFolder = (
opts: { experimental: boolean },
suite: Suite,
suite: RunnerTestSuite,
) => {
// Clean the old folder if exists (useful for dev)
rmSync(getLogPath(opts, suite), {
@@ -348,7 +348,10 @@ export const recreateLogFolder = (
mkdirSync(getLogPath(opts, suite), { recursive: true });
};

const getLogPath = (opts: { experimental: boolean }, suite: Suite) => {
const getLogPath = (
opts: { experimental: boolean },
suite: RunnerTestSuite,
) => {
const { file } = suite;

const suiteFilename = file
@@ -362,7 +365,7 @@ const getLogPath = (opts: { experimental: boolean }, suite: Suite) => {
);
};

const normalizeTestName = (task: Test) => {
const normalizeTestName = (task: RunnerTask) => {
const baseName = task.name
.toLowerCase()
.replace(/\s+/g, "_") // replace any whitespace with `_`
5 changes: 3 additions & 2 deletions packages/vitest-pool-workers/src/pool/index.ts
Original file line number Diff line number Diff line change
@@ -935,7 +935,8 @@ async function executeMethod(
// Make sure `setImmediate` and `clearImmediate` are never faked as they
// don't exist on the workers global scope
config.fakeTimers.toFake = config.fakeTimers.toFake?.filter(
(method) => method !== "setImmediate" && method !== "clearImmediate"
(timerMethod) =>
timerMethod !== "setImmediate" && timerMethod !== "clearImmediate"
);

// We don't need all pool options from the config at runtime.
@@ -1050,7 +1051,7 @@ export default function (ctx: Vitest): ProcessPool {

return {
name: "vitest-pool-workers",
async runTests(specs, invalidates, method = "run") {
async runTests(specs, invalidates) {
await executeMethod(ctx, specs, invalidates, "run");
},
async collectTests(specs, invalidates) {
Original file line number Diff line number Diff line change
@@ -209,6 +209,15 @@ export default class WorkersTestRunner extends VitestTestRunner {
initialState.current = this.state.current;
}

async onBeforeRunFiles() {
if (DEBUG) {
__console.log("onBeforeRunFiles");
await scheduler.wait(100);
}

resetMockAgent(fetchMock);
}

async onAfterRunFiles() {
if (DEBUG) {
__console.log("onAfterRunFiles");
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { vi } from "vitest";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
import { mockUploadWorkerRequest } from "./helpers/mock-upload-worker";

0 comments on commit 8897415

Please sign in to comment.