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

Add package name to NotifyReporter notification #5898

Merged
merged 3 commits into from
Aug 9, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- `[jest-cli]` Add package name to `NotifyReporter` notification ([#5898](https://github.com/facebook/jest/pull/5898))
- `[jest-runner]` print stack trace when `process.exit` is called from user code ([#6714](https://github.com/facebook/jest/pull/6714))
- `[jest-each]` introduces `%#` option to add index of the test to its title ([#6414](https://github.com/facebook/jest/pull/6414))
- `[pretty-format]` Support serializing `DocumentFragment` ([#6705](https://github.com/facebook/jest/pull/6705))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,64 @@ Array [
]
`;

exports[`test always with moduleName 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
]
`;

exports[`test always with rootDir 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
]
`;

exports[`test change 1`] = `
Array [
Object {
Expand All @@ -46,6 +104,40 @@ Array [
]
`;

exports[`test change with moduleName 1`] = `
Array [
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
]
`;

exports[`test change with rootDir 1`] = `
Array [
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
]
`;

exports[`test failure-change 1`] = `
Array [
Object {
Expand All @@ -67,6 +159,48 @@ Array [
]
`;

exports[`test failure-change with moduleName 1`] = `
Array [
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
]
`;

exports[`test failure-change with rootDir 1`] = `
Array [
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
]
`;

exports[`test success 1`] = `
Array [
Object {
Expand All @@ -84,6 +218,40 @@ Array [
]
`;

exports[`test success with moduleName 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
]
`;

exports[`test success with rootDir 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
]
`;

exports[`test success-change 1`] = `
Array [
Object {
Expand All @@ -108,3 +276,53 @@ Array [
},
]
`;

exports[`test success-change with moduleName 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-module - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-module - 100% Failed",
},
]
`;

exports[`test success-change with rootDir 1`] = `
Array [
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 tests passed",
"title": "some-test - 100% Passed",
},
Object {
"message": "3 of 3 tests failed",
"title": "some-test - 100% Failed",
},
]
`;
100 changes: 92 additions & 8 deletions packages/jest-cli/src/__tests__/notify_reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('.addReporter() .removeReporter()', () => {
expect(scheduler._dispatcher._reporters).not.toContain(reporter);
});

const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
const testModes = ({notifyMode, arl, rootDir, moduleName}) => {
const notify = require('node-notifier');

let previousContext = initialContext;
Expand All @@ -91,12 +91,28 @@ const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
previousSuccess: previousContext.previousSuccess,
});
const reporter = new NotifyReporter(
{notify: true, notifyMode},
{notify: true, notifyMode, rootDir},
{},
newContext,
);
previousContext = newContext;
reporter.onRunComplete(new Set(), ar);
const contexts = new Set();

if (moduleName != null) {
contexts.add({
hasteFS: {
getModuleName() {
return moduleName;
},

matchFiles() {
return ['package.json'];
},
},
});
}

reporter.onRunComplete(contexts, ar);

if (ar.numTotalTests === 0) {
expect(notify.notify).not.toHaveBeenCalled();
Expand All @@ -112,23 +128,91 @@ const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
};

test('test always', () => {
testModes('always', notifyEvents);
testModes({arl: notifyEvents, notifyMode: 'always'});
});

test('test success', () => {
testModes('success', notifyEvents);
testModes({arl: notifyEvents, notifyMode: 'success'});
});

test('test change', () => {
testModes('change', notifyEvents);
testModes({arl: notifyEvents, notifyMode: 'change'});
});

test('test success-change', () => {
testModes('success-change', notifyEvents);
testModes({arl: notifyEvents, notifyMode: 'success-change'});
});

test('test failure-change', () => {
testModes('failure-change', notifyEvents);
testModes({arl: notifyEvents, notifyMode: 'failure-change'});
});

test('test always with rootDir', () => {
testModes({arl: notifyEvents, notifyMode: 'always', rootDir: 'some-test'});
});

test('test success with rootDir', () => {
testModes({arl: notifyEvents, notifyMode: 'success', rootDir: 'some-test'});
});

test('test change with rootDir', () => {
testModes({arl: notifyEvents, notifyMode: 'change', rootDir: 'some-test'});
});

test('test success-change with rootDir', () => {
testModes({
arl: notifyEvents,
notifyMode: 'success-change',
rootDir: 'some-test',
});
});

test('test failure-change with rootDir', () => {
testModes({
arl: notifyEvents,
notifyMode: 'failure-change',
rootDir: 'some-test',
});
});

test('test always with moduleName', () => {
testModes({
arl: notifyEvents,
moduleName: 'some-module',
notifyMode: 'always',
});
});

test('test success with moduleName', () => {
testModes({
arl: notifyEvents,
moduleName: 'some-module',
notifyMode: 'success',
});
});

test('test change with moduleName', () => {
testModes({
arl: notifyEvents,
moduleName: 'some-module',
notifyMode: 'change',
});
});

test('test success-change with moduleName', () => {
testModes({
arl: notifyEvents,
moduleName: 'some-module',
notifyMode: 'success-change',
});
});

test('test failure-change with moduleName', () => {
testModes({
arl: notifyEvents,
moduleName: 'some-module',
notifyMode: 'failure-change',
});
});

afterEach(() => {
Expand Down
Loading