Closed upupming closed 3 years ago
You are not using jest 27. ts-jest major version always goes together with Jest major version.
@ahnpnl I can confirm that this is happening with the following versions of jest
and ts-jest
:
"@types/jest": "^27.0.1", "jest": "^27.1.0", "ts-jest": "^27.0.5", "typescript": "^4.4.2"
Test suite failed to run
TypeError: Jest: a transform must export a `process` function.
at ScriptTransformer._getTransformer (node_modules/@jest/transform/build/ScriptTransformer.js:357:15)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:419:28)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:523:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
Is there a ts-jest
version to match v27.1.0 ?
N.B. I have uninstalled all versions of jest and ts-jest before re-running npm install prior to submitting this, in case there was a package.json
mismatch with node_modules ...
you can try to clear Jest cache. This error doesn't exist on a new project.
@ahnpnl Could you run me through that ...
FYI ... I've just run npx jest --clearCache
and I am still seeing this error.
jest --clearCache
is the way to clear Jest cache. I suspect something wrong with your lock file and node_modules
in your project that Jest and ts-jest
having a mismatch. This can be due to you use a framework/libraries having nested dependencies.
@ahnpnl I would say not, here is the devDependencies list for my package-lock.json
:
"devDependencies": {
"@babel/core": "^7.15.5",
"@fullhuman/postcss-purgecss": "^4.0.3",
"@rollup/plugin-typescript": "^8.2.5",
"@storybook/addon-actions": "^6.3.8",
"@storybook/addon-essentials": "^6.3.8",
"@storybook/addon-links": "^6.3.8",
"@storybook/vue3": "^6.3.8",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vitejs/plugin-vue": "^1.3.0",
"@vue/cli-plugin-babel": "4.5.0",
"@vue/cli-plugin-eslint": "4.5.0",
"@vue/cli-plugin-typescript": "4.5.0",
"@vue/cli-plugin-unit-jest": "4.5.0",
"@vue/cli-service": "4.5.13",
"@vue/compiler-sfc": "^3.2.6",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/test-utils": "^2.0.0-rc.14",
"autoprefixer": "^10.3.3",
"babel-jest": "^27.1.0",
"babel-loader": "^8.2.2",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0",
"jest": "^27.1.0",
"lint-staged": "^9.5.0",
"postcss": "^8.3.6",
"rollup-plugin-postcss": "^4.0.1",
"tailwindcss": "^2.2.9",
"ts-jest": "^27.0.5",
"typescript": "^4.4.2",
"vite": "^2.5.2",
"vue": "^3.2.9",
"vue-loader": "^16.5.0",
"vue-tsc": "^0.3.0",
"vue3-jest": "^27.0.0-alpha.2"
},
I've also deleted node_modules and re-run npm install
... and the error persists.
Do I need to add anything extra to my "types" config in tsconfig.json? At the moment I have:
"types": [
"webpack-env",
"jest"
],
Or perhaps, something is a mis here in my jest.config.js:
module.exports = {
collectCoverageFrom: [
"**/*.{js,ts,vue}",
"!**/node_modules/**"
],
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
transform: {
"^.+\\.tsx?$": "ts-jest",
'^.+\\.vue$': 'vue3-jest'
},
verbose: true
}
I see you are using vue3-jest
alpha which is a Jest transformer for Vue. What is your full stacktrace?
@ahnpnl Full stack trace isn't too exciting, but leaving it here for brevity:
I suspect this is problem with vue3-jest
. If I look at https://github.com/vuejs/vue-jest/blob/v27.0.0-alpha.2/packages/vue3-jest/lib/index.js#L3 , this way of exporting transformer no longer works with Jest 27.
The right way to export transformer is https://github.com/kulshekhar/ts-jest/blob/master/src/index.ts
cc @lmiller1990
Can you try @vue/vue3-jest
? It's on alpha 1. https://www.npmjs.com/package/@vue/vue3-jest. Should be working with Jest 27, or at least, that's the intention (internal tests are passing, but Jest ecosystem is immense).
master
for vue-jest
now defaults to Jest 27. I think this process API should be correct: https://github.com/vuejs/vue-jest/blob/master/packages/vue3-jest/lib/index.js
Still figuring out Jest 27 and Vue 3 compat is work in progress but should be pretty stable and the main version in Vue CLI soon. There is some work in Vue CLI to make everything work with Jest 27, you might find some useful info here: https://github.com/vuejs/vue-cli/pull/6627
🐛 Bug Report
To Reproduce
Steps to reproduce the behavior:
ts-jest
according to the docs.npx jest
Expected behavior
npx jest
works properlyLink to repo (highly encouraged)
Debug log:
Don't need this yet.
envinfo
Additional context: When I downgrade ts-jest to
26.5.5
, everything works perfectly. It seems the recent version of ts-jest breaks the jest command, should we add aprocess
export as the error log said?