我如何 运行 带有 ts-node 的量角器配置文件 (.ts)?
How can I run a protractor config file (.ts) with ts-node?
以前运行以前用TS编译e2e量角器测试,现在想出了运行时间编译ts文件的方法——ts-node貌似不错为此的工具。正如许多文章所说,我在量角器配置文件中注册了 ts-node,这样我就可以 运行 我的测试规范就好像它们是 .ts 文件一样,它们将在 tun-time 中编译。像这样:
beforeLaunch: () => {
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
},
太好了。但我遇到的所有情况都包含带有 .js 配置文件的示例 --> 你不需要编译配置文件,但所有规范都可以在 TS 中,并将使用 ts-node 编译。
我希望拥有的是在 TypeScript 中拥有我的所有文件:配置和规范。我如何 运行 我的量角器测试给出 config.ts 并且其中有 specs.ts?
像量角器 ts-node config.ts
这样的东西会很棒。
只需创建另一个 .js 文件,该文件将包含以下内容
launcher.js
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
module.export.config = require('./protractor.conf.ts').config;
然后 运行 量角器并将启动器作为配置文件传递:
protractor launcher.js
在 config.js
的 onPrepare()
中添加以下代码
onPrepare() {
/* Compile TS files */
require('ts-node').register({
project: './tsconfig.json'
});
希望对你有帮助
根据 Madhan 的回答和 中的问题,我的解决方案是一个单一的启动器 JS 文件,它可以启动通过命令行传递的任何 TS 配置文件:--params.tsconfigpath=myfile.ts
.
var getTsConfigPath = function() {
for (var i = 3; i < process.argv.length; i++) {
var match = process.argv[i].match(/^--params\.([^=]+)=(.*)$/);
if (match && match[1] === "tsconfigpath")
return match[2];
}
return "protractor.conf.ts";
};
require("ts-node").register({
project: require("path").join(__dirname, "./tsconfig.json")
});
tscconfigpath = require("path").join(__dirname, getTsConfigPath());
console.info("Starting protractor with TS config file '" + tscconfigpath + "'...");
module.exports.config = require(tscconfigpath).config;
以前运行以前用TS编译e2e量角器测试,现在想出了运行时间编译ts文件的方法——ts-node貌似不错为此的工具。正如许多文章所说,我在量角器配置文件中注册了 ts-node,这样我就可以 运行 我的测试规范就好像它们是 .ts 文件一样,它们将在 tun-time 中编译。像这样:
beforeLaunch: () => {
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
},
太好了。但我遇到的所有情况都包含带有 .js 配置文件的示例 --> 你不需要编译配置文件,但所有规范都可以在 TS 中,并将使用 ts-node 编译。
我希望拥有的是在 TypeScript 中拥有我的所有文件:配置和规范。我如何 运行 我的量角器测试给出 config.ts 并且其中有 specs.ts?
像量角器 ts-node config.ts
这样的东西会很棒。
只需创建另一个 .js 文件,该文件将包含以下内容
launcher.js
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
},
disableWarnings: true,
fast: true
});
module.export.config = require('./protractor.conf.ts').config;
然后 运行 量角器并将启动器作为配置文件传递:
protractor launcher.js
在 config.js
onPrepare()
中添加以下代码
onPrepare() {
/* Compile TS files */
require('ts-node').register({
project: './tsconfig.json'
});
希望对你有帮助
根据 Madhan 的回答和 --params.tsconfigpath=myfile.ts
.
var getTsConfigPath = function() {
for (var i = 3; i < process.argv.length; i++) {
var match = process.argv[i].match(/^--params\.([^=]+)=(.*)$/);
if (match && match[1] === "tsconfigpath")
return match[2];
}
return "protractor.conf.ts";
};
require("ts-node").register({
project: require("path").join(__dirname, "./tsconfig.json")
});
tscconfigpath = require("path").join(__dirname, getTsConfigPath());
console.info("Starting protractor with TS config file '" + tscconfigpath + "'...");
module.exports.config = require(tscconfigpath).config;