Skip to content

Changes in 7.2.0 break external reporters #1646

@jan-molak

Description

@jan-molak

Hey @davidjgoss and @charlierudolph!

It looks like support for ESM introduced in 7.2.0 (#1589) breaks a number of external reporters, as it no longer allows for sub-module imports.

This manifests itself with an error in projects that attempt a sub-module import.

For example, calling either:

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

or:

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

results in:

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

Affected projects I'm aware of (there could be more):

  • Serenity/JS - @serenity-js/cucumber module relies on following sub-module imports:
    • @cucumber/cucumber/package.js (to read the version)
    • @cucumber/cucumber/lib/models/test_case_hook_definition - to instantiate TestCaseHookDefinition
  • @jbpros cucumber-pretty-formatter - see Breaks with @cucumber/cucumber v7.2.0 cucumber-js-pretty-formatter#2, which relies on loading:
    • @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, which loads:
    • @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

Would it be possible for Cucumber.js to export the above classes, types, and functions, for example under reporters namespace (or something similar so that they don't get in the way of regular users):

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

reporters.TestCaseHookDefinition

Alternatively, would it be possible to revert those changes if the above proposal requires too much work?

Thanks,
Jan

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions