sodatea / vite-jest

First-class Vite integration for Jest
MIT License
401 stars 51 forks source link

testing in `jest-environment-node` #34

Open eunjae-lee opened 2 years ago

eunjae-lee commented 2 years ago

Hi there,

I'm trying to test in jest-environment-node and getting some errors.

In your examples/vue-app-ts, I did

import fs from "fs";

console.log("# fs", fs.readFileSync);

it("test nothing", () => {
  expect(true).toEqual(true);
});

Then I get this error when running the test:

  ● Test suite failed to run

    Module "fs" has been externalized for browser compatibility and cannot be accessed in client code.

      at Object.get (node_modules/.vite-jest-cache/__slash__@id__slash____vite-browser-external__colon__fs.js:3:11)
      at src/components/__tests__/HelloWorld.spec.ts?1639665446845:3:24
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

Do I need to do something in the vite.config.ts?