-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor out the directory crawler from the test runner
- Loading branch information
Showing
5 changed files
with
32 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import fs from 'fs' | ||
import util from 'util' | ||
import path from 'path' | ||
|
||
const readdir = util.promisify(fs.readdir); | ||
|
||
export default function crawl(dir){ | ||
return readdir(dir) | ||
.then(files => files.map(file => path.resolve(dir, file))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
import fs from 'fs' | ||
import childProcess from 'child_process' | ||
import perfHooks from 'perf_hooks' | ||
import os from 'os' | ||
import batchPromise from './batch-promise.mjs' | ||
|
||
export default function run (testDirectory, report = () => {}) { | ||
export default function run (files, report = () => {}) { | ||
const timestamp = perfHooks.performance.now() | ||
let passed = 0 | ||
let failed = 0 | ||
|
||
return new Promise((resolve, reject) => { | ||
fs.readdir(testDirectory, (err, files) => { | ||
if (err) reject(err) | ||
return batchPromise(files, os.cpus().length, file => { | ||
return new Promise(resolve => { | ||
const forked = childProcess.fork(file) | ||
|
||
let passed = 0 | ||
let failed = 0 | ||
|
||
batchPromise(files, os.cpus().length, file => { | ||
return new Promise(resolve => { | ||
const forked = childProcess.fork(`${testDirectory}${file}`) | ||
|
||
forked.on('message', ({ didPass, title, location, message }) => { | ||
didPass ? passed++ : failed++ | ||
report({ didPass, title, location, message, timestamp, file, passed, failed, isComplete: false }) | ||
}) | ||
|
||
forked.on('close', () => resolve()) | ||
}) | ||
forked.on('message', ({ didPass, title, location, message }) => { | ||
didPass ? passed++ : failed++ | ||
report({ didPass, title, location, message, timestamp, file, passed, failed, isComplete: false }) | ||
}) | ||
.then(() => { | ||
report({ timestamp, passed, failed, isComplete: true }) | ||
resolve({ passed, failed }) | ||
}) | ||
.catch(err => reject(err)) | ||
|
||
forked.on('close', () => resolve()) | ||
}) | ||
}) | ||
.then(() => { | ||
report({ timestamp, passed, failed, isComplete: true }) | ||
return { passed, failed } | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters