在我们的应用程序上运行Jest测试时,在进行了大规模的包升级之后,我们会出现以下错误:
TypeError: [BABEL] /home/grubshka/devel/project/src/engine/models/Hive.ts: Cannot add property 1, object is not extensible
at Array.push (<anonymous>)
at node_modules/@babel/core/lib/config/full.js:314:26
at Function.<anonymous> (node_modules/@babel/core/lib/gensync-utils/async.js:25:3)
at evaluateSync (node_modules/gensync/index.js:251:28)
at Function.sync (node_modules/gensync/index.js:89:14)
at sync (node_modules/@babel/core/lib/gensync-utils/async.js:68:25)
at sync (node_modules/gensync/index.js:182:19)
at onFirstPause (node_modules/gensync/index.js:210:24)错误的第一条路径是随机的,有时是来自于反应本机文件.
在本地计算机上,如果我们随机地对特定的文件运行测试,在一些测试之后它开始工作,然后所有的测试都能工作,似乎在某个地方有一些缓存。在CI上,它从来不起作用。
以下是我们的主要配置文件:
// babel.config.js
module.exports = {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-typescript',
'@babel/preset-flow'
],
plugins: [
['@babel/plugin-transform-flow-strip-types'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }]
],
env: {
production: {
plugins: ['react-native-paper/babel']
}
}
}// jest.config.js
const { defaults: tsjPreset } = require('ts-jest/presets')
module.exports = {
...tsjPreset,
preset: 'react-native',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.jest.json',
babelConfig: true
}
},
transform: {
...tsjPreset.transform,
'^.+\\.jsx?$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
'^.+\\.tsx?$': 'ts-jest'
},
/*
transformIgnorePatterns: [
'node_modules/(?!(react-native|react-native-elements|react-native-vector-icons|react-native-ratings|react-native-status-bar-height|react-native-maps|react-native-maps-super-cluster|@beeobs)/)'
],
transformIgnorePatterns: [
'<rootDir>/node_modules/react-native/react-native-fs/.+'
],
*/
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: ['<rootDir>/dist/'],
setupFiles: ['./jest.setup.js'],
setupFilesAfterEnv: [
'jest-enzyme',
'<rootDir>/jest.env.js'
],
testEnvironment: 'enzyme',
testEnvironmentOptions: {
enzymeAdapter: 'react16'
}
}// tsconfig.json
{
"compilerOptions": {
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es6",
"dom"
], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"jsx": "react-native", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"noEmit": true, /* Do not emit outputs. */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"strict": true, /* Enable all strict type-checking options. */
"strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"typeRoots": [ /* List of folders to include type definitions from. */
"./types",
"./node_modules/@types"
],
"noImplicitAny": false,
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"resolveJsonModule": true, /* Resolve JSON files as modules, used for localization as of right now */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"skipLibCheck": true
},
"exclude": [
".yalc",
"node_modules/*",
"babel.config.js",
"metro.config.js",
"jest.config.js",
"**/*.test.tsx",
"**/__mocks__/**",
".eslintrc.js"
],
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/*.jsx"
]
}如果需要,我可以提供更多的配置文件。
谢谢!
发布于 2022-03-02 16:48:11
更新Jest和Babel (和我们所有的模块)修复了这个错误..。
https://stackoverflow.com/questions/71292944
复制相似问题