Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/project/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ npm install # pulls in thomas via a pinned github:DeepSpaceCartel/thomas comm
npm test
```

To run only some features, use `test:feature`:

```bash
npm run test:feature -- features/request_validation.feature features/health.feature
npm run test:feature -- features/health.feature --parallel 1
```

`npm test -- features/x.feature` runs the **whole** suite: cucumber-js merges
paths given on the command line with `cucumber.mjs`'s `features/**/*.feature`.

### Developing against a local, unreleased Thomas checkout

`service/package.json`'s `thomas` devDependency is pinned to a real commit
Expand Down
13 changes: 13 additions & 0 deletions service/cucumber.feature.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// `npm run test:feature -- features/<name>.feature [...]`: only the given
// feature files. A plain `npm test -- <file>` runs EVERYTHING, because
// cucumber-js merges command-line paths with cucumber.mjs's
// features/**/*.feature (deprecated behavior it warns about) - which on a
// small cluster means hours, not minutes.
import base from './cucumber.mjs';

const files = (process.env.FEATURES ?? '').split(/\s+/).filter(Boolean);
if (files.length === 0) {
throw new Error('test:feature: name the feature files, e.g. npm run test:feature -- features/health.feature');
}

export default { ...base, paths: files };
3 changes: 2 additions & 1 deletion service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"start": "node dist/index.js",
"test": "NODE_OPTIONS='--import tsx' cucumber-js",
"test:unit": "node --import tsx --import ./src/testing/setup.ts --test src/*.test.ts",
"test:coverage": "node --import tsx --import ./src/testing/setup.ts --test --experimental-test-coverage --test-coverage-include='src/**/*.ts' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/testing/**' src/*.test.ts"
"test:coverage": "node --import tsx --import ./src/testing/setup.ts --test --experimental-test-coverage --test-coverage-include='src/**/*.ts' --test-coverage-exclude='src/**/*.test.ts' --test-coverage-exclude='src/testing/**' src/*.test.ts",
"test:feature": "node scripts/test-feature.mjs"
},
"dependencies": {
"@fastify/swagger": "^9.8.1",
Expand Down
11 changes: 11 additions & 0 deletions service/scripts/test-feature.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Runs cucumber-js on just the feature files given as arguments (see
// cucumber.feature.mjs for why `npm test -- <file>` isn't enough).
import { spawnSync } from 'node:child_process';

const files = process.argv.slice(2).filter((a) => !a.startsWith('-'));
const flags = process.argv.slice(2).filter((a) => a.startsWith('-'));
const result = spawnSync('npx', ['cucumber-js', '-c', 'cucumber.feature.mjs', ...flags], {
stdio: 'inherit',
env: { ...process.env, FEATURES: files.join(' '), NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --import tsx`.trim() },
});
process.exit(result.status ?? 1);
Loading