From 40239c1428f26fe72500d0259a36a86cac41b7fe Mon Sep 17 00:00:00 2001
From: George Sapkin <george.sapkin@gmail.com>
Date: Sun, 29 Apr 2018 11:39:43 +0200
Subject: [PATCH 1/3] Add package name to NotifyReporter notification

---
 CHANGELOG.md                                  |  2 +-
 .../jest-cli/src/reporters/notify_reporter.js | 25 +++++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36003f385552..2444849c3109 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,9 +2,9 @@
 
 ### 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))
 
 ### Fixes
 
diff --git a/packages/jest-cli/src/reporters/notify_reporter.js b/packages/jest-cli/src/reporters/notify_reporter.js
index c35a6537f35c..1ada22641bce 100644
--- a/packages/jest-cli/src/reporters/notify_reporter.js
+++ b/packages/jest-cli/src/reporters/notify_reporter.js
@@ -41,6 +41,26 @@ export default class NotifyReporter extends BaseReporter {
     const success =
       result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0;
 
+    const firstContext = contexts.values().next();
+
+    const hasteFS =
+      firstContext && firstContext.value && firstContext.value.hasteFS;
+
+    let packageName;
+    if (hasteFS != null) {
+      // assuming root package.json is the first one
+      const [filePath] = hasteFS.matchFiles('package.json');
+
+      packageName =
+        filePath != null
+          ? hasteFS.getModuleName(filePath)
+          : this._globalConfig.rootDir;
+    } else {
+      packageName = this._globalConfig.rootDir;
+    }
+
+    packageName = packageName != null ? `${packageName} - ` : '';
+
     const notifyMode = this._globalConfig.notifyMode;
     const statusChanged =
       this._context.previousSuccess !== success || this._context.firstRun;
@@ -55,7 +75,7 @@ export default class NotifyReporter extends BaseReporter {
         (notifyMode === 'change' && statusChanged) ||
         (notifyMode === 'failure-change' && statusChanged))
     ) {
-      const title = util.format('%d%% Passed', 100);
+      const title = util.format('%s%d%% Passed', packageName, 100);
       const message = util.format(
         (isDarwin ? '\u2705 ' : '') + '%d tests passed',
         result.numPassedTests,
@@ -74,7 +94,8 @@ export default class NotifyReporter extends BaseReporter {
       const failed = result.numFailedTests / result.numTotalTests;
 
       const title = util.format(
-        '%d%% Failed',
+        '%s%d%% Failed',
+        packageName,
         Math.ceil(Number.isNaN(failed) ? 0 : failed * 100),
       );
       const message = util.format(

From 7411e9013ce7ee35104b742019cc135e108e80d2 Mon Sep 17 00:00:00 2001
From: George Sapkin <george.sapkin@gmail.com>
Date: Mon, 7 May 2018 02:19:22 +0200
Subject: [PATCH 2/3] Added basic NotifyReporter title tests

---
 .../notify_reporter.test.js.snap              | 218 ++++++++++++++++++
 .../src/__tests__/notify_reporter.test.js     | 100 +++++++-
 2 files changed, 310 insertions(+), 8 deletions(-)

diff --git a/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap b/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap
index 5235644f80da..eea891a82bef 100644
--- a/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap
+++ b/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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",
+  },
+]
+`;
diff --git a/packages/jest-cli/src/__tests__/notify_reporter.test.js b/packages/jest-cli/src/__tests__/notify_reporter.test.js
index cc9f0baeeb99..ebb30f54bb30 100644
--- a/packages/jest-cli/src/__tests__/notify_reporter.test.js
+++ b/packages/jest-cli/src/__tests__/notify_reporter.test.js
@@ -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;
@@ -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();
@@ -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(() => {

From 4fac2249c0e3981d215d8c1a037c7c1ca1309bff Mon Sep 17 00:00:00 2001
From: George Sapkin <george.sapkin@gmail.com>
Date: Thu, 9 Aug 2018 11:30:07 +0200
Subject: [PATCH 3/3] Fixed rebasing error

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2444849c3109..4cd3a05337eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 - `[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))
 
 ### Fixes