Skip to content

Commit

Permalink
fix(esm): worked around the fact that __dirname is not defined for esm
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jun 28, 2022
1 parent 26a85ec commit 1b8c560
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"ui":"tdd","require":["@babel/register","./test/mocha-setup.js"]}
{
"ui": "tdd",
"require": [
"@babel/register",
"./test/mocha-setup.js"
]
}
6 changes: 0 additions & 6 deletions cucumber.js

This file was deleted.

22 changes: 22 additions & 0 deletions cucumber.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const base = {
formatOptions: {snippetInterface: 'async-await'},
import: ['test/integration/features/**/*.mjs'],
publishQuiet: true
};

export default base;

export const wip = {
...base,
tags: '@wip and not @skip'
};

export const noWip = {
...base,
tags: 'not @skip and not @wip'
};

export const focus = {
...base,
tags: '@focus'
};
143 changes: 142 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"lint:engines": "ls-engines",
"lint:gherkin": "gherkin-lint",
"test:integration": "run-s 'test:integration:base -- --profile noWip'",
"test:integration:base": "NODE_OPTIONS=--enable-source-maps DEBUG=any cucumber-js test/integration --profile base",
"pretest:integration:base": "run-s build",
"test:integration:base": "NODE_OPTIONS=\"--loader=testdouble --enable-source-maps\" DEBUG=any cucumber-js test/integration",
"test:integration:debug": "DEBUG=test run-s test:integration",
"test:integration:wip": "run-s 'test:integration:base -- --profile wip'",
"test:integration:wip:debug": "DEBUG=test run-s 'test:integration:wip'",
Expand Down Expand Up @@ -82,11 +83,13 @@
"rimraf": "3.0.2",
"rollup": "2.75.7",
"rollup-plugin-auto-external": "2.0.0",
"sinon": "14.0.0"
"sinon": "14.0.0",
"testdouble": "3.16.6"
},
"dependencies": {
"@form8ion/config-file": "^1.0.1",
"@form8ion/core": "^1.8.0",
"filedirname": "^2.7.0",
"make-dir": "^3.1.0"
}
}
3 changes: 3 additions & 0 deletions src/mocha.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {promises as fs} from 'fs';
import path from 'path';
import filedirname from 'filedirname';
import {fileTypes} from '@form8ion/core';
import {write} from '@form8ion/config-file';

import mkdir from '../thirdparty-wrappers/make-dir';

const [, __dirname] = filedirname();

export default async function ({projectRoot}) {
const testFilenamePattern = 'src/**/*-test.js';
const [createdTestDirectory, createdSrcDirectory] = await Promise.all([
Expand Down
6 changes: 6 additions & 0 deletions test/integration/features/scaffold.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: scaffold

Scenario: new project
When the project is scaffolded
Then the testing framework is configured
And a canary test exists to ensure the framework configuration works
23 changes: 23 additions & 0 deletions test/integration/features/step_definitions/common-steps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {resolve} from 'path';
import filedirname from 'filedirname';
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
import {scaffold} from '@form8ion/mocha-scaffolder';

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

const [, __dirname] = filedirname();
const pathToProjectRoot = [__dirname, '..', '..', '..', '..'];

Before(function () {
stubbedFs({
node_modules: stubbedFs.load(resolve(...([...pathToProjectRoot, 'node_modules']))),
templates: stubbedFs.load(resolve(...([...pathToProjectRoot, 'templates'])))
});
})

When('the project is scaffolded', async function () {
this.scaffoldRoot = process.cwd();

await scaffold({projectRoot: this.scaffoldRoot});
});
13 changes: 13 additions & 0 deletions test/integration/features/step_definitions/configuration-steps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Then} from '@cucumber/cucumber';
import {fileExists} from '@form8ion/core';

import {assert} from 'chai';

Then('the testing framework is configured', async function () {
assert.isTrue(await fileExists(`${this.scaffoldRoot}/.mocharc.json`));
assert.isTrue(await fileExists(`${this.scaffoldRoot}/test/mocha-setup.js`));
});

Then('a canary test exists to ensure the framework configuration works', async function () {
assert.isTrue(await fileExists(`${this.scaffoldRoot}/src/canary-test.js`));
});

0 comments on commit 1b8c560

Please sign in to comment.