Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support returning array of TestResult #20

Open
tunnckoCore opened this issue Sep 17, 2019 · 0 comments · May be fixed by #22
Open

Support returning array of TestResult #20

tunnckoCore opened this issue Sep 17, 2019 · 0 comments · May be fixed by #22

Comments

@tunnckoCore
Copy link

tunnckoCore commented Sep 17, 2019

The change is pretty small and useful.

The use case is that I have a runner that uses cosmiconfig to get some configuration, which also can be an array, so I basically return something like

Promise.all(
  configs.map((cfg) => {
    /* runner thing */
  })
)

Currently, we need to return an object only, something like

const results = await Promise.all(
  configs.map((cfg) => {
    /* runner thing */
  })
)

return results[0];

But this way it won't show/report in the terminal all the test results.

The only change needed is this:

const runAllTests = Promise.all(
tests.map(test =>
runTestInWorker(test)
.then(testResult => onResult(test, testResult))
.catch(error => onError(error, test)),
),
);

to something like

const runAllTests = Promise.all(
  tests.map(test =>
    runTestInWorker(test)
      .then(testResult => {
        if (Array.isArray(testResult)) {
          testResult.forEach(result =>
            result.errorMessage && result.stats.failures > 0
              ? onError(new Error(result.errorMessage), test)
              : onResult(test, result),
          );
          return;
        }
        onResult(test, testResult);
      })
      .catch(err => onError(err, test)),
  ),
);

Tested. It is working and shows all the tests.


$ jest -c jest.build.config.js
 PASS   build  @tunnckocore/utils/dist/main/index.js
 PASS   build  @tunnckocore/utils/dist/module/index.js
 PASS   build  @tunnckocore/execa/dist/main/index.js
 PASS   build  @tunnckocore/execa/dist/module/index.js

previously was showing only

 PASS   build  @tunnckocore/utils/dist/main/index.js
 PASS   build  @tunnckocore/execa/dist/main/index.js
tunnckoCore added a commit to tunnckoCore/create-jest-runner that referenced this issue Sep 17, 2019
Signed-off-by: Charlike Mike Reagent <[email protected]>
@tunnckoCore tunnckoCore linked a pull request Sep 17, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant