Merge pull request #2904 from xmbhasin/mocha-grep

Add --grep flag to gulp test
This commit is contained in:
Jason Poon 2018-07-28 09:03:04 -07:00 committed by GitHub
commit 1e1e8b0533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View File

@ -45,9 +45,10 @@ When submitting a PR, please fill out the template that is presented by GitHub w
# Or run tests by selecting the appropriate drop down option
# Alternatively, build and run tests through gulp and npm scripts
gulp build # build
npm test # test
gulp test # run tests inside Docker container
gulp build # build
npm test # test
gulp test # run tests inside Docker container
gulp test --grep testSuite # run only tests/suites filtered by js regex inside container
```
## Code Architecture

View File

@ -178,6 +178,13 @@ gulp.task('forceprettier', function(done) {
// test
gulp.task('test', function(done) {
// the flag --grep takes js regex as a string and filters by test and test suite names
var knownOptions = {
string: 'grep',
default: { grep: '' },
};
var options = minimist(process.argv.slice(2), knownOptions);
var spawn = require('child_process').spawn;
const dockerTag = 'vscodevim';
@ -200,8 +207,17 @@ gulp.task('test', function(done) {
);
}
const dockerRunArgs = [
'run',
'-it',
'--env',
`MOCHA_GREP=${options.grep}`,
'-v',
process.cwd() + ':/app',
dockerTag,
];
console.log('Running tests inside container...');
var dockerRunCmd = spawn('docker', ['run', '-it', '-v', process.cwd() + ':/app', dockerTag], {
var dockerRunCmd = spawn('docker', dockerRunArgs, {
cwd: process.cwd(),
stdio: 'inherit',
});

View File

@ -17,10 +17,15 @@ Globals.mockConfiguration = new Configuration();
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
var testRunner = require('vscode/lib/testrunner');
testRunner.configure({
// create new RegExp to catch errors early, ie before passing it to mocha
const mochaGrep = new RegExp(process.env.MOCHA_GREP || '');
const testRunnerConfiguration: MochaSetupOptions = {
ui: 'tdd',
useColors: true,
timeout: 10000,
});
grep: mochaGrep,
};
testRunner.configure(testRunnerConfiguration);
module.exports = testRunner;