sodatea / vite-jest

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

TypeError: (0 , _loadBabelConfig.loadPartialConfigAsync) is not a function when loading test suites #28

Open msakrejda opened 2 years ago

msakrejda commented 2 years ago

When I run my tests, every suite fails with the "is not a function" error in the issue title. Here are the full details for one failure:

 FAIL  app/javascript/util/map.test.ts
  ● Test suite failed to run

    TypeError: (0 , _loadBabelConfig.loadPartialConfigAsync) is not a function

      at loadBabelConfigAsync (node_modules/babel-jest/build/index.js:197:73)
      at ScriptTransformer._getCacheKeyAsync (node_modules/@jest/transform/build/ScriptTransformer.js:313:37)
      at ScriptTransformer._getFileCachePathAsync (node_modules/@jest/transform/build/ScriptTransformer.js:357:33)
      at ScriptTransformer.transformSourceAsync (node_modules/@jest/transform/build/ScriptTransformer.js:637:38)
      at ScriptTransformer._transformAndBuildScriptAsync (node_modules/@jest/transform/build/ScriptTransformer.js:717:46)
      at ScriptTransformer.transformAsync (node_modules/@jest/transform/build/ScriptTransformer.js:789:25)

This is my jest config:

module.exports = {
  preset: 'vite-jest',
  testEnvironment: 'jsdom',
  globalSetup: './app/javascript/jestTestSetup',
  testMatch: [ "**/app/javascript/**/?(*.)+(spec|test).[jt]s?(x)" ],
  moduleDirectories: [ "node_modules", "app/javascript" ],
  moduleNameMapper: {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
    "\\.(css)$": "identity-obj-proxy",
  },
  transform: {
    "^.+\\.[t|j]sx?$": "babel-jest",
    "\\.(graphql)$": "<rootDir>/__mocks__/graphqlMock.js",
  },
};

Versions:

jest: 27.2.4 babel-jest: 27.2.4 vite-jest: 0.0.3

Any ideas?

msakrejda commented 2 years ago

Digging into this a bit, I found that the problem was probably an outdated @babel/core. I updated it and then started getting an error similar to https://github.com/storybookjs/storybook/issues/12893, but I followed the recommendation to remove node_modules and reinstall them, and that seems to have fixed things.

Should the deps be updated to require a recent-enough version? (I can track down what that version should be and submit a PR.)