Skip to content

Commit

Permalink
fix(loadFeature): regression in loadFeature now corrected to consider…
Browse files Browse the repository at this point in the history
… global options for relative feature file loading
  • Loading branch information
pplancq committed Apr 18, 2024
1 parent 94d1c05 commit 938bf7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": [
"**/*.steps.ts"
"**/*.{steps,test}.ts"
],
"moduleFileExtensions": [
"js",
Expand Down
18 changes: 18 additions & 0 deletions specs/parsed-feature-loading.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
3 changes: 2 additions & 1 deletion src/parsed-feature-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 938bf7c

Please sign in to comment.