-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created --notifyMode option for notifications on certain events (#5125)
* added notifyMode flag to specify when a notification should display forgot about other notifyMode configs add notifyMode to normalize Created TestSchedulerContext to save previous status of test to make the change option work updated docs minor linting fix Added additional options such as success-change and failure-change Put conditions back in if else clauses Fixed documentation on notifyMode Added notify reporter test (for review) Finished NotifyReporter tests. Testing against simulated sequences of events. * hipsters and their emojis 😞 * icons might not show in some envs * Update CHANGELOG.md
- Loading branch information
1 parent
ad91d0a
commit 1947496
Showing
17 changed files
with
324 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test always 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test change 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test failure-change 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test success 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test success-change 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"message": "3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; |
119 changes: 119 additions & 0 deletions
119
packages/jest-cli/src/__tests__/notify_reporter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import TestScheduler from '../test_scheduler'; | ||
import NotifyReporter from '../reporters/notify_reporter'; | ||
import type {TestSchedulerContext} from '../test_scheduler'; | ||
import type {AggregatedResult} from '../../../../types/TestResult'; | ||
|
||
jest.mock('../reporters/default_reporter'); | ||
jest.mock('node-notifier', () => ({ | ||
notify: jest.fn(), | ||
})); | ||
|
||
const initialContext: TestSchedulerContext = { | ||
firstRun: true, | ||
previousSuccess: false, | ||
}; | ||
|
||
const aggregatedResultsSuccess: AggregatedResult = { | ||
numFailedTestSuites: 0, | ||
numFailedTests: 0, | ||
numPassedTestSuites: 1, | ||
numPassedTests: 3, | ||
numRuntimeErrorTestSuites: 0, | ||
numTotalTestSuites: 1, | ||
numTotalTests: 3, | ||
success: true, | ||
}; | ||
|
||
const aggregatedResultsFailure: AggregatedResult = { | ||
numFailedTestSuites: 1, | ||
numFailedTests: 3, | ||
numPassedTestSuites: 0, | ||
numPassedTests: 9, | ||
numRuntimeErrorTestSuites: 0, | ||
numTotalTestSuites: 1, | ||
numTotalTests: 3, | ||
success: false, | ||
}; | ||
|
||
// Simulated sequence of events for NotifyReporter | ||
const notifyEvents = [ | ||
aggregatedResultsSuccess, | ||
aggregatedResultsFailure, | ||
aggregatedResultsSuccess, | ||
aggregatedResultsSuccess, | ||
aggregatedResultsFailure, | ||
aggregatedResultsFailure, | ||
]; | ||
|
||
test('.addReporter() .removeReporter()', () => { | ||
const scheduler = new TestScheduler( | ||
{}, | ||
{}, | ||
Object.assign({}, initialContext), | ||
); | ||
const reporter = new NotifyReporter(); | ||
scheduler.addReporter(reporter); | ||
expect(scheduler._dispatcher._reporters).toContain(reporter); | ||
scheduler.removeReporter(NotifyReporter); | ||
expect(scheduler._dispatcher._reporters).not.toContain(reporter); | ||
}); | ||
|
||
const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => { | ||
const notify = require('node-notifier'); | ||
|
||
let previousContext = initialContext; | ||
arl.forEach((ar, i) => { | ||
const newContext = Object.assign(previousContext, { | ||
firstRun: i === 0, | ||
previousSuccess: previousContext.previousSuccess, | ||
}); | ||
const reporter = new NotifyReporter( | ||
{notify: true, notifyMode}, | ||
{}, | ||
newContext, | ||
); | ||
previousContext = newContext; | ||
reporter.onRunComplete(new Set(), ar); | ||
}); | ||
|
||
expect( | ||
notify.notify.mock.calls.map(([{message, title}]) => ({ | ||
message: message.replace('\u26D4\uFE0F ', '').replace('\u2705 ', ''), | ||
title, | ||
})), | ||
).toMatchSnapshot(); | ||
}; | ||
|
||
test('test always', () => { | ||
testModes('always', notifyEvents); | ||
}); | ||
|
||
test('test success', () => { | ||
testModes('success', notifyEvents); | ||
}); | ||
|
||
test('test change', () => { | ||
testModes('change', notifyEvents); | ||
}); | ||
|
||
test('test success-change', () => { | ||
testModes('success-change', notifyEvents); | ||
}); | ||
|
||
test('test failure-change', () => { | ||
testModes('failure-change', notifyEvents); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.