Skip to content

Commit

Permalink
PR Feedback: Conver to use Sets
Browse files Browse the repository at this point in the history
  • Loading branch information
hswolff committed Dec 27, 2017
1 parent 29558a9 commit f8a5439
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
19 changes: 11 additions & 8 deletions src/runMocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ const runMocha = ({ config, testPath, globalConfig }, workerCallback) => {
class Reporter extends Mocha.reporters.Base {
constructor(runner) {
super(runner);
const tests = [];
const pending = [];
const failures = [];
const passes = [];
const tests = new Set();
const pending = new Set();
const failures = new Set();
const passes = new Set();

runner.on('test end', test => tests.push(test));
runner.on('pass', test => passes.push(test));
runner.on('test end', test => tests.add(test));
runner.on('pass', test => passes.add(test));
runner.on('fail', (test, err) => {
test.err = err;
failures.push(test);
failures.add(test);

// Ensure we include failing tests in our final set of tests.
tests.add(test);
});
runner.on('pending', test => pending.push(test));
runner.on('pending', test => pending.add(test));
runner.on('end', () => {
try {
workerCallback(
Expand Down
17 changes: 4 additions & 13 deletions src/utils/toTestResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@ const getFailureMessages = tests => {
return failureMessages.length ? failureMessages : null;
};

const toTestResult = ({ stats, tests, failures, jestTestPath, coverage }) => {
const effectiveTests = tests;

// Merge failed tests that don't exist in the tests array so that we report
// all tests even if an error occurs in a beforeEach block.
failures.forEach(test => {
if (!tests.some(t => t === test)) {
tests.push(test);
}
});

const toTestResult = ({ stats, tests: testsSet, jestTestPath, coverage }) => {
const tests = Array.from(testsSet);
return {
coverage,
console: null,
failureMessage: getFailureMessages(effectiveTests),
failureMessage: getFailureMessages(tests),
numFailingTests: stats.failures,
numPassingTests: stats.passes,
numPendingTests: stats.pending,
Expand All @@ -47,7 +38,7 @@ const toTestResult = ({ stats, tests, failures, jestTestPath, coverage }) => {
sourceMaps: {},
testExecError: null,
testFilePath: jestTestPath,
testResults: effectiveTests.map(test => {
testResults: tests.map(test => {
return {
ancestorTitles: [],
duration: test.duration / 1000,
Expand Down

0 comments on commit f8a5439

Please sign in to comment.