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

Fix message when changedSince is being used #7028

Merged
merged 5 commits into from
Sep 23, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661))
- `[jest-haste-map]` Add `getFileIterator` to `HasteFS` for faster file iteration ([#7010](https://github.com/facebook/jest/pull/7010)).
- `[jest-worker]` [**BREAKING**] Add functionality to call a `setup` method in the worker before the first call and a `teardown` method when ending the farm ([#7014](https://github.com/facebook/jest/pull/7014)).
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `faluire-change` ([#7024](https://github.com/facebook/jest/pull/7024))
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `failure-change` ([#7024](https://github.com/facebook/jest/pull/7024))
Copy link
Member

Choose a reason for hiding this comment

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

😅


### Fixes

Expand All @@ -15,6 +15,7 @@
- `[jest-haste-map]` Fixed Haste whitelist generation for scoped modules on Windows ([#6980](https://github.com/facebook/jest/pull/6980))
- `[jest-mock]` Fix inheritance of static properties and methods in mocks ([#7003](https://github.com/facebook/jest/pull/7003))
- `[jest-mock]` Fix mocking objects without `Object.prototype` in their prototype chain ([#7003](https://github.com/facebook/jest/pull/7003))
- `[jest-cli]` Update jest-cli to show git ref in message when using `changedSince` ([#7028](https://github.com/facebook/jest/pull/7028))

### Chore & Maintenance

Expand Down
23 changes: 23 additions & 0 deletions e2e/__tests__/only_changed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ const HG = 'hg --config ui.username=jest_test';
beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

test('run for "onlyChanged" and "changedSince"', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
'file1.js': 'module.exports = {}',
'package.json': '{}',
});

run(`${GIT} init`, DIR);
run(`${GIT} add .`, DIR);
run(`${GIT} commit -m "first"`, DIR);

let stdout = runJest(DIR, ['-o']).stdout;
expect(stdout).toMatch(
/No tests found related to files changed since last commit./,
);

stdout = runJest(DIR, ['--changedSince=master']).stdout;
expect(stdout).toMatch(
/No tests found related to files changed since "master"./,
);
});

test('run only changed files', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-cli/src/getNoTestFoundRelatedToChangedFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import chalk from 'chalk';
import {isInteractive} from 'jest-util';

export default function getNoTestFoundRelatedToChangedFiles(globalConfig) {
let msg = chalk.bold(
'No tests found related to files changed since last commit.',
);
const ref = globalConfig.changedSince
? `"${globalConfig.changedSince}"`
: 'last commit';
let msg = chalk.bold(`No tests found related to files changed since ${ref}.`);

if (isInteractive) {
msg += chalk.dim(
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-editor-support/src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export default class Runner extends EventEmitter {

findMessageType(buf: Buffer): MessageType {
const str = buf.toString('utf8', 0, 58);
if (str === 'No tests found related to files changed since last commit.') {
const lastCommitRegex = /No tests found related to files changed since ((last commit)|([a-z0-9]+))./;
Copy link
Author

@natealcedo natealcedo Sep 23, 2018

Choose a reason for hiding this comment

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

@SimenB I just realised that this regular expression should include the quotation marks. The reason why the tests passed was because the tests were wrong. Going to make a new PR to fix this.

Edit: #7029 should fix this small issue.

if (lastCommitRegex.test(str)) {
return messageTypes.noTests;
}

if (/^\s*Watch Usage\b/.test(str)) {
return messageTypes.watchUsage;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/jest-editor-support/src/__tests__/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,16 @@ describe('events', () => {
expect(runner.prevMessageTypes).toEqual([messageTypes.noTests]);
});

it('should track when "No tests found related to files changed since master" is received', () => {
const data = Buffer.from(
'No tests found related to files changed since master.\n' +
'Press `a` to run all tests, or run Jest with `--watchAll`.',
);
fakeProcess.stderr.emit('data', data);

expect(runner.prevMessageTypes).toEqual([messageTypes.noTests]);
});

it('should clear the message type history when any other other data is received', () => {
const data = Buffer.from('');
fakeProcess.stderr.emit('data', data);
Expand All @@ -484,6 +494,14 @@ describe('events', () => {
expect(runner.findMessageType(buf)).toBe(messageTypes.noTests);
});

it('should identify "No tests found related to files changed since git ref."', () => {
const buf = Buffer.from(
'No tests found related to files changed since master.\n' +
'Press `a` to run all tests, or run Jest with `--watchAll`.',
);
expect(runner.findMessageType(buf)).toBe(messageTypes.noTests);
});

it('should identify the "Watch Usage" prompt', () => {
const buf = Buffer.from('\n\nWatch Usage\n...');
expect(runner.findMessageType(buf)).toBe(messageTypes.watchUsage);
Expand Down