Skip to content

Instantly share code, notes, and snippets.

@slacktracer
Forked from anonymous/mochainstance.mjs
Created February 18, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slacktracer/88c79348dbee5680e86e91b6e5f6b315 to your computer and use it in GitHub Desktop.
Save slacktracer/88c79348dbee5680e86e91b6e5f6b315 to your computer and use it in GitHub Desktop.
Mocha ES Modules Example
import Mocha from "mocha"
export default new Mocha()
import mocha from "./mochainstance.mjs"
mocha.suite.emit(
"post-require",
global,
"If anything uses the file argument, you'd actually need one pre-require, require and post-require per test file with the test file name hardcoded here",
mocha);
import mocha from "./mochainstance.mjs"
mocha.suite.emit(
"pre-require",
global,
"If anything uses the file argument, you'd actually need one pre-require, require and post-require per test file with the test file name hardcoded here",
mocha);
import mocha from "./mochainstance.mjs"
mocha.suite.emit(
"require",
null /* if this is actually needed... then like the file argument, you'd need one of this file per test file to import the test file and pass the test file here */,
"If anything uses the file argument, you'd actually need one pre-require, require and post-require per test file with the test file name hardcoded here",
mocha);
import "./prerequire.mjs"
import "./test-forwardslash-file1.mjs"
import "./require.mjs"
import "./postrequire.mjs"
import "./prerequire.mjs"
import "./test-forwardslash-file2.js"
import "./require.mjs"
import "./postrequire.mjs"
import "./prerequire.mjs"
import "./test-forwardslash-file3.mjs"
import "./require.mjs"
import "./postrequire.mjs"
import mocha from "./mochainstance.mjs"
mocha.run(function(failures) {
process.on("exit", function() {
process.exit(failures > 0 ? 1 : 0);
});
});
describe("ES Module file 1", function() {
it("should load this test", function() {})
})
describe("CommonJS Module file 2", function() {
it("should load this test", function() {})
})
describe("ES Module file 3", function() {
it("should load this test", function() {})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment