Skip to content

Configuring vitest to use singleFork for some files, not others #6438

Answered by AriPerkkio
slhck asked this question in Q&A
Discussion options

You must be logged in to vote

You can also define the singleFork in the workspace file. Then you can run all tests with a single vitest command.

import { defineWorkspace } from "vitest/config";

export default defineWorkspace([
  {
    test: {
      name: "parallel",
      include: ["**/first.test.ts", "**/second.test.ts"],
    },
  },
  {
    test: {
      name: "sequential",
      include: ["**/third.test.ts", "**/fourth.test.ts"],
      poolOptions: { forks: { singleFork: true } },
    },
  },
]);

Here I have 4 tests:

import { test } from "vitest";

test("testing", async () => {
  console.log(process.pid);
  await new Promise((r) => setTimeout(r, 1000));
});
vitest-workspace-singlefork.mov

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AriPerkkio
Comment options

Answer selected by slhck
@slhck
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants