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

Add projectConfig argument to shouldRunTestSuite hook #6350

Merged
merged 2 commits into from
May 30, 2018

Conversation

rogeliog
Copy link
Contributor

Summary

Currently, the shouldRunTestSuite hook only takes the testPath. I did that intentionally when designing plugins to keep the API surface as small as possible, but it seems that getting the ProjectConfig, along with the testPath might be useful.

Another idea was to pass the whole test: Test object, which seems really nice but I'm worried that it will leak out a lot of implementation details, for example context.moduleMap and context.hasteFS... The only other option inside test that would be interesting to get, is duration.

This should allow us to do something like a project selection plugin.
select-projects

@@ -61,11 +61,11 @@ class JestHooks {
this._listeners.onTestRunComplete.forEach(listener =>
listener(results),
),
shouldRunTestSuite: async testPath =>
shouldRunTestSuite: async (testPath, config) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option for this would be to change the signature to ({ testPath, config }) => {}, which might be better for future API changes, given that adding keys to that object would not be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although this would mean an initial breaking change, which should probably only affect jest-watch-typeahead

Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope people will understand it's still getting in shape ;)

Copy link
Member

Choose a reason for hiding this comment

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

We can call it out in the blog post as still somewhat experimental?

@@ -58,7 +58,9 @@ const getTestPaths = async (
}

const shouldTestArray = await Promise.all(
data.tests.map(test => jestHooks.shouldRunTestSuite(test.path)),
data.tests.map(test =>
jestHooks.shouldRunTestSuite(test.path, test.context.config),
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about passing a stripped information about test, e.g. ({path, duration, config})

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that seems like the best idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although duration is not always present, right?

@@ -58,7 +58,9 @@ const getTestPaths = async (
}

const shouldTestArray = await Promise.all(
data.tests.map(test => jestHooks.shouldRunTestSuite(test.path)),
data.tests.map(test =>
jestHooks.shouldRunTestSuite(test.path, test.context.config),
Copy link
Member

Choose a reason for hiding this comment

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

+1

shouldRunTestSuite: (testPath: string) => Promise<boolean>,
shouldRunTestSuite: (
testPath: string,
config: ProjectConfig,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, from the discussion above I could see the type here being TestSuiteConfig which is some subset of Test

jestHooks.shouldRunTestSuite({
config: test.context.config,
duration: test.duration,
testPath: test.path,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(testPath vs path) and (config vs projectConfig):

I like testPath and config better, but I'm fine with anything

@codecov-io
Copy link

Codecov Report

Merging #6350 into master will not change coverage.
The diff coverage is 50%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6350   +/-   ##
=======================================
  Coverage   63.63%   63.63%           
=======================================
  Files         226      226           
  Lines        8648     8648           
  Branches        4        4           
=======================================
  Hits         5503     5503           
  Misses       3144     3144           
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-watch/src/jest_hooks.js 76.47% <0%> (ø) ⬆️
packages/jest-cli/src/run_jest.js 69.41% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2307643...a0e47a8. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Changelog? :D

@rogeliog
Copy link
Contributor Author

Yes 🤦‍♂️ , I’ll add it when I wake up tomorrow morning, because I’m not in my computer right now

@SimenB
Copy link
Member

SimenB commented May 30, 2018

Haha, timezones are weird. I'm on the bus on my way to work

@cpojer cpojer merged commit 126858b into jestjs:master May 30, 2018
@cpojer
Copy link
Member

cpojer commented May 30, 2018

I'll let you send a new PR with the changelog entry pls! #movefast

rogeliog added a commit to rogeliog/jest that referenced this pull request May 30, 2018
rogeliog added a commit to rogeliog/jest that referenced this pull request May 30, 2018
@rogeliog
Copy link
Contributor Author

@cpojer thanks, here is the PR for the changelog entry #6355

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants