2

在更新了我的核心依赖项 @nrwl/ 、 @angular/和 cypress 之后,我的 e2e 测试有点坏了。我收到以下错误:

import './command'; ^ ParseError: 'import' and 'export' may appear only with 'sourceType: module'.

赛普拉斯还显示此错误:在此处输入图像描述

这些是更新的依赖项: 在此处输入图像描述

在更新之前,我们只是直接从command.ts规范文件中的 -file 导入自定义命令。但也通过使用support/index.ts出现相同的错误,但随后在 index-file 中。

唯一有效(但实际上不能成为解决方案)的方法是将自定义命令移动到索引文件本身并删除导入语句。

而且由于我在 NX-Workspace 中运行这些测试,我无法直接访问任何 webpack 或 babel 配置或类似的东西。

任何提示或想法,我可以尝试什么?

4

2 回答 2

3

我自己找到了解决方案。问题是,我错过了typescript preprocessor.

我不知道为什么,但直到 NX 版本 7.4(或更高版本),没有必要定义插件文件。不知何故,NX 掩盖了这一点。

这就是我必须改变的:

// plugins/index.js
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config

  // Preprocess Typescript
  on('file:preprocessor', preprocessTypescript(config));
};

并引用文件cypress.json

{
    "fileServerFolder": "./",
    "fixturesFolder": "./src/fixtures",
    "integrationFolder": "./src/integration",
    "pluginsFile": "./src/plugins/index",
    "supportFile": "./src/support/index.ts"
  }
于 2019-07-02T12:16:40.737 回答
2

错误ParseError: 'import' and 'export' may appear only with 'sourceType: module'.来自eslint

要修复它.eslintrc.json,请在cypress/目录中添加一个包含内容的文件:

{
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  }
}
于 2019-07-01T18:00:32.463 回答