diff --git a/test/grep/README b/test/grep/README index 821e739..eb274b8 100644 --- a/test/grep/README +++ b/test/grep/README @@ -1 +1,2 @@ -Check that --grep flag run tests by string pattern 'grep' +- index.js check that --grep flag run tests by string pattern 'grep' +- indexProgrammatic.js check that --grep flag run tests by string pattern 'grep' with programmatic using mocha diff --git a/test/grep/index.js b/test/grep/index.js index 828ee3d..111133c 100755 --- a/test/grep/index.js +++ b/test/grep/index.js @@ -22,6 +22,5 @@ exec(libExecutable + ' -R json --grep grep test/grep/tests', { process.exit(1); } - assert.strictEqual(jsonReporterOutput.stats.passes, 3, 'Tests number is wrong. Expected 3. Actual: ' - + jsonReporterOutput.stats.passes); + assert.strictEqual(jsonReporterOutput.stats.passes, 3); }); diff --git a/test/grep/indexProgrammatic.js b/test/grep/indexProgrammatic.js new file mode 100755 index 0000000..53c3350 --- /dev/null +++ b/test/grep/indexProgrammatic.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node + +'use strict'; + +const assert = require('assert'); +const MochaParallelTests = require('../../dist/main/mocha').default; +const { setProcessExitListeners } = require('../../dist/util'); +const SilentReporter = require('../util/silent-reporter'); + +setProcessExitListeners(); + +const mocha = new MochaParallelTests; +mocha.addFile(`${__dirname}/tests/test.js`) + .addFile(`${__dirname}/tests/test1.js`) + .timeout(10000) + .grep('grep') + .reporter(SilentReporter); + +mocha.run().on('end', function () { + assert.strictEqual(this.stats.passes, 3); +}); diff --git a/test/index.sh b/test/index.sh index e8c74ab..0ed3f2c 100755 --- a/test/index.sh +++ b/test/index.sh @@ -77,6 +77,7 @@ test 'subprocess exits before sending an end message' test/no-subprocess-end/ind test 'unhandled rejections should not force subprocess to exit' test/q-promises/index.js test 'uncaught exceptions should not force subprocess to exit' test/uncaught-exception/index.js test 'grep option' test/grep/index.js +test 'grep option - programmatic API support' test/grep/indexProgrammatic.js echo "Passes: $PASSES Failes: $FAILES" echo ""