-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
testPathPattern message test #4006
Merged
aaronabramov
merged 1 commit into
jestjs:master
from
aaronabramov:test_path_pattern_message_test
Jul 11, 2017
+44
−0
Merged
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions
44
integration_tests/__tests__/test_path_pattern_reporter_message.test.js
This file contains 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,44 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import runJest from '../runJest'; | ||
import {cleanup, writeFiles} from '../utils'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
const skipOnWindows = require('skipOnWindows'); | ||
const DIR = path.resolve(os.tmpdir(), 'jest_path_pattern_reporter_message'); | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
test('prints a message with path pattern at the end', () => { | ||
writeFiles(DIR, { | ||
'.watchmanconfig': '', | ||
'__tests__/a.test.js': `test('a', () => {});`, | ||
'__tests__/b.test.js': `test('b', () => {});`, | ||
'package.json': '{}', | ||
}); | ||
let stderr; | ||
|
||
({stderr} = runJest(DIR, ['a'])); | ||
expect(stderr).toMatch('Ran all test suites matching "a"'); | ||
|
||
({stderr} = runJest(DIR, ['a', 'b'])); | ||
expect(stderr).toMatch('Ran all test suites matching /a|b/'); | ||
|
||
({stderr} = runJest(DIR, ['--testPathPattern', 'a'])); | ||
expect(stderr).toMatch('Ran all test suites matching /a/'); | ||
|
||
({stderr} = runJest(DIR, ['--testPathPattern', 'a|b'])); | ||
expect(stderr).toMatch('Ran all test suites matching /a|b/'); | ||
}); |
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.
there is a lot of complexity around this case in the codebase.
We create a
testPathPattern
string and pass it all the way through the entire test flow toSummaryReporter
just so that we can print"a"
instead of/a/
, even though if we pass multiple parrterns we still print/a|b/
at the end.example:
but:
this complexity can be avoided if we always print the pattern (and not a string). This way we can just put
testPathPattern
intoglobalConfig
and remove it from everywhere else (run_jest.js, TestSelectionConfig, ReporterOptions, formatTestPathPattern, argv and a few other places).if we do this, the only change to this test will be this like, and it'll look like this:
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.
if we absolutely must print double quotes for single string arguments, i'd rather replace
/
at the end of the run.(
/a/ => "a'
, or `/matchers.test/ => "matchers.test").in my opinion id' rather see the actual pattern that was used to match the tests rather than the passed string (also the input string is pretty much a regexp)
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.
Maybe there was some idea behind this? But I like showing regex here. To be even more precise, we could change the message to:
Similar to what we do in watch mode.
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.
I think printing the exact regex that is run on all the paths is beneficial. Whatever you type on the terminal might not be what ends up inside of Jest as the regex, because of different terminals and expansions and the like. Showing what Jest does gives a hint to engineers when they are using Jest incorrectly.
If the way this is implemented isn't clean, then we can fix that, but it doesn't make sense to degrade the user experience to simplify the architecture of the code in an immaterial way.
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.
so by switching to showing the regexp instead of the original input we can simplify the design and improve the experience. which is win/win.
I'll merge this tests and update it to expect the regexp when i change the implementation.