Skip to content

refactor: Simplify test-runner logic #196

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

Merged
merged 5 commits into from
Feb 3, 2021
Merged

Conversation

pmdartus
Copy link
Member

This PR is an attempt to simplify the test runner logic:

  • Use the same code path for both standards and debug run. There hasn't been any signal from the jest team to expose a Node.js API for Jest. Spawning a new process is the most reliable approach to invoke Jest.
  • Use a pass-through instead of a disallow list for known options. This avoids having to update the disallow list every time a new option is added to the CLI.

Fixes #36

@pmdartus
Copy link
Member Author

@trevor-bliss The entire test suite has to be rebuilt reworked after this change. Before I do this I would like to get your feeling on this change.

Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

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

Added a few suggestions but looks great overall!

function getJestArgs(argv) {
// Extract known options from parsed arguments
const knownOptions = Object.keys(argv)
.filter((key) => argv[key] && JEST_PASSTHROUGH_OPTIONS.has(key))
Copy link
Member

Choose a reason for hiding this comment

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

Looking through this repository, it doesn't look like we have any logic that requires explicit default values of false for boolean arguments so I think we can remove the defaults from the configuration in this file. That would make this code more robust since it wouldn't need to change if we ever introduce new non-boolean arguments with truthy values.

Otherwise, my second preference would be to change this to:

Suggested change
.filter((key) => argv[key] && JEST_PASSTHROUGH_OPTIONS.has(key))
.filter((key) => argv[key] !== false && JEST_PASSTHROUGH_OPTIONS.has(key))

Copy link
Contributor

@trevor-bliss trevor-bliss left a comment

Choose a reason for hiding this comment

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

This is great. Tried it out locally against lwc-recipe and things look like they're running normally.

@pmdartus pmdartus requested a review from trevor-bliss February 2, 2021 16:34
@pmdartus
Copy link
Member Author

pmdartus commented Feb 2, 2021

@trevor-bliss Do you mind doing another round of review now I have reworked the test suite?

@@ -16,7 +16,7 @@
},
"scripts": {
"check-license-headers": "node ./scripts/checkLicenseHeaders.js",
"lint": "eslint src/",
"lint": "eslint src/ tests/",
Copy link
Member Author

Choose a reason for hiding this comment

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

Test files were not linted before.


process.on('unhandledRejection', reason => {
runJest(args)
Copy link
Member Author

Choose a reason for hiding this comment

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

Delegating all the process.exit handling to the bin file instead of having this all around the code base.

});
});
};
const promiseExec = promisify(exec);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a beautiful help in Node.js for doing this =)

Copy link
Contributor

@trevor-bliss trevor-bliss left a comment

Choose a reason for hiding this comment

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

:shipit:

@pmdartus pmdartus merged commit 082c407 into master Feb 3, 2021
@pmdartus pmdartus deleted the pmdartus/simplify-exec branch February 3, 2021 10:18
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 this pull request may close these issues.

Parity between debug and non-debug execution of Jest
4 participants