From 938bf7cad93160088e3485a6af17167ef66f8b10 Mon Sep 17 00:00:00 2001 From: pplancq Date: Thu, 18 Apr 2024 18:27:48 +0200 Subject: [PATCH] fix(loadFeature): regression in loadFeature now corrected to consider global options for relative feature file loading --- package.json | 2 +- specs/parsed-feature-loading.test.ts | 18 ++++++++++++++++++ src/parsed-feature-loading.ts | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 specs/parsed-feature-loading.test.ts diff --git a/package.json b/package.json index aa4797f..6458982 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "^.+\\.tsx?$": "ts-jest" }, "testMatch": [ - "**/*.steps.ts" + "**/*.{steps,test}.ts" ], "moduleFileExtensions": [ "js", diff --git a/specs/parsed-feature-loading.test.ts b/specs/parsed-feature-loading.test.ts new file mode 100644 index 0000000..d6d3ce2 --- /dev/null +++ b/specs/parsed-feature-loading.test.ts @@ -0,0 +1,18 @@ +import { loadFeature, setJestCucumberConfiguration } from '../src'; + +describe('loadFeature', () => { + it('should not throw an exception when loadFeature is called with loadRelativePath set to true in the global configuration', () => { + setJestCucumberConfiguration({ + loadRelativePath: true, + }); + + let hasException = false; + try { + loadFeature('./features/auto-bind-steps.feature'); + } catch (e) { + hasException = true; + } + + expect(hasException).toBeFalsy(); + }); +}); diff --git a/src/parsed-feature-loading.ts b/src/parsed-feature-loading.ts index bfb8b58..a7cfb9d 100644 --- a/src/parsed-feature-loading.ts +++ b/src/parsed-feature-loading.ts @@ -347,7 +347,8 @@ export const loadFeature = (featureFilePath: string, options?: Options) => { const callSite = callsites()[1]; const fileOfCaller = (callSite && callSite.getFileName()) || ''; const dirOfCaller = dirname(fileOfCaller); - const absoluteFeatureFilePath = resolve(options && options.loadRelativePath ? dirOfCaller : '', featureFilePath); + const resolveOptions = getJestCucumberConfiguration(options); + const absoluteFeatureFilePath = resolve(resolveOptions.loadRelativePath ? dirOfCaller : '', featureFilePath); try { const featureText: string = readFileSync(absoluteFeatureFilePath, 'utf8');