2021-06-15 19:51:25 +02:00
|
|
|
const path = require('path');
|
|
|
|
const { promises: fs } = require('fs');
|
|
|
|
const yargs = require('yargs/yargs');
|
|
|
|
const { hideBin } = require('yargs/helpers');
|
|
|
|
const { runInShell } = require('../../development/lib/run-command');
|
|
|
|
const { exitWithError } = require('../../development/lib/exit-with-error');
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const { argv } = yargs(hideBin(process.argv))
|
|
|
|
.usage(
|
|
|
|
'$0 [options]',
|
|
|
|
'Run all E2E tests, with a variable number of retries.',
|
|
|
|
(_yargs) =>
|
|
|
|
_yargs
|
|
|
|
.option('browser', {
|
|
|
|
description: `Set the browser used; either 'chrome' or 'firefox'.`,
|
|
|
|
type: 'string',
|
|
|
|
choices: ['chrome', 'firefox'],
|
|
|
|
})
|
2022-03-10 23:01:55 +01:00
|
|
|
.option('snaps', {
|
|
|
|
description: `run snaps e2e tests`,
|
|
|
|
type: 'boolean',
|
|
|
|
})
|
2021-06-15 19:51:25 +02:00
|
|
|
.option('retries', {
|
|
|
|
description:
|
|
|
|
'Set how many times the test should be retried upon failure.',
|
|
|
|
type: 'number',
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.strict()
|
|
|
|
.help('help');
|
|
|
|
|
2022-03-10 23:01:55 +01:00
|
|
|
const { browser, retries, snaps } = argv;
|
|
|
|
|
|
|
|
let testDir = path.join(__dirname, 'tests');
|
2021-06-15 19:51:25 +02:00
|
|
|
|
2022-03-10 23:01:55 +01:00
|
|
|
if (snaps) {
|
|
|
|
testDir = path.join(__dirname, 'snaps');
|
|
|
|
}
|
2021-06-15 19:51:25 +02:00
|
|
|
|
|
|
|
const testFilenames = await fs.readdir(testDir);
|
|
|
|
const testPaths = testFilenames.map((filename) =>
|
|
|
|
path.join(testDir, filename),
|
|
|
|
);
|
2022-03-10 23:01:55 +01:00
|
|
|
|
|
|
|
if (!snaps) {
|
|
|
|
testPaths.push(path.join(__dirname, 'metamask-ui.spec.js'));
|
|
|
|
}
|
2021-06-15 19:51:25 +02:00
|
|
|
|
|
|
|
const runE2eTestPath = path.join(__dirname, 'run-e2e-test.js');
|
|
|
|
|
|
|
|
const args = [runE2eTestPath];
|
|
|
|
if (browser) {
|
|
|
|
args.push('--browser', browser);
|
|
|
|
}
|
|
|
|
if (retries) {
|
|
|
|
args.push('--retries', retries);
|
|
|
|
}
|
|
|
|
|
2022-03-10 23:01:55 +01:00
|
|
|
for (const testPath of testPaths) {
|
2021-06-15 19:51:25 +02:00
|
|
|
await runInShell('node', [...args, testPath]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
exitWithError(error);
|
|
|
|
});
|