我过去常常在运行前编译用 TS 编写的 e2e Protractor 测试,但现在我想出了如何在运行时编译 ts 文件——ts-node 似乎是一个很好的工具。正如许多文章所说,我在 Protractor 配置文件中注册了 ts-node,这样我就可以像运行 .ts 文件一样运行我的测试规范,并且它们将在 tun-time 中编译。像这样:
beforeLaunch: () => {
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
},
太好了。但我遇到的所有情况都包含带有 .js 配置文件的示例 --> 你不需要编译配置文件,但所有规范都可以在 TS 中,并将使用 ts-node 编译。
我希望拥有的是在 TypeScript 中拥有我的所有文件:配置和规范。我怎样才能运行我的 Protractor 测试给出 config.ts 并在那里有 specs.ts?
像 Protractor ts-node config.ts
这样的东西会很棒。
最佳答案
只需创建另一个包含以下内容的 .js 文件
启动器.js
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
module.export.config = require('./protractor.conf.ts').config;
然后运行 Protractor 并将启动器作为配置文件传递:
protractor launcher.js
关于typescript - 如何使用 ts-node 运行 Protractor 配置文件 (.ts)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60213411/