我正在尝试让wdio设置运行我们的React应用程序。问题是,只有当我修改tsconfig.json文件本身以使用所需的types、将module更改为commonjs并将isolatedModules设置为false时,它才能工作。
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"types": ["node", "@wdio/sync", "@wdio/jasmine-framework"]
},
"include": [
"src"
]
}我想要做的是-能够将其分解为单独的tsconfig.json文件,并在需要时利用每个文件。例如,在为集成测试运行wdio时,我只希望它使用tsconfig.test.json文件,如下所示:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [ "./*" ],
"src/*": ["./src/*"]
},
"types": ["node", "@wdio/sync", "@wdio/jasmine-framework"]
},
"include": [
"./src/**/*.ts"
]
}我尝试过将jasmineNodeOpts设置为wdio.conf.js本身以检索tsconfig.test.json,但它没有工作。是否有一种方法可以通过标志或其他方式告诉wdio使用特定的tsconfig文件?
编辑
添加了wdio.conf.js茉莉花对象:
// Options to be passed to Jasmine.
jasmineNodeOpts: {
// TypeScript setup
requires: ['ts-node/register'],
// helpers: ["helper.js"],
// Jasmine default timeout
defaultTimeoutInterval: 60000,
//
// The Jasmine framework allows interception of each assertion in order to log the state of the application
// or website depending on the result. For example, it is pretty handy to take a screenshot every time
// an assertion fails.
expectationResultHandler: function(passed, assertion) {
// do something
}
},编辑2
根据乔恩的建议,我安装了cross-env并将脚本更改为:
"int": "cross-env TS_NODE_PROJECT=tsconfig.test.json wdio wdio.conf.js",但这现在又抛出了另一个错误,特别是在我的虚拟测试中:
import { openApp } from "./utils";
describe("Example.ts", () => {
beforeEach(() => {
openApp(browser, 'localhost');
});
it("should go to home page", () => {
expect(true).toBe(true);
});
});而错误是:
import { openApp } from "./utils";
^^^^^^
SyntaxError: Cannot use import statement outside a module如果我将tsconfig.test.json中的tsconfig.test.json更改为commonjs,它将通过这个错误并开始抱怨类型:
Error: TSError: ⨯ Unable to compile TypeScript:
integration-tests/utils/index.ts(1,15): error TS7006: Parameter 'browser' implicitly has an 'any' type.
integration-tests/utils/index.ts(3,25): error TS2304: Cannot find name 'host'.
integration-tests/utils/index.ts(6,18): error TS7006: Parameter 'browser' implicitly has an 'any' type.
integration-tests/utils/index.ts(6,27): error TS7006: Parameter 'path' implicitly has an 'any' type.奇怪的是,通过更改模块,您可能会认为它正在获取测试配置,但为什么不加载测试所需的类型呢?
发布于 2022-06-28 22:48:46
我面临着一个类似的问题,对我来说,问题在于我将ts-node库导入到我的文件中的方式。
当我把从改为
require('ts-node/register');到
require('ts-node');测试能够在不出现TS编译问题的情况下运行。
https://stackoverflow.com/questions/63251052
复制相似问题