You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-20Lines changed: 42 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,9 @@ written in plain language, they can be read by anyone on your team. Because they
17
17
read by anyone, you can use them to help improve communication, collaboration and trust on
18
18
your team.
19
19
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
+
⚠️⚠️⚠️
21
23
22
24
## Install
23
25
@@ -60,11 +62,11 @@ import { Greeter } from '../../lib/Greeter.js'
60
62
61
63
When('the greeter says hello', (t) => {
62
64
t.world.whatIHeard=newGreeter().sayHello()
63
-
});
65
+
})
64
66
65
67
Then('I should have heard {string}', (t, expectedResponse) => {
This isn't configurable ([yet](https://github.com/cucumber/cucumber-node/issues/10)).
112
114
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')`
114
121
115
122
### TypeScript
116
123
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:
118
133
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
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.
121
139
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.
123
143
124
144
## Reporters
125
145
@@ -128,29 +148,31 @@ Some Cucumber formatters are included as Node.js test reporters:
128
148
- HTML `--test-reporter=@cucumber/node/reporters/html --test-reporter-destination=./report.html`
There are some caveats that apply when using these reporters (but not otherwise):
132
152
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.
134
155
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
137
157
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):
139
159
140
160
-[Filtering by tag expression](https://github.com/cucumber/cucumber-node/issues/9)
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:
147
169
148
-
### Arrow functions
170
+
### Concurrency by default
149
171
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
151
175
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.
153
177
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.
155
178
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