Skip to content

Commit 3cd9985

Browse files
authored
Add test and docs for CommonJS support (#30)
1 parent d655ee1 commit 3cd9985

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ features/**/*.{cjs,js,mjs,cts,mts,ts}
105105

106106
This isn't configurable ([yet](https://github.com/cucumber/cucumber-node/issues/10)).
107107

108+
Both ESM (e.g. `import { Given } from '@cucumber/node'`) and CommonJS (e.g. `const { Given } = require('@cucumber/node')`) module formats are supported.
109+
108110
### TypeScript
109111

110112
You can write your code in TypeScript. Depending on your project, you might either:

test/integration/modules.spec.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@ describe('Modules', () => {
66
it('handles TypeScript code via type stripping', async () => {
77
const harness = await makeTestHarness()
88
await harness.writeFile(
9-
'features/first.feature',
10-
`Feature:
9+
'features/first.feature',
10+
`Feature:
1111
Scenario:
1212
Given a step
1313
`
1414
)
1515
await harness.writeFile(
16-
'features/steps.ts',
17-
`import { Given } from '@cucumber/node'
16+
'features/steps.ts',
17+
`import { Given } from '@cucumber/node'
1818
import type { TestCaseContext } from '@cucumber/node'
1919
Given('a step', (t: TestCaseContext) => {
2020
t.assert.strictEqual(2, 2)
21+
})
22+
`
23+
)
24+
const [output] = await harness.run('spec', '--experimental-strip-types')
25+
const sanitised = stripVTControlCharacters(output.trim())
26+
expect(sanitised).to.include('ℹ pass 2')
27+
})
28+
29+
it('handles CommonJS code via require(esm)', async () => {
30+
const harness = await makeTestHarness()
31+
await harness.writeFile(
32+
'features/first.feature',
33+
`Feature:
34+
Scenario:
35+
Given a step
36+
`
37+
)
38+
await harness.writeFile(
39+
'features/steps.cjs',
40+
`const { Given } = require('@cucumber/node')
41+
Given('a step', (t) => {
42+
t.assert.strictEqual(2, 2)
2143
})
2244
`
2345
)

0 commit comments

Comments
 (0)