From ebb3da7dc79585aeb36b7934c15d2712c2ab7f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Andr=C3=A9=20Zinser?= Date: Fri, 30 Dec 2016 16:47:44 +0100 Subject: [PATCH] export factory function to use mocha-webpack programmatically --- package.json | 1 + src/cli/index.js | 4 ++-- src/createMochaWebpack.js | 7 +++++++ test/unit/createMochaWebpack.test.js | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/createMochaWebpack.js create mode 100644 test/unit/createMochaWebpack.test.js diff --git a/package.json b/package.json index 6c83e63..1248f4d 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "bin": { "mocha-webpack": "./bin/mocha-webpack" }, + "main": "./lib/createMochaWebpack.js", "files": [ "*.md", "bin", diff --git a/src/cli/index.js b/src/cli/index.js index a4e0ab7..7212916 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -6,7 +6,7 @@ import { existsFileSync } from '../util/exists'; import parseConfig from './parseConfig'; import requireWebpackConfig from './requireWebpackConfig'; import { ensureGlob, extensionsToGlob } from '../util/glob'; -import MochaWebpack from '../MochaWebpack'; +import createMochaWebpack from '../createMochaWebpack'; function resolve(mod) { @@ -39,7 +39,7 @@ options.include = options.include.map(resolve); options.webpackConfig = requireWebpackConfig(options.webpackConfig); -const mochaWebpack = new MochaWebpack(); +const mochaWebpack = createMochaWebpack(); options.include.forEach((f) => mochaWebpack.addInclude(f)); diff --git a/src/createMochaWebpack.js b/src/createMochaWebpack.js new file mode 100644 index 0000000..2b6a1b6 --- /dev/null +++ b/src/createMochaWebpack.js @@ -0,0 +1,7 @@ +// @flow +import MochaWebpack from './MochaWebpack'; + +// module.exports cause of babel 6 +module.exports = function createMochaWebpack(): MochaWebpack { + return new MochaWebpack(); +}; diff --git a/test/unit/createMochaWebpack.test.js b/test/unit/createMochaWebpack.test.js new file mode 100644 index 0000000..234ace9 --- /dev/null +++ b/test/unit/createMochaWebpack.test.js @@ -0,0 +1,15 @@ +/* eslint-env node, mocha */ +/* eslint-disable func-names, prefer-arrow-callback, no-loop-func, max-len */ +import { assert } from 'chai'; +import MochaWebpack from '../../src/MochaWebpack'; +import createMochaWebpack from '../../src/createMochaWebpack'; + +describe('createMochaWebpack', function () { + it('should create a instance of MochaWebpack', function () { + assert.doesNotThrow(() => createMochaWebpack()); + const mochaWebpack = createMochaWebpack(); + + assert.isNotNull(mochaWebpack); + assert.instanceOf(mochaWebpack, MochaWebpack); + }); +});