sodatea / vite-jest

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

Running test:unit in the react-app-ts and react-app-type-module examples folder fails on Windows #10

Closed callmeberzerker closed 2 years ago

callmeberzerker commented 2 years ago

Hi there,

I've tried to use vite-jest on a small demo project and it failed with the same error I get when I try to run the examples test:unit script... It might be some Windows paths shenanigans but I am not sure...

Both projects (react-app-ts and react-app-type-module) successfully bundle (prod mode) and start in DEV mode.

If there is anything I can do to help, holla at me.

The error log:

> @0.0.0 test:unit E:\Projects\vite-jest\examples\react-app-ts
> vite-jest

● Validation Error:

  Module /E:/Projects/vite-jest/packages/vite-jest/index.js in the transform option was not found.
         <rootDir> is: E:\Projects\vite-jest\examples\react-app-ts

  Configuration Documentation:
  https://jestjs.io/docs/configuration

E:\Projects\vite-jest\node_modules\.pnpm\execa@5.1.1\node_modules\execa\lib\error.js:60
                error = new Error(message);
                        ^

Error: Command failed with exit code 1: node --experimental-vm-modules E:\Projects\vite-jest\node_modules\.pnpm\jest@27.0.6\node_modules\jest\bin\jest.js
    at makeError (E:\Projects\vite-jest\node_modules\.pnpm\execa@5.1.1\node_modules\execa\lib\error.js:60:11)
    at Function.module.exports.sync (E:\Projects\vite-jest\node_modules\.pnpm\execa@5.1.1\node_modules\execa\index.js:194:17)
    at file:///E:/Projects/vite-jest/packages/vite-jest/bin/vite-jest.js:11:7
    at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
    at async handleMainPromise (node:internal/modules/run_main:63:12) {
  shortMessage: 'Command failed with exit code 1: node --experimental-vm-modules E:\\Projects\\vite-jest\\node_modules\\.pnpm\\jest@27.0.6\\node_modules\\jest\\bin\\jest.js',  command: 'node --experimental-vm-modules E:\\Projects\\vite-jest\\node_modules\\.pnpm\\jest@27.0.6\\node_modules\\jest\\bin\\jest.js',
  escapedCommand: 'node --experimental-vm-modules "E:\\Projects\\vite-jest\\node_modules\\.pnpm\\jest@27.0.6\\node_modules\\jest\\bin\\jest.js"',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Sys info:

  System:
    OS: Windows 10 10.0.19043
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 17.81 GB / 31.92 GB
  Binaries:
    Node: 16.4.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 91.0.4472.124
    Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.67)
    Internet Explorer: 11.0.19041.1
callmeberzerker commented 2 years ago

I hacked around the issue by setting up my jestconfig.js preset with relative path.

export default {
  preset: "../../packages/vite-jest/index.js",

  setupFilesAfterEnv: ["<rootDir>/src/setupTests.js"],
  testMatch: [
    "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
    "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}",
  ],
  testEnvironment: "jest-environment-jsdom",
  verbose: true,
};
jamesg1 commented 2 years ago

Also could be https://github.com/sodatea/vite-jest/pull/16/files if your stuck.

mjfwebb commented 2 years ago

I had the same issue. I changed the preset value in jest.config.js to

preset: "./node_modules/vite-jest/index.js",

And was able to get a bit further (before encountering a new issue 😅)

moimikey commented 8 months ago

@mjfwebb your answer fixed my situation. was getting vite-jest not found until using the relative path.