【发布时间】:2017-07-31 14:23:55
【问题描述】:
我正在尝试使用 Typescript 在现有 Zend Framework 2 项目上创建 CasperJS 前端测试。
ZF2 项目结构是这样设置的:
project
- .composer
- config
- data
- module
-- Application
-- Module1
--- config (module1 config)
--- src (php sources)
--- view (module1 view files)
--- test
---- Module1Test (has PHPUnit tests)
---- UI
----- Tests
------ SubArea
------ testArea.casper.ts
-- Module2
...
- public
- vendor
- tests
-- backend
-- frontend
--- casperjs
...
---- tsconfig.json
我试图让我的 tsconfig.json 查找并编译每个应用程序模块 Test 目录中的所有 *.casper.ts 文件,并编译到 root/tests/frontend 中的临时目录中。大约有30个模块。
目前我的文件如下所示:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"outDir": "./_tmp/build/"
},
"filesGlob": [
"../../../module/**/test/UI/Tests/Demo/*.casper.ts",
"!./node_modules/**/*.ts"
],
"exclude": [
"node_modules"
]
}
但它没有找到任何文件。
如何制定 filesGlob 规则以在 tsconfig.json 文件本身上方的目录中查找文件? 就像:
"../../../module/**/test/UI/Tests/Demo/*.casper.ts"
谢谢
【问题讨论】:
-
是什么阻止您将构建相关文件(
tsconfig、tslint、package.json、node_modules)放在项目的根目录中?这就是它们在逻辑上所属的地方,特别是如果您有.ts文件不在您的“前端根目录”下。 -
根项目是ZF2项目,不是ts/js/casper项目。这些东西目前仅用于测试。我们还有其他事情要做,如果一切都在根源上,它就会变成狂野的西部。
-
+1 用于将 tsconfig 放在项目目录的根目录中,您的 filesGlob 中的文件模式看起来像狂野的西部,在目录中跳转等等 :)。它还将为您简化事情。您可能还应该寻找 [long-ass-path]/**/*.casper.ts 它将在 Demo 文件夹的任何子目录中获取您的 casper.ts 文件。
-
此外,如果您的项目的文件夹结构发生变化,那么您使用的文字路径将成为维护的噩梦。我建议简单地将整个
../../../blah/blah/blah/blah路径替换为../../../**/*.casper.ts- 再次将 tsconfig 移动到项目根目录,您的路径将被简化为**/*.casper.ts
标签: typescript tsconfig