Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"12.0.0-beta-2"}
{ ".": "12.0.0-beta-2" }
8 changes: 8 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ Mocha.prototype.reporter = function (reporterName, reporterOptions) {
}
}
}
if (reporter.default) {
reporter = reporter.default;
}

this._reporter = reporter;
}
this.options.reporterOption = reporterOptions;
Expand Down Expand Up @@ -363,6 +367,10 @@ Mocha.prototype.ui = function (ui) {
}
}
}
if (bindInterface.default) {
bindInterface = bindInterface.default;
}

bindInterface(this.suite);

this.suite.on(EVENT_FILE_PRE_REQUIRE, function (context) {
Expand Down
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/reporter-esm.fixture.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function SimplerReporter(runner, options) {
console.log(JSON.stringify(options.reporterOption));
}

export default SimplerReporter;
39 changes: 39 additions & 0 deletions test/integration/fixtures/simple-ui.fixture.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Mocha from '../../../lib/mocha.js'
import MochaInterface from '../../../lib/interfaces/common.js';

const Test = Mocha.Test;
const EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;

/**
* A simple UI that only exposes a single function: test
*/
function SimpleUI(suite) {
suite.on(EVENT_FILE_PRE_REQUIRE, function(
context,
file,
mocha
) {
const common = MochaInterface(
[suite],
context
);

context.run = mocha.options.delay && common.runWithSuite(suite);

/**
* Describes a specification or test-case with the given `title`
* and callback `fn` acting as a thunk.
*/
context.test = function(title, fn) {
const test = new Test(title, fn);
test.file = file;
suite.addTest(test);

return test;
};
});
};

Mocha.interfaces['simple-ui'] = SimpleUI;

export default SimpleUI;
30 changes: 30 additions & 0 deletions test/integration/options/reporter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

var runMocha = require("../helpers").runMocha;
var path = require("node:path");

describe("--reporter", function () {
it("should work for ESM", function (done) {
runMocha(
"passing.fixture.js",
[
"--reporter",
path.join(
__dirname,
"..",
"fixtures",
"options",
"reporter-esm.fixture.mjs",
),
],
function (err, res) {
if (err) {
return done(err);
}
expect(res, "to have passed");
done();
},
"inherit",
);
});
});
33 changes: 32 additions & 1 deletion test/integration/options/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var helpers = require("../helpers");
var runMochaJSON = helpers.runMochaJSON;

describe("--ui", function () {
var simpleUiPath = require.resolve("../fixtures/simple-ui.fixture");
var simpleUiPath = require.resolve("../fixtures/simple-ui.fixture.js");
var simpleUiESMPath = require.resolve("../fixtures/simple-ui.fixture.mjs");

it("should load interface and run it", function (done) {
runMochaJSON(
Expand Down Expand Up @@ -35,4 +36,34 @@ describe("--ui", function () {
},
);
});

it("should work for ESM", function (done) {
runMochaJSON(
"test-for-simple-ui",
["--require", simpleUiESMPath, "--ui", "simple-ui"],
function (err, res) {
if (err) {
done(err);
return;
}
expect(res, "to have passed");
done();
},
);
});

it("should work for ESM when imported via path", function (done) {
runMochaJSON(
"test-for-simple-ui",
["--ui", simpleUiESMPath],
function (err, res) {
if (err) {
done(err);
return;
}
expect(res, "to have passed");
done();
},
);
});
});