Open cassus opened 11 months ago
Possibly related error during code generation when importing an ESM module from a component. When running playwright component tests this ESM module imports and works fine.
Loading features from: src/**/*.feature
Loading steps from: src/**/*steps.{common,comp}.{ts,tsx}
/Users/cassus/Dev/org-mat-viz/node_modules/@cucumber/cucumber/lib/try_require.js:15
throw Error(`Cucumber expected a CommonJS module at '${path}' but found an ES module.
^
Error: Cucumber expected a CommonJS module at '/Users/cassus/Dev/org-mat-viz/src/features/participate/e2e/ConditionalQuestions.steps.comp.tsx' but found an ES module.
Either change the file to CommonJS syntax or use the --import directive instead of --require.
Original error message: require() of ES Module /Users/cassus/Dev/org-mat-viz/node_modules/react-markdown/index.js from /Users/cassus/Dev/org-mat-viz/src/lib/ReactMarkdown/InlineMarkdown.tsx not supported.
Instead change the require of index.js in /Users/cassus/Dev/org-mat-viz/src/lib/ReactMarkdown/InlineMarkdown.tsx to a dynamic import() which is available in all CommonJS modules.
at tryRequire (/Users/cassus/Dev/org-mat-viz/node_modules/@cucumber/cucumber/src/try_require.ts:12:13)
at /Users/cassus/Dev/org-mat-viz/node_modules/@cucumber/cucumber/src/api/support.ts:27:40
at Array.map (<anonymous>)
at getSupportCodeLibrary (/Users/cassus/Dev/org-mat-viz/node_modules/@cucumber/cucumber/src/api/support.ts:27:16)
at loadSupport (/Users/cassus/Dev/org-mat-viz/node_modules/@cucumber/cucumber/src/api/load_support.ts:30:37)
at TestFilesGenerator.loadSteps (/Users/cassus/Dev/org-mat-viz/node_modules/playwright-bdd/src/gen/index.ts:81:31)
at async Promise.all (index 1)
at /Users/cassus/Dev/org-mat-viz/node_modules/playwright-bdd/src/gen/index.ts:43:7
at withExitHandler (/Users/cassus/Dev/org-mat-viz/node_modules/playwright-bdd/src/utils/exit.ts:30:12)
at TestFilesGenerator.generate (/Users/cassus/Dev/org-mat-viz/node_modules/playwright-bdd/src/gen/index.ts:41:5)
at async Promise.all (index 0)
at Command.<anonymous> (/Users/cassus/Dev/org-mat-viz/node_modules/playwright-bdd/src/cli/commands/test.ts:29:5)
Given
When I generate the tests
Then
But I expect Code generation to work as it works when there is no asset import in the component test
Isolated demo I extended test/component-tests with this case, see my branch at https://github.com/cassus/playwright-bdd/tree/cassus/comp-test-asset
Environment
Additional thoughts This issue reminds me of the errors I get when I accidentally import a component that uses assets in my e2e playwright tests. It seems like playwright-ct test runner parses the code in a different way that avoids errors like this.