UNPKG

2.55 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const run_js_1 = __importDefault(require("mocha/lib/cli/run.js"));
7const options_js_1 = require("mocha/lib/cli/options.js");
8const yargs_1 = __importDefault(require("yargs/yargs"));
9const instant_mocha_1 = __importDefault(require("./instant-mocha"));
10// eslint-disable-next-line @typescript-eslint/no-var-requires
11const { version } = require('../package.json');
12const INSTANT_MOCHA_OPTIONS_GROUP = 'instant-mocha options';
13const argv = options_js_1.loadOptions(process.argv.slice(2));
14yargs_1.default()
15 .scriptName('instant-mocha')
16 .command({
17 ...run_js_1.default,
18 command: ['$0 [spec..]'],
19 describe: 'Build tests with Webpack and run them with Mocha',
20 builder(cli) {
21 const removeOptions = new Set([
22 'watch',
23 'watch-files',
24 'watch-ignore',
25 ]);
26 const proxiedCli = Object.assign(Object.create(cli), {
27 options(mochaOptions) {
28 const filteredOptions = {};
29 for (const key in mochaOptions) {
30 if (!removeOptions.has(key)) {
31 filteredOptions[key] = mochaOptions[key];
32 }
33 }
34 return cli.options.call(this, filteredOptions);
35 },
36 });
37 run_js_1.default.builder(proxiedCli);
38 },
39 async handler(options) {
40 try {
41 const failures = await instant_mocha_1.default(options);
42 if (failures > 0) {
43 // Mocha originally exists with the number of failures
44 // but that's non-standard: https://github.com/mochajs/mocha/issues/3559
45 process.exit(1);
46 }
47 }
48 catch (error) {
49 console.log(error.message);
50 process.exit(1);
51 }
52 },
53})
54 .options({
55 'webpack-config': {
56 description: 'Path to Webpack configuration',
57 group: INSTANT_MOCHA_OPTIONS_GROUP,
58 type: 'string',
59 },
60 watch: {
61 description: 'Watch mode',
62 group: INSTANT_MOCHA_OPTIONS_GROUP,
63 },
64})
65 .help('help', 'Show usage information & exit')
66 .alias('help', 'h')
67 .version('version', 'Show version number & exit', version)
68 .alias('version', 'V')
69 .wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
70 .config(argv)
71 .parse(argv._);