我正在尝试将测试框架迁移到Jest。似乎在我的大多数测试中,我通常都可以使导入工作,但是由于某些原因,“ vue-timers”无法正确导入。进口产品在开发或生产中运作良好;因此,我确定我的配置有问题。
错误:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var set$1=function(t,e,i){var n=assign({},i);return n[t]=e,n},assign=Object.assign||function(t){for(var e=1;e<arguments.length;e+=1){var i=arguments[e];for(var n in i)t[n]=i[n]}return t},isArray=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function generateData(t){return Object.keys(t).reduce(function(e,i){return set$1(i,{isRunning:!1,time:t[i].time||0,instance:null},e)},{})}function setTimer(t){return t?setInterval:setTimeout}function clearTimer(t){return t?clearInterval:clearTimeout}function generateTimer(t,e){return setTimer(t.repeat)(function(){e.$emit("timer-tick:"
SyntaxError: Unexpected token export
6 | <script>
7 | import { Component, Vue, Prop } from 'vue-property-decorator';
> 8 | import VueTimers from 'vue-timers';
| ^
9 |
10 | export default {
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at src/renderer/components/ApplicationStatus.vue:8:1
at Object.<anonymous> (src/renderer/components/....vue:34:3)
.babelrc
{
"comments": false,
"env": {
"test": {
"presets": [["env", { "targets": { "node": "current" } }]],
"plugins": ["transform-es2015-modules-commonjs"]
},
"main": {
"presets": [
[
"env",
{
"targets": { "node": 7 }
}
],
"stage-0"
]
},
"renderer": {
"presets": [
[
"env",
{
"modules": false
}
],
"stage-0"
]
},
"web": {
"presets": [
[
"env",
{
"modules": false
}
],
"stage-0"
]
}
},
"plugins": ["transform-runtime", "transform-object-rest-spread"]
}
jest.config.js
module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'vue'],
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.tsx?$': 'ts-jest',
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/renderer/$1',
'^vue$': 'vue/dist/vue.common.js',
},
modulePaths: ['<rootDir>'],
setupFiles: ['<rootDir>/vue-test-setup.ts'],
snapshotSerializers: ['jest-serializer-vue'],
testMatch: ['**/test/**/*.spec.(js|jsx|ts|tsx)|**/__test__/*.(js|jsx|ts|tsx)'],
transformIgnorePatterns: ['<rootDir>/node_modules/'],
};