Skip to content
New issue

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

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

Already on GitHub? # to your account

Support return array #22

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/node_modules
build
build
integrationTests/__fixtures__
generator/fixtures
26 changes: 23 additions & 3 deletions lib/createJestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@ const createRunner = (runPath, { getExtraOptions } = {}) => {
return runner(baseOptions);
});
})
.then(result => onResult(test, result))
.then(testResult => {
if (Array.isArray(testResult)) {
testResult.forEach(result =>
result.numFailingTests > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do an if rather than the ternary?

Copy link
Author

@tunnckoCore tunnckoCore Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, soon maybe cuz I'm not active in the past year.

? onFailure(test, new Error(result.errorMessage))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? I thought onResult was called with all test results regardless of whether the result is a failure or not, and onFailure was called if the test framework errored out. That might be wrong though, I haven't looked into the source code of this module for some time 😅

Could you show an example of how this is used in a runner and how it looks when used in Jest?

Copy link

@KaiSpencer KaiSpencer Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, onFailure is when the framework errors out. It is passed a SerializableError

I am working on this jest-python. It would be good to see if it was at all possible to simplify its implementation with this library.

: onResult(test, result),
);
return;
}
onResult(test, testResult);
})
.catch(err => onFailure(test, err)),
),
Promise.resolve(),
Expand Down Expand Up @@ -142,8 +152,18 @@ const createRunner = (runPath, { getExtraOptions } = {}) => {
const runAllTests = Promise.all(
tests.map(test =>
runTestInWorker(test)
.then(testResult => onResult(test, testResult))
.catch(error => onError(error, test)),
.then(testResult => {
if (Array.isArray(testResult)) {
testResult.forEach(result =>
result.numFailingTests > 0
? onError(new Error(result.errorMessage), test)
: onResult(test, result),
);
return;
}
onResult(test, testResult);
})
.catch(err => onError(err, test)),
),
);

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"generator/"
],
"scripts": {
"test": "jest",
"lint": "eslint .",
"pre-commit": "yarn test && yarn lint",
"pretest": "yarn build",
"test": "jest --no-colors",
"lint": "eslint . --fix",
"watch": "babel lib -w --ignore **/*.test.js,integration -d build",
"build": "babel lib --ignore **/*.test.js,integration -d build",
"prepublish": "yarn build",
"prepublishOnly": "yarn pre-commit",
"format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
},
"dependencies": {
Expand Down