Skip to content

Commit 502b9c1

Browse files
authored
Improve documentation (#37)
1 parent 693756d commit 502b9c1

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ written in plain language, they can be read by anyone on your team. Because they
1717
read by anyone, you can use them to help improve communication, collaboration and trust on
1818
your team.
1919

20-
⚠️ This is a new implementation of Cucumber built around the [Node.js test runner](https://nodejs.org/api/test.html). It's still in the pre-1.0.0 phase, so APIs and behaviour might change. The stable canonical implementation of Cucumber for JavaScript continues to be [@cucumber/cucumber](https://github.com/cucumber/cucumber-js) for now. ⚠️
20+
⚠️⚠️⚠️
21+
This is a new implementation of Cucumber built around the [Node.js test runner](https://nodejs.org/api/test.html). It's still in the pre-1.0.0 phase, so APIs and behaviour might change. The stable canonical implementation of Cucumber for JavaScript continues to be [@cucumber/cucumber](https://github.com/cucumber/cucumber-js) for now.
22+
⚠️⚠️⚠️
2123

2224
## Install
2325

@@ -60,11 +62,11 @@ import { Greeter } from '../../lib/Greeter.js'
6062

6163
When('the greeter says hello', (t) => {
6264
t.world.whatIHeard = new Greeter().sayHello()
63-
});
65+
})
6466

6567
Then('I should have heard {string}', (t, expectedResponse) => {
6668
assert.equal(t.world.whatIHeard, expectedResponse)
67-
});
69+
})
6870
```
6971

7072
Finally, run `node --test` with some special arguments:
@@ -91,8 +93,8 @@ Since cucumber-node augments the standard Node.js test runner, you can use many
9193

9294
Full API documentation is at https://cucumber.github.io/cucumber-node and includes:
9395

94-
- `Before` and `After` for hooks
9596
- `Given`, `When` and `Then` for steps
97+
- `Before` and `After` for hooks
9698
- `ParameterType` for custom parameter types
9799
- `DataTable` for working with data tables
98100

@@ -110,16 +112,34 @@ features/**/*.{cjs,js,mjs,cts,mts,ts}
110112

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

113-
Both ESM (e.g. `import { Given } from '@cucumber/node'`) and CommonJS (e.g. `const { Given } = require('@cucumber/node')`) module formats are supported.
115+
### ESM and CommonJS
116+
117+
cucumber-node is an ESM package, but you can write your code in either format:
118+
119+
- ESM - e.g. `import { Given } from '@cucumber/node'`
120+
- CommonJS - e.g. `const { Given } = require('@cucumber/node')`
114121

115122
### TypeScript
116123

117-
You can write your code in TypeScript. Depending on your project, you might either:
124+
You also can write your code in TypeScript.
125+
126+
We recommend bringing in [`tsx`](https://www.npmjs.com/package/tsx) to handle the transpilation, plus the Node.js types:
127+
128+
```shell
129+
npm install --save-dev tsx @types/node
130+
```
131+
132+
Then, add `tsx` as another import when you run:
118133

119-
1. Just rely on Node.js built-in type stripping without any other dependencies or configuration
120-
2. Use [tsx](https://www.npmjs.com/package/tsx) to transpile by adding `--import tsx` to your test command
134+
```shell
135+
node --import @cucumber/node/bootstrap --import tsx --test "features/**/*.feature"
136+
```
137+
138+
Remember to add a [`tsconfig.json`](https://www.typescriptlang.org/tsconfig/) to your project. If you're not sure what you need, [`@tsconfig/node22`](https://www.npmjs.com/package/@tsconfig/node22) is a good place to start.
121139

122-
See https://nodejs.org/api/typescript.html for more details.
140+
#### Without dependencies
141+
142+
You might even be able to go without any extra dependencies and instead lean on [Node.js built-in TypeScript support](https://nodejs.org/api/typescript.html), although this is still very new and has several limitations.
123143

124144
## Reporters
125145

@@ -128,29 +148,31 @@ Some Cucumber formatters are included as Node.js test reporters:
128148
- HTML `--test-reporter=@cucumber/node/reporters/html --test-reporter-destination=./report.html`
129149
- Message `--test-reporter=@cucumber/node/reporters/message --test-reporter-destination=./messages.ndjson`
130150

131-
## Limitations
151+
There are some caveats that apply when using these reporters (but not otherwise):
132152

133-
It's early days, and there are some rough edges here, which we'll smooth out as soon as possible:
153+
- *Don't mix Cucumber tests with other tests* - if you have non-Cucumber tests to run with `node --test`, you should do that in a separate run.
154+
- *Don't use the `spec` reporter at the same time* - because we're abusing the `diagnostic` channel to send messages to the reporter, it makes the `spec` output very noisy - we recommend the `dot` reporter instead.
134155

135-
- **You can't mix Cucumber tests with other tests** so if you have non-Cucumber tests to run with `node --test`, you should do that in a separate run.
136-
- **The `spec` reporter gets noisy if you also use a Cucumber reporter** because we're kind of abusing the `diagnostic` channel to send messages to the reporter. We'd recommend the `dot` reporter in the meantime.
156+
## Limitations
137157

138-
There are also some pretty standard Cucumber features that are conspicuous by their absence (again, not for long):
158+
There are some pretty standard Cucumber features that are missing (but not for long):
139159

140160
- [Filtering by tag expression](https://github.com/cucumber/cucumber-node/issues/9)
141161
- [BeforeAll/AfterAll hooks](https://github.com/cucumber/cucumber-node/issues/8)
142162
- [Regular expression steps](https://github.com/cucumber/cucumber-node/issues/6)
163+
- [Customise World creation and type](https://github.com/cucumber/cucumber-node/issues/7)
164+
- [Snippets](https://github.com/cucumber/cucumber-node/issues/36)
143165

144166
## What's different?
145167

146-
Some behaviour differs from that of `cucumber-js` in meaningful ways.
168+
Some behaviour of cucumber-node is different - and better - than in cucumber-js:
147169

148-
### Arrow functions
170+
### Concurrency by default
149171

150-
`cucumber-node` doesn't set `this` to anything for the scope of your step/hook functions. Instead, a context object is passed as the first argument. This means there's no need to avoid arrow functions.
172+
`node --test` by default runs each test file in a separate process, and runs them concurrently as much as possible within the constraints of the system. This is markedly different to cucumber-js which is single-process and serial by default. This is also a good thing, helping you identify and fix unintentional dependencies between scenarios.
173+
174+
### Arrow functions
151175

152-
### Concurrency
176+
There's no reliance on `this` in your step and hook functions to access state, since we pass a context object as the first argument to all functions. This means you're free to use arrow functions as you normally would in JavaScript.
153177

154-
`node --test` by default runs each test file in a separate process, and runs them concurrently as much as possible within the constraints of the system. This is different from `cucumber-js` which by default runs everything in-process and in serial.
155178

156-
The way work is divided up to run concurrently is also worth calling out. `node --test` does so at the file level, meaning many feature files can be executed concurrently, but scenarios within a feature file will always run in the defined order and in the same process. This is more predictable than `cucumber-js` which just makes a single pool of all scenarios and assigns them to worker processes as they become idle.

0 commit comments

Comments
 (0)