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

testPathPattern message test #4006

Merged
Merged
Changes from all commits
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
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"');
Copy link
Contributor Author

@aaronabramov aaronabramov Jul 10, 2017

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 to SummaryReporter 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:

 $> ./jest matchers.test
...
Ran all test suites matching "matchers.test".

but:

$> ./jest matchers.test matchers1.test
Ran all test suites matching /matchers.test|matchers1.test/.

this complexity can be avoided if we always print the pattern (and not a string). This way we can just put testPathPattern into globalConfig 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:

({stderr} = runJest(DIR, ['a']));
expect(stderr).toMatch('Ran all test suites matching /a/');

Copy link
Contributor Author

@aaronabramov aaronabramov Jul 10, 2017

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)

./jest (matcher|reporter)(\\.|\\-)test\.js
...
Ran all test suites matching "(matcher|reporter)(\.|\-)test.js". // this does not look right to me

Copy link
Collaborator

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:

Ran all test suites matching pattern /some.*regex/

Similar to what we do in watch mode.

Copy link
Member

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.

Copy link
Contributor Author

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.


({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/');
});