首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以配置wdio以使用不同的tsconfig文件?

是否可以配置wdio以使用不同的tsconfig文件?
EN

Stack Overflow用户
提问于 2020-08-04 16:19:57
回答 1查看 942关注 0票数 1

我正在尝试让wdio设置运行我们的React应用程序。问题是,只有当我修改tsconfig.json文件本身以使用所需的types、将module更改为commonjs并将isolatedModules设置为false时,它才能工作。

代码语言:javascript
复制
{
  "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文件,如下所示:

代码语言:javascript
复制
{
  "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茉莉花对象:

代码语言:javascript
复制
    // 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并将脚本更改为:

代码语言:javascript
复制
"int": "cross-env TS_NODE_PROJECT=tsconfig.test.json wdio wdio.conf.js",

但这现在又抛出了另一个错误,特别是在我的虚拟测试中:

代码语言:javascript
复制
import { openApp } from "./utils";

describe("Example.ts", () => {
  beforeEach(() => {
    openApp(browser, 'localhost');
  });
  it("should go to home page", () => {
    expect(true).toBe(true);
  });
});

而错误是:

代码语言:javascript
复制
import { openApp } from "./utils";
^^^^^^

SyntaxError: Cannot use import statement outside a module

如果我将tsconfig.test.json中的tsconfig.test.json更改为commonjs,它将通过这个错误并开始抱怨类型:

代码语言:javascript
复制
 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.

奇怪的是,通过更改模块,您可能会认为它正在获取测试配置,但为什么不加载测试所需的类型呢?

EN

回答 1

Stack Overflow用户

发布于 2022-06-28 22:48:46

我面临着一个类似的问题,对我来说,问题在于我将ts-node库导入到我的文件中的方式。

当我把改为

代码语言:javascript
复制
require('ts-node/register');

代码语言:javascript
复制
require('ts-node');

测试能够在不出现TS编译问题的情况下运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63251052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档