Cucumber-js: 7.2.0 的变化打破了外部记者

创建于 2021-04-21  ·  4评论  ·  资料来源: cucumber/cucumber-js

@davidjgoss和@charlierudolph!

看起来对7.2.0 (#1589) 中引入的 ESM 的支持破坏了许多外部报告器,因为它不再允许子模块导入。

这在尝试子模块导入的项目中表现为错误。

例如,调用:

const TestCaseHookDefinition = require('@cucumber/cucumber/lib/models/test_case_hook_definition')

或者:

import TestCaseHookDefinition from '@cucumber/cucumber/lib/models/test_case_hook_definition';

结果是:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/models/test_case_hook_definition' 
 is not defined by "exports" in /path/to/project/node_modules/@cucumber/cucumber/package.json

我知道的受影响项目(可能还有更多):

  • Serenity/JS - @serenity-js/cucumber模块依赖于以下子模块导入:

    • @cucumber/cucumber/package.js (阅读版本)

    • @cucumber/cucumber/lib/models/test_case_hook_definition - 实例化TestCaseHookDefinition

  • @jbpros cucumber-pretty-formatter - 参见 jbpros/cucumber-pretty-formatter#2,它依赖于加载:

    • @cucumber/cucumber/lib/formatter - IFormatterOptions

    • @cucumber/cucumber/lib/formatter/helpers - formatLocation

    • @cucumber/cucumber/lib/formatter/helpers/gherkin_document_parser - getGherkinExampleRuleMap , getGherkinScenarioMap , getGherkinStepMap

    • @cucumber/cucumber/lib/formatter/helpers/pickle_parser - getPickleStepMap

  • @christian-bromann - @wdio/cucumber-framework ,加载:

    • @cucumber/cucumber/lib/support_code_library_builder/types - ITestCaseHookParameter

    • @cucumber/cucumber/lib/formatter/helpers/event_data_collector - EventDataCollector

    • @cucumber/cucumber/lib/support_code_library_builder/types - ITestCaseHookParameter

    • @cucumber/cucumber/lib/runtime - IRuntimeOptions

Cucumber.js 是否可以导出上述类、类型和函数,例如在reporters命名空间下(或类似的东西,以便它们不会妨碍普通用户):

import { reporters } from '@cucumber/cucumber';

reporters.TestCaseHookDefinition

或者,如果上述提案需要太多工作,是否可以恢复这些更改?

谢谢,

最有用的评论

好的,7.2.1 已经恢复,我会重新深入研究 ESM 的内容,看看是否有办法避免这个问题。 感谢您提出@jan-molak

所有4条评论

@jan-molak

看起来对 7.2.0 (#1589) 中引入的 ESM 的支持破坏了许多外部报告器,因为它不再允许子模块导入。

只是为了快速澄清,这只发生在使用--esm ,对吗?

我今天也注意到了漂亮的问题,我将看看扩大我们出口的主要入口点的影响。 大多数看起来合理,但我们需要小心,因为我们正在有效地向 API 契约添加新内容,稍后撤消将是一个重大更改。

嗨@davidjgoss!

只是为了快速澄清,这只发生在使用 --esm 时,对吗?

不,只要外部项目尝试从@cucumber/cucumber导入任何子模块,就会出现问题。

我在这里重现了这个问题 - https://github.com/jan-molak/cucumber-js-1646

git clone https://github.com/jan-molak/cucumber-js-1646.git
cd cucumber-js-1646
npm install
npm start

见错误:

> [email protected] start /path/to/jan-molak/cucumber-js-1646
> node index.js

internal/modules/cjs/loader.js:438
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/models/test_case_hook_definition' is not defined by "exports" in /path/to/jan-molak/cucumber-js-1646/node_modules/@cucumber/cucumber/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:513:3)
    at resolveExports (internal/modules/cjs/loader.js:432:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:472:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/path/to/jan-molak/cucumber-js-1646/index.js:1:32)

好的,7.2.1 已经恢复,我会重新深入研究 ESM 的内容,看看是否有办法避免这个问题。 感谢您提出@jan-molak

感谢您这么快回复,@davidjgoss!

此页面是否有帮助?
0 / 5 - 0 等级