Skip to content

Commit

Permalink
api: add runCucumber function internally (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss committed Dec 9, 2021
1 parent 49a51f9 commit efff3a3
Show file tree
Hide file tree
Showing 26 changed files with 934 additions and 865 deletions.
38 changes: 20 additions & 18 deletions compatibility/cck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import glob from 'glob'
import fs from 'fs'
import path from 'path'
import { PassThrough, pipeline, Writable } from 'stream'
import { Cli } from '../src'
import toString from 'stream-to-string'
import {
ignorableKeys,
Expand All @@ -14,6 +13,8 @@ import {
import * as messages from '@cucumber/messages'
import * as messageStreams from '@cucumber/message-streams'
import util from 'util'
import { runCucumber } from '../src/run'
import { IRunConfiguration } from '../src/configuration'

const asyncPipeline = util.promisify(pipeline)
const PROJECT_PATH = path.join(__dirname, '..')
Expand All @@ -29,27 +30,28 @@ describe('Cucumber Compatibility Kit', () => {
const suiteName = match[1]
const extension = match[2]
it(`passes the cck suite for '${suiteName}'`, async () => {
const cliOptions = [
`${CCK_FEATURES_PATH}/${suiteName}/${suiteName}${extension}`,
'--require',
`${CCK_IMPLEMENTATIONS_PATH}/${suiteName}/${suiteName}.ts`,
'--profile',
'cck',
]
if (suiteName === 'retry') {
cliOptions.push('--retry', '2')
}
const args = [
'node',
path.join(PROJECT_PATH, 'bin', 'cucumber-js'),
].concat(cliOptions)
const stdout = new PassThrough()
const runConfiguration: IRunConfiguration = {
sources: {
paths: [`${CCK_FEATURES_PATH}/${suiteName}/${suiteName}${extension}`],
},
support: {
transpileWith: ['ts-node/register'],
paths: [`${CCK_IMPLEMENTATIONS_PATH}/${suiteName}/${suiteName}.ts`],
},
formats: {
stdout: 'message',
},
runtime: {
retry: suiteName === 'retry' ? 2 : 0,
},
}
try {
await new Cli({
argv: args,
await runCucumber(runConfiguration, {
cwd: PROJECT_PATH,
stdout,
}).run()
env: process.env,
})
} catch (ignored) {
console.error(ignored)
}
Expand Down
34 changes: 12 additions & 22 deletions cucumber.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
const feature = [
'--require-module ts-node/register',
'--require features/**/*.ts',
`--format progress-bar`,
'--format rerun:@rerun.txt',
'--format usage:usage.txt',
'--format message:messages.ndjson',
'--format html:html-formatter.html',
'--retry 2',
'--retry-tag-filter @flaky',
'--publish-quiet',
].join(' ')

const cck = [
'--require-module',
'ts-node/register',
'--format',
'message',
].join(' ')

module.exports = {
default: feature,
cck,
default: [
'--require-module ts-node/register',
'--require features/**/*.ts',
`--format progress-bar`,
'--format rerun:@rerun.txt',
'--format usage:usage.txt',
'--format message:messages.ndjson',
'--format html:html-formatter.html',
'--retry 2',
'--retry-tag-filter @flaky',
'--publish-quiet',
].join(' '),
}
1 change: 1 addition & 0 deletions features/i18n.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@spawn
Feature: internationalization

Scenario: view available languages
Expand Down
1 change: 1 addition & 0 deletions features/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class World {
argv: args,
cwd,
stdout,
env,
})
let error: any, stderr: string
try {
Expand Down
23 changes: 16 additions & 7 deletions src/cli/argv_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Command } from 'commander'
import path from 'path'
import { dialects } from '@cucumber/gherkin'
import { SnippetInterface } from '../formatter/step_definition_snippet_builder/snippet_syntax'
import { getKeywords, getLanguages } from './i18n'
import Formatters from '../formatter/helpers/formatters'
import { PickleOrder } from './helpers'

// Using require instead of import so compiled typescript will have the desired folder structure
const { version } = require('../../package.json') // eslint-disable-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -31,7 +33,7 @@ export interface IParsedArgvOptions {
i18nLanguages: boolean
language: string
name: string[]
order: string
order: PickleOrder
parallel: number
profile: string[]
publish: boolean
Expand Down Expand Up @@ -216,14 +218,21 @@ const ArgvParser = {
{}
)

program.on('--help', () => {
/* eslint-disable no-console */
console.log(
' For more details please visit https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md\n'
)
/* eslint-enable no-console */
program.on('option:i18n-languages', () => {
console.log(getLanguages())
process.exit()
})

program.on('option:i18n-keywords', function (isoCode: string) {
console.log(getKeywords(isoCode))
process.exit()
})

program.addHelpText(
'afterAll',
'For more details please visit https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md'
)

program.parse(argv)
const options: IParsedArgvOptions = program.opts()
ArgvParser.validateRetryOptions(options)
Expand Down
Loading

0 comments on commit efff3a3

Please sign in to comment.