Skip to content

Commit

Permalink
feat(common-steps): updated the template to stub the file system in t…
Browse files Browse the repository at this point in the history
…he `Before` step
  • Loading branch information
travi committed Dec 26, 2023
1 parent c716af3 commit 42ab498
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions templates/common-steps.mustache
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';

import {After, When} from '@cucumber/cucumber';
import {After, Before When} from '@cucumber/cucumber';
import stubbedFs from 'mock-fs';

const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-underscore-dangle
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));

After(function () {
stubbedFs.restore();
});
let scaffold;

When('the project is scaffolded', async function () {
Before(function () {
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
const {scaffold} = await import('{{{ packageName }}}');
({scaffold} = await import('{{{ packageName }}}'));

stubbedFs({
node_modules: stubbedNodeModules
});
});

After(function () {
stubbedFs.restore();
});

When('the project is scaffolded', async function () {
await scaffold({projectRoot: process.cwd()});
});

0 comments on commit 42ab498

Please sign in to comment.