@@ -10,7 +10,7 @@ import TestStepHookDefinition from '../models/test_step_hook_definition'
1010import TestRunHookDefinition from '../models/test_run_hook_definition'
1111import StepDefinition from '../models/step_definition'
1212import { formatLocation } from '../formatter/helpers'
13- import { doesHaveValue , doesNotHaveValue } from '../value_checker'
13+ import { doesHaveValue } from '../value_checker'
1414import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types'
1515import { GherkinStepKeyword } from '../models/gherkin_step_keyword'
1616import validateArguments from './validate_arguments'
@@ -65,9 +65,10 @@ interface ITestRunHookDefinitionConfig {
6565 uri : string
6666}
6767
68+ type LibraryStatus = 'PENDING' | 'OPEN' | 'FINALIZED'
69+
6870export class SupportCodeLibraryBuilder {
6971 public readonly methods : IDefineSupportCodeMethods
70-
7172 private originalCoordinates : ISupportCodeCoordinates
7273 private afterTestCaseHookDefinitionConfigs : ITestCaseHookDefinitionConfig [ ]
7374 private afterTestRunHookDefinitionConfigs : ITestRunHookDefinitionConfig [ ]
@@ -83,6 +84,7 @@ export class SupportCodeLibraryBuilder {
8384 private stepDefinitionConfigs : IStepDefinitionConfig [ ]
8485 private World : any
8586 private parallelCanAssign : ParallelAssignmentValidator
87+ private status : LibraryStatus = 'PENDING'
8688
8789 constructor ( ) {
8890 const methods : IDefineSupportCodeMethods = {
@@ -123,11 +125,11 @@ export class SupportCodeLibraryBuilder {
123125 When : this . defineStep ( 'When' , ( ) => this . stepDefinitionConfigs ) ,
124126 }
125127 const checkInstall = ( method : string ) => {
126- if ( doesNotHaveValue ( this . cwd ) ) {
128+ if ( this . status === 'PENDING' ) {
127129 throw new Error (
128130 `
129- You're calling functions (e.g. "${ method } ") on an instance of Cucumber that isn't running.
130- This means you have an invalid installation, mostly likely due to:
131+ You're calling functions (e.g. "${ method } ") on an instance of Cucumber that isn't running (status: ${ this . status } ) .
132+ This means you may have an invalid installation, potentially due to:
131133 - Cucumber being installed globally
132134 - A project structure where your support code is depending on a different instance of Cucumber
133135 Either way, you'll need to address this in order for Cucumber to work.
@@ -414,6 +416,7 @@ export class SupportCodeLibraryBuilder {
414416 }
415417
416418 finalize ( canonicalIds ?: ICanonicalSupportCodeIds ) : SupportCodeLibrary {
419+ this . status = 'FINALIZED'
417420 const stepDefinitionsResult = this . buildStepDefinitions (
418421 canonicalIds ?. stepDefinitionIds
419422 )
@@ -472,6 +475,7 @@ export class SupportCodeLibraryBuilder {
472475 this . stepDefinitionConfigs = [ ]
473476 this . parallelCanAssign = ( ) => true
474477 this . World = World
478+ this . status = 'OPEN'
475479 }
476480}
477481
0 commit comments