-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implemented Watch mode filter by filename and by test name #1530 #3372
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
Open
mmulet
wants to merge
9
commits into
avajs:main
Choose a base branch
from
mmulet:Watch_mode_filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
78a3768
Implemented Watch mode filter by filename and by test name #1530
8ecd51d
fix tests on onlder node versions
0d78fd3
Format documentation
novemberborn b72a9dd
Add newline at EOF
novemberborn a3cce75
Fix error handling in watcher tests
novemberborn b0762b0
Remove unnecessary this.done() calls in catch blocks
novemberborn 5195cbe
Remove unnecessary multiline comments
novemberborn 16630d4
implemented fixes
0b88520
lint fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* The InteractiveFilter class is used to determine | ||
* if a test should be skipped using filters provided | ||
* by the user in watch mode. | ||
*/ | ||
export class InteractiveFilter { | ||
#filepathRegex = null; | ||
|
||
replaceFilepathRegex(filepathRegex) { | ||
const filterHasChanged = !this.#regexesAreEqual(this.#filepathRegex, filepathRegex); | ||
this.#filepathRegex = filepathRegex; | ||
return filterHasChanged; | ||
} | ||
|
||
#testTitleRegex = null; | ||
|
||
replaceTestTitleRegex(testTitleRegex) { | ||
const filterHasChanged = !this.#regexesAreEqual(this.#testTitleRegex, testTitleRegex); | ||
this.#testTitleRegex = testTitleRegex; | ||
return filterHasChanged; | ||
} | ||
|
||
#regexesAreEqual(a, b) { | ||
return a?.source === b?.source && a?.flags === b?.flags; | ||
} | ||
|
||
constructor(interactiveFilterData = undefined) { | ||
if (!interactiveFilterData) { | ||
return; | ||
} | ||
|
||
this.#filepathRegex = interactiveFilterData.filepathRegex; | ||
this.#testTitleRegex = interactiveFilterData.testTitleRegex; | ||
} | ||
|
||
getData() { | ||
return { | ||
filepathRegex: this.#filepathRegex, | ||
testTitleRegex: this.#testTitleRegex, | ||
}; | ||
} | ||
|
||
printFilePathRegex() { | ||
if (!this.#filepathRegex) { | ||
return ''; | ||
} | ||
|
||
return `Current filename filter is ${this.#filepathRegex}`; | ||
} | ||
|
||
printTestTitleRegex() { | ||
if (!this.#testTitleRegex) { | ||
return ''; | ||
} | ||
|
||
return `Current test title filter is ${this.#testTitleRegex}`; | ||
} | ||
|
||
shouldSkipThisFile(file) { | ||
if (this.#filepathRegex === null) { | ||
return false; | ||
} | ||
|
||
return !this.#filepathRegex.test(file); | ||
} | ||
|
||
canSelectTestsInThisFile(file) { | ||
return this.#filepathRegex?.test(file) ?? true; | ||
} | ||
|
||
shouldSelectTest(testTitle) { | ||
return this.#testTitleRegex?.test(testTitle) ?? true; | ||
} | ||
|
||
hasAnyFilters() { | ||
return this.#filepathRegex !== null || this.#testTitleRegex !== null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import {matcher} from 'matcher'; | |
|
||
import ContextRef from './context-ref.js'; | ||
import createChain from './create-chain.js'; | ||
import {InteractiveFilter} from './interactive-filter.js'; | ||
import parseTestArgs from './parse-test-args.js'; | ||
import serializeError from './serialize-error.js'; | ||
import {load as loadSnapshots, determineSnapshotDir} from './snapshot-manager.js'; | ||
|
@@ -29,6 +30,8 @@ export default class Runner extends Emittery { | |
this.serial = options.serial === true; | ||
this.snapshotDir = options.snapshotDir; | ||
this.updateSnapshots = options.updateSnapshots; | ||
this.interactiveFilter | ||
= new InteractiveFilter(options.interactiveFilterData); | ||
|
||
this.activeRunnables = new Set(); | ||
this.boundCompareTestSnapshot = this.compareTestSnapshot.bind(this); | ||
|
@@ -91,9 +94,12 @@ export default class Runner extends Emittery { | |
metadata.taskIndex = this.nextTaskIndex++; | ||
|
||
const {args, implementation, title} = parseTestArgs(testArgs); | ||
|
||
if (this.checkSelectedByLineNumbers) { | ||
metadata.selected = this.checkSelectedByLineNumbers(); | ||
if ( | ||
this.interactiveFilter.shouldSelectTest(title.value) | ||
) { | ||
metadata.selected = this.checkSelectedByLineNumbers ? this.checkSelectedByLineNumbers() : true; | ||
} else { | ||
metadata.selected = false; | ||
} | ||
|
||
if (metadata.todo) { | ||
|
@@ -181,6 +187,7 @@ export default class Runner extends Emittery { | |
serial: false, | ||
exclusive: false, | ||
skipped: false, | ||
selected: false, | ||
todo: false, | ||
failing: false, | ||
callback: false, | ||
|
@@ -254,8 +261,8 @@ export default class Runner extends Emittery { | |
await runnables.reduce((previous, runnable) => { // eslint-disable-line unicorn/no-array-reduce | ||
if (runnable.metadata.serial || this.serial) { | ||
waitForSerial = previous.then(() => | ||
// Serial runnables run as long as there was no previous failure, unless | ||
// the runnable should always be run. | ||
// Serial runnables run as long as there was no previous failure, unless | ||
// the runnable should always be run. | ||
(allPassed || runnable.metadata.always) && runAndStoreResult(runnable), | ||
); | ||
return waitForSerial; | ||
|
@@ -264,10 +271,10 @@ export default class Runner extends Emittery { | |
return Promise.all([ | ||
previous, | ||
waitForSerial.then(() => | ||
// Concurrent runnables are kicked off after the previous serial | ||
// runnables have completed, as long as there was no previous failure | ||
// (or if the runnable should always be run). One concurrent runnable's | ||
// failure does not prevent the next runnable from running. | ||
// Concurrent runnables are kicked off after the previous serial | ||
// runnables have completed, as long as there was no previous failure | ||
// (or if the runnable should always be run). One concurrent runnable's | ||
// failure does not prevent the next runnable from running. | ||
(allPassed || runnable.metadata.always) && runAndStoreResult(runnable), | ||
), | ||
]); | ||
|
@@ -402,7 +409,7 @@ export default class Runner extends Emittery { | |
return alwaysOk && hooksOk && testOk; | ||
} | ||
|
||
async start() { // eslint-disable-line complexity | ||
async start() { | ||
const concurrentTests = []; | ||
const serialTests = []; | ||
for (const task of this.tasks.serial) { | ||
|
@@ -411,7 +418,7 @@ export default class Runner extends Emittery { | |
continue; | ||
} | ||
|
||
if (this.checkSelectedByLineNumbers && !task.metadata.selected) { | ||
if (!task.metadata.selected) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I moved to metadata.selected rather than metadata.skipped, I had to delete the checks for All tests still pass, and it works fine. So, I am assuming that these checks are not needed. |
||
this.snapshots.skipBlock(task.title, task.metadata.taskIndex); | ||
continue; | ||
} | ||
|
@@ -437,7 +444,7 @@ export default class Runner extends Emittery { | |
continue; | ||
} | ||
|
||
if (this.checkSelectedByLineNumbers && !task.metadata.selected) { | ||
if (!task.metadata.selected) { | ||
this.snapshots.skipBlock(task.title, task.metadata.taskIndex); | ||
continue; | ||
} | ||
|
@@ -464,7 +471,7 @@ export default class Runner extends Emittery { | |
continue; | ||
} | ||
|
||
if (this.checkSelectedByLineNumbers && !task.metadata.selected) { | ||
if (!task.metadata.selected) { | ||
continue; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed like the best place to skip loading entire file if it was filtered out by the interactive filter, but would somewhere else be better?