playwright/test/mocha/index.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-08-10 20:10:39 -07:00
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const builtinReporters = require('mocha/lib/reporters');
2020-08-10 20:10:39 -07:00
const fs = require('fs');
const path = require('path');
const program = require('commander');
const { Runner } = require('./runner');
const DotRunner = require('./dotReporter');
2020-08-10 20:10:39 -07:00
program
.version('Version ' + require('../../package.json').version)
.option('--reporter <reporter>', 'reporter to use', '')
.option('--max-workers <maxWorkers>', 'reporter to use', '')
.action(async (command, args) => {
const testDir = path.join(process.cwd(), 'test');
const files = [];
for (const name of fs.readdirSync(testDir)) {
if (!name.includes('.spec.'))
continue;
if (!command.args.length) {
files.push(path.join(testDir, name));
continue;
}
for (const filter of command.args) {
if (name.includes(filter)) {
files.push(path.join(testDir, name));
break;
}
}
}
2020-08-10 20:10:39 -07:00
const runner = new Runner({
reporter: command.reporter ? builtinReporters[command.reporter] : DotRunner,
maxWorkers: command.maxWorkers || Math.ceil(require('os').cpus().length / 2)
});
await runner.run(files);
await runner.stop();
});
2020-08-10 20:10:39 -07:00
program.parse(process.argv);