-
-
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.
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.
- Loading branch information
1 parent
a24204a
commit 42cd78c
Showing
17 changed files
with
350 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
141 changes: 141 additions & 0 deletions
141
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,141 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test always 1`] = ` | ||
Array [ | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test change 1`] = ` | ||
Array [ | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test failure-change 1`] = ` | ||
Array [ | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test success 1`] = ` | ||
Array [ | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`test success-change 1`] = ` | ||
Array [ | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "✅ 3 tests passed", | ||
"title": "100% Passed", | ||
}, | ||
Object { | ||
"icon": true, | ||
"message": "⛔️ 3 of 3 tests failed", | ||
"title": "100% Failed", | ||
}, | ||
] | ||
`; |
122 changes: 122 additions & 0 deletions
122
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,122 @@ | ||
/** | ||
* 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'; | ||
import type {Jest as jest} from '../../../../types/Jest'; | ||
|
||
const ICON_PATH = '/assets/jest_logo.png'; | ||
|
||
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, | ||
]; | ||
|
||
const iconShown = path => path.endsWith(ICON_PATH); | ||
|
||
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'); | ||
notify.notify.mock.calls = []; | ||
|
||
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(([{icon, message, title}]) => ({ | ||
icon: iconShown(icon), | ||
message, | ||
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); | ||
}); |
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.