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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?

),
);

const filteredTests = data.tests.filter((test, i) => shouldTestArray[i]);
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-watch/src/jest_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Promise.all(
this._listeners.shouldRunTestSuite.map(listener =>
listener(testPath),
),
this._listeners.shouldRunTestSuite.map(listener => {
return listener(testPath, config);
}),
).then(result =>
result.every(shouldRunTestSuite => shouldRunTestSuite),
),
Expand Down
10 changes: 8 additions & 2 deletions types/JestHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export type JestHookExposedFS = {
};

export type FileChange = (fs: JestHookExposedFS) => void;
export type ShouldRunTestSuite = (testPath: string) => Promise<boolean>;
export type ShouldRunTestSuite = (
testPath: string,
config: ProjectConfig,
) => Promise<boolean>;
export type TestRunComplete = (results: AggregatedResult) => void;

export type JestHookSubscriber = {
Expand All @@ -27,5 +30,8 @@ export type JestHookSubscriber = {
export type JestHookEmitter = {
onFileChange: (fs: JestHookExposedFS) => void,
onTestRunComplete: (results: AggregatedResult) => void,
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

) => Promise<boolean>,
};
2 changes: 1 addition & 1 deletion website/versioned_docs/version-23.0/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MyWatchPlugin {

Below are the hooks available in Jest.

#### `jestHooks.shouldRunTestSuite(testPath)`
#### `jestHooks.shouldRunTestSuite(testPath, projectConfig)`

Returns a boolean (or `Promise<boolean>`) for handling asynchronous operations) to specify if a test should be run or not.

Expand Down