diff --git a/.mocharc.yml b/.mocharc.yml index 09b9087a2..b4eac47fb 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -2,6 +2,8 @@ colors: true file: - test/test_helper.ts full-trace: true +forbid-only: true +forbid-pending: true recursive: true reporter: dot require: 'ts-node/register' diff --git a/CHANGELOG.md b/CHANGELOG.md index 55777b60c..5702012b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,13 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ---- ## [Unreleased] (In Git) +See the [migration guide](./docs/migration.md) for details of how to migrate from 7.x.x to 8.x.x + ### Breaking changes * Drop support for Node.js 10 and 15, add support for Node.js 16 -* Remove deprecated `--retryTagFilter` option (the correct option is `--retry-tag-filter`) +* Remove deprecated `--retryTagFilter` option (the correct option is `--retry-tag-filter`) +* Remove `setDefinitionFunctionWrapper` and step definition option `wrapperOptions` ### Added @@ -25,7 +28,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ### Fixed * Prevent duplicate scenario execution where the same feature is targeted in multiple line expressions ([#1706](https://github.com/cucumber/cucumber-js/issues/1706)) -* Fixed reports banner to point to [new docs](https://cucumber.io/docs/cucumber/environment-variables/) about environment variables +* Fixed reports banner to point to [new docs](https://cucumber.io/docs/cucumber/environment-variables/) about environment variables * Re-add color functions for use with custom formatters [1582](https://github.com/cucumber/cucumber-js/issues/1582) * IParameterTypeDefinition regexp fix [1702](https://github.com/cucumber/cucumber-js/issues/1702) diff --git a/dependency-lint.yml b/dependency-lint.yml index ff28f414c..8286b8bcb 100644 --- a/dependency-lint.yml +++ b/dependency-lint.yml @@ -21,7 +21,6 @@ ignoreErrors: - '@typescript-eslint/eslint-plugin' # peer dependency of standard-with-typescript - '@typescript-eslint/parser' # peer dependency of @typescript-eslint/eslint-plugin - '@types/*' # type definitions - - bluebird # features/generator_step_definitions.feature - coffeescript # features/compiler.feature - eslint-config-prettier # .eslintrc.yml - extends - prettier - eslint-config-standard-with-typescript # .eslintrc.yml - extends - standard-with-typescript diff --git a/docs/migration.md b/docs/migration.md index ba342eabb..36ee13f82 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -1,14 +1,22 @@ -# Migrating to cucumber-js 7.x.x +# Migrating from 7.x.x to 8.x.x + +## Removal of setDefinitionFunctionWrapper + +If this was used to wrap generator functions, please transition to using async / await. +If this was used to wrap step definitions, please use `BeforeStep` / `AfterStep` hooks instead. +If you had other use cases, please create an issue. + +# Migrating from 6.x.x to 7.x.x ## Package Name cucumber-js is now published at `@cucumber/cucumber` instead of `cucumber`. To upgrade, you'll need to remove the old package and add the new one: - + ```shell $ npm rm cucumber $ npm install --save-dev @cucumber/cucumber -``` - +``` + You'll need to update any `import`/`require` statements in your support code to use the new package name. (The executable is still `cucumber-js` though.) diff --git a/docs/support_files/api_reference.md b/docs/support_files/api_reference.md index 6ad0f6360..e47a01570 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -112,7 +112,6 @@ Aliases: `Given`, `When`, `Then`. * `pattern`: A regex or string pattern to match against a gherkin step. * `options`: An object with the following keys: - `timeout`: A step-specific timeout, to override the default timeout. - - `wrapperOptions`: Step-specific options that are passed to the definition function wrapper. * `fn`: A function, which should be defined as follows: - Should have one argument for each capture in the regular expression. - May have an additional argument if the gherkin step has a docstring or data table. @@ -132,37 +131,6 @@ Set the default timeout for asynchronous steps. Defaults to `5000` milliseconds. --- -#### `setDefinitionFunctionWrapper(wrapper)` - -Set a function used to wrap step / hook definitions. - -The `wrapper` function is expected to take 2 arguments: - -- `fn` is the original function defined for the step - needs to be called in order for the step to be run. -- `options` is the step specific `wrapperOptions` and may be undefined. - -A common use case is attaching a screenshot on step failure - this would typically look something like (for a promise-based setup): - -```javascript -setDefinitionFunctionWrapper(function(fn, options) { - return function(...args) { - // call original function with correct `this` and arguments - // ensure return value of function is returned - return fn.apply(this, args) - .catch(error => { - // call a method on world - this.doScreenshot(); - // rethrow error to avoid swallowing failure - throw error; - }); - } -}) -``` - -When used, the result is wrapped again to ensure it has the same length of the original step / hook definition. - ---- - #### `setWorldConstructor(constructor)` Set a custom world constructor, to override the default world constructor: diff --git a/docs/support_files/step_definitions.md b/docs/support_files/step_definitions.md index b62e2da76..fba2aed2e 100644 --- a/docs/support_files/step_definitions.md +++ b/docs/support_files/step_definitions.md @@ -69,36 +69,6 @@ When(/^I view my profile$/, function () { }); ``` - -## Definition function wrapper - -If you would like to wrap step or hook definitions in with some additional logic you can use `setDefinitionFunctionWrapper(fn)`. The definitions will be wrapped after they have all been loaded but before the tests begin to run. One example usage is wrapping generator functions to return promises. Cucumber will do an additional stage of wrapping to ensure the function retains its original length. - -```javascript -// features/step_definitions/file_steps.js -const { Then } = require('@cucumber/cucumber'); -const assert = require('assert'); -const mzFs = require('mz/fs'); - -Then(/^the file named (.*) is empty$/, function *(fileName) { - contents = yield mzFs.readFile(fileName, 'utf8'); - assert.equal(contents, ''); -}); - -// features/support/setup.js -const { setDefinitionFunctionWrapper } = require('@cucumber/cucumber'); -const isGenerator = require('is-generator'); -const Promise = require('bluebird'); - -setDefinitionFunctionWrapper(function (fn) { - if (isGenerator.fn(fn)) { - return Promise.coroutine(fn); - } else { - return fn; - } -}); -``` - ## Pending steps Each interface has its own way of marking a step as pending diff --git a/features/generator_step_definitions.feature b/features/generator_step_definitions.feature deleted file mode 100644 index a9f520286..000000000 --- a/features/generator_step_definitions.feature +++ /dev/null @@ -1,61 +0,0 @@ -Feature: Generator Step Definitions - In order to use new JavaScript features - As a developer - I want Cucumber to provide the possibility to use ES6 features - - Background: - Given a file named "features/a.feature" with: - """ - Feature: Step is a generator - Scenario: Step generator run successfully - When I call a step which is a generator with return value "ok" - Then I can see the yielded "ok" value in the context - """ - And a file named "features/step_definitions/cucumber_steps.js" with: - """ - const assert = require('assert') - const {setWorldConstructor, Then, When} = require('@cucumber/cucumber') - - setWorldConstructor(function () { - this.context = "" - }) - - When(/^I call a step which is a generator with return value "([^"]*)"$/, function *(return_value) { - this.context = yield Promise.resolve(return_value); - }) - - Then(/^I can see the yielded "([^"]*)" value in the context$/, function(return_value) { - assert.equal(this.context, return_value) - }) - """ - - @spawn - Scenario: without generator function runner - When I run cucumber-js - Then it fails - And the error output contains the text: - """ - The following hook/step definitions use generator functions: - - features/step_definitions/cucumber_steps.js:8 - - Use 'this.setDefinitionFunctionWrapper(fn)' to wrap them in a function that returns a promise - """ - - Scenario: with generator function wrapper - Given a file named "features/support/setup.js" with: - """ - const isGenerator = require('is-generator') - const {coroutine} = require('bluebird') - const {setDefinitionFunctionWrapper} = require('@cucumber/cucumber') - - setDefinitionFunctionWrapper(function (fn) { - if (isGenerator.fn(fn)) { - return coroutine(fn) - } else { - return fn - } - }) - """ - When I run cucumber-js - Then it passes diff --git a/features/step_wrapper_with_options.feature b/features/step_wrapper_with_options.feature deleted file mode 100644 index 63f7428f8..000000000 --- a/features/step_wrapper_with_options.feature +++ /dev/null @@ -1,35 +0,0 @@ -Feature: Step Wrapper with Options - In order to be able to write more complex step definition wrappers - As a developer - I want Cucumber to provide the "options" object to the wrapping function - - @spawn - Scenario: options passed to the step definitions wrapper - Given a file named "features/a.feature" with: - """ - Feature: Step with an option - Scenario: Steps - When I run a step with options - """ - And a file named "features/step_definitions/cucumber_steps.js" with: - """ - const {When} = require('@cucumber/cucumber') - - When(/^I run a step with options$/, {wrapperOptions: {retry: 2}}, function () {}) - """ - And a file named "features/support/setup.js" with: - """ - const {setDefinitionFunctionWrapper} = require('@cucumber/cucumber') - - setDefinitionFunctionWrapper(function (fn, options = {}) { - if (options.retry) { - console.log("Max retries: ", options.retry); - } - return fn; - }) - """ - When I run cucumber-js - Then the output contains the text: - """ - Max retries: 2 - """ diff --git a/package.json b/package.json index c3d6e0ef1..271e13492 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,6 @@ "@cucumber/messages": "^16.0.1", "@cucumber/tag-expressions": "^3.0.1", "assertion-error-formatter": "^3.0.0", - "bluebird": "^3.7.2", "capital-case": "^1.0.4", "cli-table3": "^0.6.0", "colors": "^1.4.0", @@ -187,7 +186,6 @@ "figures": "^3.2.0", "glob": "^7.1.6", "indent-string": "^4.0.0", - "is-generator": "^1.0.3", "is-stream": "^2.0.0", "knuth-shuffle-seeded": "^1.0.6", "mz": "^2.7.0", @@ -198,7 +196,6 @@ "stacktrace-js": "^2.0.2", "string-argv": "^0.3.1", "tmp": "^0.2.1", - "util-arity": "^1.1.0", "verror": "^1.10.0" }, "devDependencies": { @@ -206,7 +203,6 @@ "@cucumber/message-streams": "2.1.0", "@cucumber/query": "10.1.0", "@sinonjs/fake-timers": "7.1.2", - "@types/bluebird": "3.5.35", "@types/chai": "4.2.19", "@types/dirty-chai": "2.0.2", "@types/express": "4.17.12", diff --git a/src/cli/helpers_spec.ts b/src/cli/helpers_spec.ts index 4f4e0e640..711f54f01 100644 --- a/src/cli/helpers_spec.ts +++ b/src/cli/helpers_spec.ts @@ -135,7 +135,6 @@ describe('helpers', () => { stepDefinitions: [ new StepDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '0', line: 9, options: {}, @@ -173,7 +172,6 @@ describe('helpers', () => { stepDefinitions: [ new StepDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '0', line: 9, options: {}, @@ -211,7 +209,6 @@ describe('helpers', () => { beforeTestCaseHookDefinitions: [ new TestCaseHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '0', line: 3, options: { @@ -223,7 +220,6 @@ describe('helpers', () => { afterTestCaseHookDefinitions: [ new TestCaseHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '1', line: 7, options: {}, @@ -231,7 +227,6 @@ describe('helpers', () => { }), new TestCaseHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '2', line: 11, options: {}, @@ -285,7 +280,6 @@ describe('helpers', () => { beforeTestRunHookDefinitions: [ new TestRunHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '0', line: 3, options: {}, @@ -295,7 +289,6 @@ describe('helpers', () => { afterTestRunHookDefinitions: [ new TestRunHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '1', line: 7, options: {}, @@ -303,7 +296,6 @@ describe('helpers', () => { }), new TestRunHookDefinition({ code: noopFunction, - unwrappedCode: noopFunction, id: '2', line: 11, options: {}, diff --git a/src/formatter/helpers/usage_helpers/index.ts b/src/formatter/helpers/usage_helpers/index.ts index cfd327948..a711c83b7 100644 --- a/src/formatter/helpers/usage_helpers/index.ts +++ b/src/formatter/helpers/usage_helpers/index.ts @@ -34,7 +34,7 @@ function buildEmptyMapping( const mapping: Record = {} stepDefinitions.forEach((stepDefinition) => { mapping[stepDefinition.id] = { - code: stepDefinition.unwrappedCode.toString(), + code: stepDefinition.code.toString(), line: stepDefinition.line, pattern: stepDefinition.expression.source, patternType: stepDefinition.expression.constructor.name, diff --git a/src/formatter/helpers/usage_helpers/index_spec.ts b/src/formatter/helpers/usage_helpers/index_spec.ts index 081224a2a..d0d096956 100644 --- a/src/formatter/helpers/usage_helpers/index_spec.ts +++ b/src/formatter/helpers/usage_helpers/index_spec.ts @@ -7,65 +7,28 @@ import { buildSupportCodeLibrary } from '../../../../test/runtime_helpers' describe('Usage Helpers', () => { describe('getUsage', () => { describe('with step definitions', () => { - describe('without function definition wrapper', () => { - it('includes stringified code', async () => { - // Arrange - const code = function (): string { - return 'original code' - } - const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => { - Given('a step', code) - }) - const { eventDataCollector } = - await getEnvelopesAndEventDataCollector({ supportCodeLibrary }) - - // Act - const output = getUsage({ - cwd: '/project', - eventDataCollector, - stepDefinitions: supportCodeLibrary.stepDefinitions, - }) - - // Assert - expect(output).to.have.lengthOf(1) - expect(output[0].code).to.eql(code.toString()) + it('includes stringified code', async () => { + // Arrange + const code = function (): string { + return 'original code' + } + const supportCodeLibrary = buildSupportCodeLibrary(({ Given }) => { + Given('a step', code) + }) + const { eventDataCollector } = await getEnvelopesAndEventDataCollector({ + supportCodeLibrary, }) - }) - - describe('with function definition wrapper', () => { - it('includes unwrapped version of stringified code', async () => { - // Arrange - const code = function (): string { - return 'original code' - } - const supportCodeLibrary = buildSupportCodeLibrary( - ({ Given, setDefinitionFunctionWrapper }) => { - Given('a step', code) - setDefinitionFunctionWrapper( - (fn: Function) => - function (fn: Function) { - if (fn.length === 1) { - return fn - } - return fn - } - ) - } - ) - const { eventDataCollector } = - await getEnvelopesAndEventDataCollector({ supportCodeLibrary }) - - // Act - const output = getUsage({ - cwd: '/project', - eventDataCollector, - stepDefinitions: supportCodeLibrary.stepDefinitions, - }) - // Assert - expect(output).to.have.lengthOf(1) - expect(output[0].code).to.eql(code.toString()) + // Act + const output = getUsage({ + cwd: '/project', + eventDataCollector, + stepDefinitions: supportCodeLibrary.stepDefinitions, }) + + // Assert + expect(output).to.have.lengthOf(1) + expect(output[0].code).to.eql(code.toString()) }) }) }) diff --git a/src/index.ts b/src/index.ts index 3272703ac..839bf6f86 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,7 +38,6 @@ export const defineParameterType = methods.defineParameterType export const defineStep = methods.defineStep export const Given = methods.Given export const setDefaultTimeout = methods.setDefaultTimeout -export const setDefinitionFunctionWrapper = methods.setDefinitionFunctionWrapper export const setWorldConstructor = methods.setWorldConstructor export const Then = methods.Then export const When = methods.When diff --git a/src/models/definition.ts b/src/models/definition.ts index 171e89648..437bd7cc6 100644 --- a/src/models/definition.ts +++ b/src/models/definition.ts @@ -16,7 +16,6 @@ export interface IGetInvocationDataResponse { export interface IDefinitionOptions { timeout?: number - wrapperOptions?: any } export interface IHookDefinitionOptions extends IDefinitionOptions { @@ -28,7 +27,6 @@ export interface IDefinitionParameters { id: string line: number options: T - unwrappedCode?: Function uri: string } @@ -43,7 +41,6 @@ export interface IDefinition { readonly id: string readonly line: number readonly options: IDefinitionOptions - readonly unwrappedCode: Function readonly uri: string getInvocationParameters: ( @@ -56,7 +53,6 @@ export default abstract class Definition { public readonly id: string public readonly line: number public readonly options: IDefinitionOptions - public readonly unwrappedCode: Function public readonly uri: string constructor({ @@ -64,14 +60,12 @@ export default abstract class Definition { id, line, options, - unwrappedCode, uri, }: IDefinitionParameters) { this.code = code this.id = id this.line = line this.options = options - this.unwrappedCode = unwrappedCode this.uri = uri } diff --git a/src/support_code_library_builder/finalize_helpers.ts b/src/support_code_library_builder/finalize_helpers.ts deleted file mode 100644 index 83b39dacb..000000000 --- a/src/support_code_library_builder/finalize_helpers.ts +++ /dev/null @@ -1,41 +0,0 @@ -import isGenerator from 'is-generator' -import path from 'path' - -export interface IDefinitionConfig { - code: any - line: number - uri: string -} - -export interface IValidateNoGeneratorFunctionsRequest { - cwd: string - definitionConfigs: IDefinitionConfig[] -} - -export function validateNoGeneratorFunctions({ - cwd, - definitionConfigs, -}: IValidateNoGeneratorFunctionsRequest): void { - const generatorDefinitionConfigs = definitionConfigs.filter( - (definitionConfig) => isGenerator.fn(definitionConfig.code) - ) - if (generatorDefinitionConfigs.length > 0) { - const references = generatorDefinitionConfigs - .map( - (definitionConfig) => - `${path.relative( - cwd, - definitionConfig.uri - )}:${definitionConfig.line.toString()}` - ) - .join('\n ') - const message = ` - The following hook/step definitions use generator functions: - - ${references} - - Use 'this.setDefinitionFunctionWrapper(fn)' to wrap them in a function that returns a promise. - ` - throw new Error(message) - } -} diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index 3bf43524e..4a7f04d55 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -7,15 +7,12 @@ import TestRunHookDefinition from '../models/test_run_hook_definition' import StepDefinition from '../models/step_definition' import { formatLocation } from '../formatter/helpers' import validateArguments from './validate_arguments' -import arity from 'util-arity' - import { CucumberExpression, ParameterTypeRegistry, RegularExpression, } from '@cucumber/cucumber-expressions' -import { doesHaveValue, doesNotHaveValue } from '../value_checker' -import { validateNoGeneratorFunctions } from './finalize_helpers' +import { doesHaveValue } from '../value_checker' import { DefineStepPattern, IDefineStepOptions, @@ -73,7 +70,6 @@ export class SupportCodeLibraryBuilder { private beforeTestStepHookDefinitionConfigs: ITestStepHookDefinitionConfig[] private cwd: string private defaultTimeout: number - private definitionFunctionWrapper: any private newId: IdGenerator.NewId private parameterTypeRegistry: ParameterTypeRegistry private stepDefinitionConfigs: IStepDefinitionConfig[] @@ -106,9 +102,6 @@ export class SupportCodeLibraryBuilder { setDefaultTimeout: (milliseconds) => { this.defaultTimeout = milliseconds }, - setDefinitionFunctionWrapper: (fn) => { - this.definitionFunctionWrapper = fn - }, setWorldConstructor: (fn) => { this.World = fn }, @@ -243,39 +236,16 @@ export class SupportCodeLibraryBuilder { } } - wrapCode({ - code, - wrapperOptions, - }: { - code: Function - wrapperOptions: any - }): Function { - if (doesHaveValue(this.definitionFunctionWrapper)) { - const codeLength = code.length - const wrappedCode = this.definitionFunctionWrapper(code, wrapperOptions) - if (wrappedCode !== code) { - return arity(codeLength, wrappedCode) - } - return wrappedCode - } - return code - } - buildTestCaseHookDefinitions( configs: ITestCaseHookDefinitionConfig[], canonicalIds?: string[] ): TestCaseHookDefinition[] { return configs.map(({ code, line, options, uri }, index) => { - const wrappedCode = this.wrapCode({ - code, - wrapperOptions: options.wrapperOptions, - }) return new TestCaseHookDefinition({ - code: wrappedCode, + code, id: canonicalIds ? canonicalIds[index] : this.newId(), line, options, - unwrappedCode: code, uri, }) }) @@ -285,16 +255,11 @@ export class SupportCodeLibraryBuilder { configs: ITestStepHookDefinitionConfig[] ): TestStepHookDefinition[] { return configs.map(({ code, line, options, uri }) => { - const wrappedCode = this.wrapCode({ - code, - wrapperOptions: options.wrapperOptions, - }) return new TestStepHookDefinition({ - code: wrappedCode, + code, id: this.newId(), line, options, - unwrappedCode: code, uri, }) }) @@ -304,16 +269,11 @@ export class SupportCodeLibraryBuilder { configs: ITestRunHookDefinitionConfig[] ): TestRunHookDefinition[] { return configs.map(({ code, line, options, uri }) => { - const wrappedCode = this.wrapCode({ - code, - wrapperOptions: options.wrapperOptions, - }) return new TestRunHookDefinition({ - code: wrappedCode, + code, id: this.newId(), line, options, - unwrappedCode: code, uri, }) }) @@ -351,19 +311,14 @@ export class SupportCodeLibraryBuilder { ) } - const wrappedCode = this.wrapCode({ - code, - wrapperOptions: options.wrapperOptions, - }) stepDefinitions.push( new StepDefinition({ - code: wrappedCode, + code, expression, id: canonicalIds ? canonicalIds[index] : this.newId(), line, options, pattern, - unwrappedCode: code, uri, }) ) @@ -373,16 +328,6 @@ export class SupportCodeLibraryBuilder { } finalize(canonicalIds?: ICanonicalSupportCodeIds): ISupportCodeLibrary { - if (doesNotHaveValue(this.definitionFunctionWrapper)) { - const definitionConfigs = [ - this.afterTestCaseHookDefinitionConfigs, - this.afterTestRunHookDefinitionConfigs, - this.beforeTestCaseHookDefinitionConfigs, - this.beforeTestRunHookDefinitionConfigs, - this.stepDefinitionConfigs, - ].flat() - validateNoGeneratorFunctions({ cwd: this.cwd, definitionConfigs }) - } const stepDefinitionsResult = this.buildStepDefinitions( canonicalIds?.stepDefinitionIds ) @@ -424,7 +369,6 @@ export class SupportCodeLibraryBuilder { this.beforeTestCaseHookDefinitionConfigs = [] this.beforeTestRunHookDefinitionConfigs = [] this.beforeTestStepHookDefinitionConfigs = [] - this.definitionFunctionWrapper = null this.defaultTimeout = 5000 this.parameterTypeRegistry = new ParameterTypeRegistry() this.stepDefinitionConfigs = [] diff --git a/src/support_code_library_builder/index_spec.ts b/src/support_code_library_builder/index_spec.ts index 6485741a5..f0f806fa1 100644 --- a/src/support_code_library_builder/index_spec.ts +++ b/src/support_code_library_builder/index_spec.ts @@ -38,66 +38,40 @@ describe('supportCodeLibraryBuilder', () => { }) describe('step', () => { - describe('without definition function wrapper', () => { - it('adds a step definition and makes original code available', function () { - // Arrange - const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function - supportCodeLibraryBuilder.reset('path/to/project', uuid()) - supportCodeLibraryBuilder.methods.defineStep('I do a thing', step) - - // Act - const options = supportCodeLibraryBuilder.finalize() - - // Assert - expect(options.stepDefinitions).to.have.lengthOf(1) - const stepDefinition = options.stepDefinitions[0] - expect(stepDefinition.code).to.eql(step) - expect(stepDefinition.unwrappedCode).to.eql(step) - }) - - it('uses the canonical ids provided in order', function () { - // Arrange - const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function - supportCodeLibraryBuilder.reset('path/to/project', uuid()) - supportCodeLibraryBuilder.methods.defineStep('I do a thing', step) - supportCodeLibraryBuilder.methods.defineStep('I do another thing', step) + it('adds a step definition and makes original code available', function () { + // Arrange + const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function + supportCodeLibraryBuilder.reset('path/to/project', uuid()) + supportCodeLibraryBuilder.methods.defineStep('I do a thing', step) - // Act - const options = supportCodeLibraryBuilder.finalize({ - stepDefinitionIds: ['one', 'two'], - beforeTestCaseHookDefinitionIds: [], - afterTestCaseHookDefinitionIds: [], - }) + // Act + const options = supportCodeLibraryBuilder.finalize() - // Assert - expect(options.stepDefinitions).to.have.lengthOf(2) - expect( - options.stepDefinitions.map((stepDefinition) => stepDefinition.id) - ).to.deep.eq(['one', 'two']) - }) + // Assert + expect(options.stepDefinitions).to.have.lengthOf(1) + const stepDefinition = options.stepDefinitions[0] + expect(stepDefinition.code).to.eql(step) }) - describe('with definition function wrapper', () => { - it('adds a step definition and makes original code available', function () { - // Arrange - const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function - supportCodeLibraryBuilder.reset('path/to/project', uuid()) - supportCodeLibraryBuilder.methods.defineStep('I do a thing', step) - supportCodeLibraryBuilder.methods.setDefinitionFunctionWrapper( - function (fn: Function) { - return fn() - } - ) - - // Act - const options = supportCodeLibraryBuilder.finalize() + it('uses the canonical ids provided in order', function () { + // Arrange + const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function + supportCodeLibraryBuilder.reset('path/to/project', uuid()) + supportCodeLibraryBuilder.methods.defineStep('I do a thing', step) + supportCodeLibraryBuilder.methods.defineStep('I do another thing', step) - // Assert - expect(options.stepDefinitions).to.have.lengthOf(1) - const stepDefinition = options.stepDefinitions[0] - expect(stepDefinition.code).not.to.eql(step) - expect(stepDefinition.unwrappedCode).to.eql(step) + // Act + const options = supportCodeLibraryBuilder.finalize({ + stepDefinitionIds: ['one', 'two'], + beforeTestCaseHookDefinitionIds: [], + afterTestCaseHookDefinitionIds: [], }) + + // Assert + expect(options.stepDefinitions).to.have.lengthOf(2) + expect( + options.stepDefinitions.map((stepDefinition) => stepDefinition.id) + ).to.deep.eq(['one', 'two']) }) }) diff --git a/src/support_code_library_builder/types.ts b/src/support_code_library_builder/types.ts index 67d783053..693dd8a2b 100644 --- a/src/support_code_library_builder/types.ts +++ b/src/support_code_library_builder/types.ts @@ -40,7 +40,6 @@ export type TestStepFunction = ( export interface IDefineStepOptions { timeout?: number - wrapperOptions?: any } export interface IDefineTestCaseHookOptions { @@ -77,7 +76,6 @@ export interface IDefineSupportCodeMethods { code: TestStepFunction ) => void) setDefaultTimeout: (milliseconds: number) => void - setDefinitionFunctionWrapper: (fn: Function) => void setWorldConstructor: (fn: any) => void After: ((code: TestCaseHookFunction) => void) & (( diff --git a/src/time_spec.ts b/src/time_spec.ts index 6e1e94ad3..2fe66e793 100644 --- a/src/time_spec.ts +++ b/src/time_spec.ts @@ -2,7 +2,7 @@ import { describe, it } from 'mocha' import { expect } from 'chai' import { wrapPromiseWithTimeout } from './time' -describe.only('wrapPromiseWithTimeout()', () => { +describe('wrapPromiseWithTimeout()', () => { describe('promise times out (default timeout message)', () => { it('rejects the promise', async () => { // Arrange diff --git a/yarn.lock b/yarn.lock index 4c39c0b43..ba0ebe021 100644 --- a/yarn.lock +++ b/yarn.lock @@ -409,11 +409,6 @@ resolved "https://registry.yarnpkg.com/@tsd/typescript/-/typescript-4.3.4.tgz#3ca75b0fad11180c17a7a6949bda0b0f4a90682f" integrity sha512-o5nx5an9JK+SUN/UiMmVwG3Eg+SsGrtdMtrw82bpZetMO2PkXBERgsf5KxsuPw3qm576z1R/SEUQRb1KaKGlOQ== -"@types/bluebird@3.5.35": - version "3.5.35" - resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.35.tgz#3964c48372bf62d60616d8673dd77a9719ebac9b" - integrity sha512-2WeeXK7BuQo7yPI4WGOBum90SzF/f8rqlvpaXx4rjeTmNssGRDHWf7fgDUH90xMB3sUOu716fUK5d+OVx0+ncQ== - "@types/body-parser@*": version "1.19.0" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.0.tgz#0685b3c47eb3006ffed117cdd55164b61f80538f" @@ -952,7 +947,7 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bluebird@^3.4.3, bluebird@^3.7.2: +bluebird@^3.4.3: version "3.7.2" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== @@ -2377,11 +2372,6 @@ is-fullwidth-code-point@^3.0.0: resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== -is-generator@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/is-generator/-/is-generator-1.0.3.tgz#c14c21057ed36e328db80347966c693f886389f3" - integrity sha1-wUwhBX7TbjKNuANHlmxpP4hjifM= - is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" @@ -4093,11 +4083,6 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" -util-arity@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/util-arity/-/util-arity-1.1.0.tgz#59d01af1fdb3fede0ac4e632b0ab5f6ce97c9330" - integrity sha1-WdAa8f2z/t4KxOYysKtfbOl8kzA= - utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"