json - 如何配置 tsc 以从特定文件夹编译测试规范?
问题描述
我正在将 e2e 测试实施到 Angular 项目中。它不是以 开头的@angular-cli
,所以我手动配置了大部分。
我现在要做的是定义一个脚本,package.json
仅将tests/
文件夹中的规范转换为tests/compiled
.
我试图关注这个问题:tsconfig.json - Only build ts files from folder。推荐使用--rootDir
来定义文件夹。
但是如果我使用 this: tsc --rootDir tests --outDir ./tests/compiled
,它无论如何都会编译来自其他文件夹的文件(如 ./src)。此外,它返回很多 TS6059 错误,抱怨 rootDir 应该包含所有源文件。
一个例子:
error TS6059: File 'C:/Users/Betalabs/Documents/Projetos/Engine-Frontend/src/vendor.browser.ts' is not under 'rootDir' 'tests'. 'rootDir' is expected to contain all source files.
文件层次结构是这样的。请注意,*.spec.ts
我要转换的测试规范 ( ) 在tests/
文件夹中。
(root)
-- src/
-- tests/
-- compiled/
-- (transpiled test files, ".js")
-- helpers/
-- (helper modules, ".ts")
-- page-objects/
-- (page objects, ".ts")
-- forms.spec.ts
-- filters.spec.ts
-- .gitignore
-- .tern-project
-- buildspec.yml
-- conf.js
-- package-lock.json
-- package.json
-- README.md
-- tsconfig.json
-- tsconfig.webpack.json
-- tslint.json
-- typedoc.json
-- webpack.config.js
这是我的 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmitHelpers": true,
"importHelpers": true,
"strictNullChecks": false,
"baseUrl": "./src",
"paths": {
"@angular/*": ["node_modules/@angular/*"]
},
"lib": [
"dom",
"es6",
"es2017.object"
],
"typeRoots": [
"node_modules/@types"
],
"types": [
"jasmine",
"hammerjs",
"node",
"source-map",
"uglify-js",
"webpack"
]
},
"exclude": [
"node_modules",
"dist"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": { "rewriteTsconfig": false }
}
我通过编译所有文件并手动删除不必要的文件来“解决”这个问题。换句话说:一团糟:P
你能帮我解决这个问题吗?
解决方案
为了编译这些文件,您可以使用
"include": ["tests"]
在你的 tsconfig
话虽如此,我认为将项目转换为使用 ng cli 会容易得多 :) 祝你好运
推荐阅读
- css - 调整浏览器窗口大小时,内联块导航链接不会换行
- node.js - 代码:403,消息:“禁止”,响应:单击峰会表单按钮时
- django - Django Celery 任务中的 Elasticsearch 索引
- r - 如何在 R 中对描述性统计的列进行分组?
- java - Java 合并排序算法的问题
- python - VSCode:如何让 Run Above 只运行上面的单元格而不是上面的所有单元格?
- c# - 在消息队列级别拦截和修改键盘输入
- java - 如何在android的对话框片段中刷新片段?
- json - 将 ArrayType 中的值解包为 df 中的列
- c - 什么是 OpenGL 中的颜色缓冲区?