support --run argument as before, #90063
This commit is contained in:
parent
c196df9d3a
commit
03fb0b117f
1 changed files with 41 additions and 21 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
const fs = require('fs');
|
||||||
const events = require('events');
|
const events = require('events');
|
||||||
const mocha = require('mocha');
|
const mocha = require('mocha');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
@ -17,7 +18,8 @@ const playwright = require('playwright');
|
||||||
const defaultReporterName = process.platform === 'win32' ? 'list' : 'spec';
|
const defaultReporterName = process.platform === 'win32' ? 'list' : 'spec';
|
||||||
const optimist = require('optimist')
|
const optimist = require('optimist')
|
||||||
.describe('grep', 'only run tests matching <pattern>').alias('grep', 'g').alias('grep', 'f').string('grep')
|
.describe('grep', 'only run tests matching <pattern>').alias('grep', 'g').alias('grep', 'f').string('grep')
|
||||||
.describe('run', 'only run tests matching <file_pattern>').alias('run', 'glob').string('runGlob')
|
.describe('run', 'only run tests matching <relative_file_path>').string('run')
|
||||||
|
.describe('glob', 'only run tests matching <glob_pattern>').string('glob')
|
||||||
.describe('build', 'run with build output (out-build)').boolean('build')
|
.describe('build', 'run with build output (out-build)').boolean('build')
|
||||||
.describe('debug', 'do not run browsers headless').boolean('debug')
|
.describe('debug', 'do not run browsers headless').boolean('debug')
|
||||||
.describe('browser', 'browsers in which tests should run').string('browser').default('browser', ['chromium'])
|
.describe('browser', 'browsers in which tests should run').string('browser').default('browser', ['chromium'])
|
||||||
|
@ -59,35 +61,53 @@ const withReporter = (function () {
|
||||||
const outdir = argv.build ? 'out-build' : 'out';
|
const outdir = argv.build ? 'out-build' : 'out';
|
||||||
const out = path.join(__dirname, `../../../${outdir}`);
|
const out = path.join(__dirname, `../../../${outdir}`);
|
||||||
|
|
||||||
|
function ensureIsArray(a) {
|
||||||
|
return Array.isArray(a) ? a : [a];
|
||||||
|
}
|
||||||
|
|
||||||
const testModules = (async function () {
|
const testModules = (async function () {
|
||||||
|
|
||||||
const defaultGlob = '**/*.test.js';
|
|
||||||
const excludeGlob = '**/{node,electron-browser,electron-main}/**/*.test.js';
|
const excludeGlob = '**/{node,electron-browser,electron-main}/**/*.test.js';
|
||||||
const pattern = argv.glob || defaultGlob
|
let isDefaultModules = true;
|
||||||
|
let promise;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
if (argv.run) {
|
||||||
glob(pattern, { cwd: out }, (err, files) => {
|
// use file list (--run)
|
||||||
if (err) {
|
isDefaultModules = false;
|
||||||
reject(err);
|
promise = Promise.resolve(ensureIsArray(argv.run).map(file => {
|
||||||
return;
|
file = file.replace(/^src/, 'out');
|
||||||
}
|
file = file.replace(/\.ts$/, '.js');
|
||||||
|
return path.relative(out, file);
|
||||||
|
}));
|
||||||
|
|
||||||
const modules = [];
|
} else {
|
||||||
const badFiles = [];
|
// glob patterns (--glob)
|
||||||
|
const defaultGlob = '**/*.test.js';
|
||||||
|
const pattern = argv.glob || defaultGlob
|
||||||
|
isDefaultModules = argv.glob === defaultGlob;
|
||||||
|
|
||||||
for (let file of files) {
|
promise = new Promise((resolve, reject) => {
|
||||||
if (minimatch(file, excludeGlob)) {
|
glob(pattern, { cwd: out }, (err, files) => {
|
||||||
badFiles.push(file);
|
if (err) {
|
||||||
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
modules.push(file.replace(/\.js$/, ''));
|
resolve(files)
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
if (badFiles.length > 0 && pattern !== defaultGlob) {
|
|
||||||
console.warn(`DROPPED ${badFiles.length} files because '${pattern}' includes files from invalid layers.${badFiles.map(file => `\n\t-${file}`)}`);
|
|
||||||
}
|
|
||||||
resolve(modules);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then(files => {
|
||||||
|
const modules = [];
|
||||||
|
for (let file of files) {
|
||||||
|
if (!minimatch(file, excludeGlob)) {
|
||||||
|
modules.push(file.replace(/\.js$/, ''));
|
||||||
|
|
||||||
|
} else if (!isDefaultModules) {
|
||||||
|
console.warn(`DROPPONG ${file} because it cannot be run inside a browser`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modules;
|
||||||
})
|
})
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue