Skip to content

Commit efff3a3

Browse files
authored
api: add runCucumber function internally (#1849)
1 parent 49a51f9 commit efff3a3

26 files changed

+934
-865
lines changed

compatibility/cck_spec.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import glob from 'glob'
55
import fs from 'fs'
66
import path from 'path'
77
import { PassThrough, pipeline, Writable } from 'stream'
8-
import { Cli } from '../src'
98
import toString from 'stream-to-string'
109
import {
1110
ignorableKeys,
@@ -14,6 +13,8 @@ import {
1413
import * as messages from '@cucumber/messages'
1514
import * as messageStreams from '@cucumber/message-streams'
1615
import util from 'util'
16+
import { runCucumber } from '../src/run'
17+
import { IRunConfiguration } from '../src/configuration'
1718

1819
const asyncPipeline = util.promisify(pipeline)
1920
const PROJECT_PATH = path.join(__dirname, '..')
@@ -29,27 +30,28 @@ describe('Cucumber Compatibility Kit', () => {
2930
const suiteName = match[1]
3031
const extension = match[2]
3132
it(`passes the cck suite for '${suiteName}'`, async () => {
32-
const cliOptions = [
33-
`${CCK_FEATURES_PATH}/${suiteName}/${suiteName}${extension}`,
34-
'--require',
35-
`${CCK_IMPLEMENTATIONS_PATH}/${suiteName}/${suiteName}.ts`,
36-
'--profile',
37-
'cck',
38-
]
39-
if (suiteName === 'retry') {
40-
cliOptions.push('--retry', '2')
41-
}
42-
const args = [
43-
'node',
44-
path.join(PROJECT_PATH, 'bin', 'cucumber-js'),
45-
].concat(cliOptions)
4633
const stdout = new PassThrough()
34+
const runConfiguration: IRunConfiguration = {
35+
sources: {
36+
paths: [`${CCK_FEATURES_PATH}/${suiteName}/${suiteName}${extension}`],
37+
},
38+
support: {
39+
transpileWith: ['ts-node/register'],
40+
paths: [`${CCK_IMPLEMENTATIONS_PATH}/${suiteName}/${suiteName}.ts`],
41+
},
42+
formats: {
43+
stdout: 'message',
44+
},
45+
runtime: {
46+
retry: suiteName === 'retry' ? 2 : 0,
47+
},
48+
}
4749
try {
48-
await new Cli({
49-
argv: args,
50+
await runCucumber(runConfiguration, {
5051
cwd: PROJECT_PATH,
5152
stdout,
52-
}).run()
53+
env: process.env,
54+
})
5355
} catch (ignored) {
5456
console.error(ignored)
5557
}

cucumber.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
const feature = [
2-
'--require-module ts-node/register',
3-
'--require features/**/*.ts',
4-
`--format progress-bar`,
5-
'--format rerun:@rerun.txt',
6-
'--format usage:usage.txt',
7-
'--format message:messages.ndjson',
8-
'--format html:html-formatter.html',
9-
'--retry 2',
10-
'--retry-tag-filter @flaky',
11-
'--publish-quiet',
12-
].join(' ')
13-
14-
const cck = [
15-
'--require-module',
16-
'ts-node/register',
17-
'--format',
18-
'message',
19-
].join(' ')
20-
211
module.exports = {
22-
default: feature,
23-
cck,
2+
default: [
3+
'--require-module ts-node/register',
4+
'--require features/**/*.ts',
5+
`--format progress-bar`,
6+
'--format rerun:@rerun.txt',
7+
'--format usage:usage.txt',
8+
'--format message:messages.ndjson',
9+
'--format html:html-formatter.html',
10+
'--retry 2',
11+
'--retry-tag-filter @flaky',
12+
'--publish-quiet',
13+
].join(' '),
2414
}

features/i18n.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@spawn
12
Feature: internationalization
23

34
Scenario: view available languages

features/support/world.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class World {
8383
argv: args,
8484
cwd,
8585
stdout,
86+
env,
8687
})
8788
let error: any, stderr: string
8889
try {

src/cli/argv_parser.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { Command } from 'commander'
22
import path from 'path'
33
import { dialects } from '@cucumber/gherkin'
44
import { SnippetInterface } from '../formatter/step_definition_snippet_builder/snippet_syntax'
5+
import { getKeywords, getLanguages } from './i18n'
56
import Formatters from '../formatter/helpers/formatters'
7+
import { PickleOrder } from './helpers'
68

79
// Using require instead of import so compiled typescript will have the desired folder structure
810
const { version } = require('../../package.json') // eslint-disable-line @typescript-eslint/no-var-requires
@@ -31,7 +33,7 @@ export interface IParsedArgvOptions {
3133
i18nLanguages: boolean
3234
language: string
3335
name: string[]
34-
order: string
36+
order: PickleOrder
3537
parallel: number
3638
profile: string[]
3739
publish: boolean
@@ -216,14 +218,21 @@ const ArgvParser = {
216218
{}
217219
)
218220

219-
program.on('--help', () => {
220-
/* eslint-disable no-console */
221-
console.log(
222-
' For more details please visit https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md\n'
223-
)
224-
/* eslint-enable no-console */
221+
program.on('option:i18n-languages', () => {
222+
console.log(getLanguages())
223+
process.exit()
224+
})
225+
226+
program.on('option:i18n-keywords', function (isoCode: string) {
227+
console.log(getKeywords(isoCode))
228+
process.exit()
225229
})
226230

231+
program.addHelpText(
232+
'afterAll',
233+
'For more details please visit https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md'
234+
)
235+
227236
program.parse(argv)
228237
const options: IParsedArgvOptions = program.opts()
229238
ArgvParser.validateRetryOptions(options)

0 commit comments

Comments
 (0)