Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use explicit status field to determine (not) running status #2386

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: use explicit status field to determine (not) running status
davidjgoss committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 5bab57dd45d5537dad29bf6ba8fcd8ffc1c2d6a6
12 changes: 8 additions & 4 deletions src/support_code_library_builder/index.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
import TestRunHookDefinition from '../models/test_run_hook_definition'
import StepDefinition from '../models/step_definition'
import { formatLocation } from '../formatter/helpers'
import { doesHaveValue, doesNotHaveValue } from '../value_checker'

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (ubuntu-latest, 18.x)

'doesNotHaveValue' is defined but never used

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (ubuntu-latest, 20.x)

'doesNotHaveValue' is defined but never used

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (ubuntu-latest, 21.x)

'doesNotHaveValue' is defined but never used

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (windows-latest, 18.x)

'doesNotHaveValue' is defined but never used

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (windows-latest, 20.x)

'doesNotHaveValue' is defined but never used

Check failure on line 13 in src/support_code_library_builder/index.ts

GitHub Actions / test (windows-latest, 21.x)

'doesNotHaveValue' is defined but never used
import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types'
import { GherkinStepKeyword } from '../models/gherkin_step_keyword'
import validateArguments from './validate_arguments'
@@ -65,9 +65,10 @@
uri: string
}

type LibraryStatus = 'PENDING' | 'OPEN' | 'FINALIZED'

export class SupportCodeLibraryBuilder {
public readonly methods: IDefineSupportCodeMethods

private originalCoordinates: ISupportCodeCoordinates
private afterTestCaseHookDefinitionConfigs: ITestCaseHookDefinitionConfig[]
private afterTestRunHookDefinitionConfigs: ITestRunHookDefinitionConfig[]
@@ -83,6 +84,7 @@
private stepDefinitionConfigs: IStepDefinitionConfig[]
private World: any
private parallelCanAssign: ParallelAssignmentValidator
private status: LibraryStatus = 'PENDING'

constructor() {
const methods: IDefineSupportCodeMethods = {
@@ -123,11 +125,11 @@
When: this.defineStep('When', () => this.stepDefinitionConfigs),
}
const checkInstall = (method: string) => {
if (doesNotHaveValue(this.cwd)) {
if (this.status === 'PENDING') {
throw new Error(
`
You're calling functions (e.g. "${method}") on an instance of Cucumber that isn't running.
This means you have an invalid installation, mostly likely due to:
You're calling functions (e.g. "${method}") on an instance of Cucumber that isn't running (status: ${this.status}).
This means you may have an invalid installation, potentially due to:
- Cucumber being installed globally
- A project structure where your support code is depending on a different instance of Cucumber
Either way, you'll need to address this in order for Cucumber to work.
@@ -414,6 +416,7 @@
}

finalize(canonicalIds?: ICanonicalSupportCodeIds): SupportCodeLibrary {
this.status = 'FINALIZED'
const stepDefinitionsResult = this.buildStepDefinitions(
canonicalIds?.stepDefinitionIds
)
@@ -472,6 +475,7 @@
this.stepDefinitionConfigs = []
this.parallelCanAssign = () => true
this.World = World
this.status = 'OPEN'
}
}

11 changes: 11 additions & 0 deletions src/support_code_library_builder/index_spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fail } from 'node:assert'
import { describe, it } from 'mocha'
import { expect } from 'chai'
import sinon from 'sinon'
@@ -9,6 +10,16 @@ import supportCodeLibraryBuilder from './'
const { uuid } = IdGenerator

describe('supportCodeLibraryBuilder', () => {
it('should throw if not been reset yet', () => {
try {
supportCodeLibraryBuilder.methods.Given('some context', () => {})
fail()
} catch (e) {
expect(e.message).to.contain('calling functions (e.g. "Given")')
expect(e.message).to.contain('status: PENDING')
}
})

describe('no support code fns', () => {
it('returns the default options', function () {
// Arrange