使用绝对导入路径确实会破坏 Testcafe 中 Typescript 的编译器
Intellij 确实可以正确解析,但在我的测试文件中使用绝对导入路径时,Testcafe 编译器会抛出错误。 在应用程序源文件中使用绝对路径不会引发任何错误。
这里可能有什么问题?
这些是我的版本
"typescript": "~3.9.10",
"testcafe": "^1.16.0",
"@angular/core": "~10.2.5"
这是我的项目结构:
angular
├── e2e/
│ ├── tsconfig.json
│ └── src
│ ├── noResults.ts
│ └── test.e2e-spec.ts
├── node_modules/
├── src/
│ └── <project files>
├── tsconfig.json
├── testcaferc.json
这是我的 tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2020",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"noUnusedLocals": false,
"noUnusedParameters": false,
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "es2015", "dom"],
"noImplicitAny": true,
"strictNullChecks": true,
"charset": "utf8",
"newLine": "lf",
"allowSyntheticDefaultImports": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"preserveWhitespaces": true,
"strictTemplates": true
}
}
这是我的 e2e/tsconfig.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc/e2e",
"target": "ESNext",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true
}
}
这是我的 testcaferc.json:
{
"compilerOptions": {
"typescript": {
"configPath": "./e2e/tsconfig.json"
}
}
}
这是我在 e2e/src/test.e2e-spec.ts 中的导入:
import { noResults } from 'e2e/src/no-results';
这是我在 e2e/src/noResults.ts 中导出
export const noResults = () => {...}
这是我的错误:
- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/index.js
at Object.<anonymous> (/home/IdeaProjects/angular/e2e/src/test.e2e-spec.ts:7:1) {
code: 'E1035',
data: [
"Error: Cannot find module 'e2e/src/noResults'\n" +
'Require stack:\n' +
'- /home/IdeaProjects/angular/e2e/test.e2e-spec.ts\n' +
'- /home/deaProjects/angular/node_modules/testcafe/lib/compiler/test-file/formats/es-next/compiler.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/compiler/compilers.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/compiler/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/runner/bootstrapper.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/runner/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/live/test-runner.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/testcafe.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/cli.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/index.js'
]
}
Intellij does resolve correctly but the Testcafe compiler throws an error when using absolute import paths in my test files.
Using absolute paths within the application source files does not throw any errors.
What could be the problem here?
These are my versions
"typescript": "~3.9.10",
"testcafe": "^1.16.0",
"@angular/core": "~10.2.5"
This is my project structure:
angular
├── e2e/
│ ├── tsconfig.json
│ └── src
│ ├── noResults.ts
│ └── test.e2e-spec.ts
├── node_modules/
├── src/
│ └── <project files>
├── tsconfig.json
├── testcaferc.json
This is my tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2020",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"noUnusedLocals": false,
"noUnusedParameters": false,
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "es2015", "dom"],
"noImplicitAny": true,
"strictNullChecks": true,
"charset": "utf8",
"newLine": "lf",
"allowSyntheticDefaultImports": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"preserveWhitespaces": true,
"strictTemplates": true
}
}
This is my e2e/tsconfig.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc/e2e",
"target": "ESNext",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true
}
}
This is my testcaferc.json:
{
"compilerOptions": {
"typescript": {
"configPath": "./e2e/tsconfig.json"
}
}
}
This is my import in the e2e/src/test.e2e-spec.ts:
import { noResults } from 'e2e/src/no-results';
This my export in e2e/src/noResults.ts
export const noResults = () => {...}
This is my error:
- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/index.js
at Object.<anonymous> (/home/IdeaProjects/angular/e2e/src/test.e2e-spec.ts:7:1) {
code: 'E1035',
data: [
"Error: Cannot find module 'e2e/src/noResults'\n" +
'Require stack:\n' +
'- /home/IdeaProjects/angular/e2e/test.e2e-spec.ts\n' +
'- /home/deaProjects/angular/node_modules/testcafe/lib/compiler/test-file/formats/es-next/compiler.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/compiler/compilers.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/compiler/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/runner/bootstrapper.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/runner/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/live/test-runner.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/testcafe.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/index.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/cli.js\n' +
'- /home/IdeaProjects/angular/node_modules/testcafe/lib/cli/index.js'
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的模块和装置文件位于同一目录中。
因此导入语句可以更改如下。
Your module and fixture files resides in the same directory.
Hence import statement can be changes as following.