我正在将ava与Nuxt.js一起用于测试我的node.js代码, 当我使用以下命令运行测试时:
ava api.test.js
我收到此错误:
Uncaught exception in test/api.test.js
~/test/api.test.js:2
1: import test from 'ava'
2: import Contract from '@/apis/api'
3:
Error: Cannot find module '@/apis/api'
Object.<anonymous> (test/api.test.js:2:1)
Module._compile (node_modules/pirates/lib/index.js:83:24)
Object.newLoader [as .js] (node_modules/pirates/lib/index.js:88:7)
✖ test/api.test.js exited with a non-zero exit code: 1
1 uncaught exception
这是我的api.test.js代码:
import test from 'ava'
import Api from '@/apis/api'
test('test function', async (t) => {
console.log(await new Api().getItems())
t.pass()
})
这是我package.json中的ava部分:
"ava": {
"require": [
"@babel/register",
"@babel/polyfill"
]
}
我正在使用以下插件:
这是我的.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"@babel/plugin-transform-runtime"
],
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-proposal-optional-chaining",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
]
}
我想念什么?
感谢您的帮助。