+async function runTests(opts, framework_options, files, results, status_bar, showTestFailures) {
+ const tests_queue = [];
+
+ for (const testPath of files) {
+ const callback = runTest(testPath, framework_options)
+ .then(out => {
+ const [output, nb_failures] = out;
+ results[nb_failures === 0 ? "successful" : "failed"].push({
+ file_name: testPath,
+ output: output,
+ });
+ if (nb_failures === 0) {
+ status_bar.successful();
+ } else if (showTestFailures) {
+ status_bar.erroneous();
+ }
+ })
+ .catch(err => {
+ results.errored.push({
+ file_name: testPath,
+ output: err,
+ });
+ if (showTestFailures) {
+ status_bar.erroneous();
+ }
+ })
+ .finally(() => {
+ // We now remove the promise from the tests_queue.
+ tests_queue.splice(tests_queue.indexOf(callback), 1);
+ });
+ tests_queue.push(callback);
+ if (opts["jobs"] > 0 && tests_queue.length >= opts["jobs"]) {
+ await Promise.race(tests_queue);
+ }
+ }
+ if (tests_queue.length > 0) {
+ await Promise.all(tests_queue);
+ }
+}
+
+function createEmptyResults() {
+ return {
+ successful: [],
+ failed: [],
+ errored: [],
+ };
+}
+