Skip to content

Commit

Permalink
Fix message when changedSince is being used (#7028)
Browse files Browse the repository at this point in the history
Fixes #7026
  • Loading branch information
Alcedo Nathaniel De Guzman Jr authored and SimenB committed Sep 23, 2018
1 parent 0418cab commit df78b49
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
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))

### 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]+))./;
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

0 comments on commit df78b49

Please sign in to comment.