-
-
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.
* Enable configurable retries for failed test cases * Update tests * Remove testRetries CLI and config option. Add as jest.retryTimes with reporter integration. * Add jest.retryTimes to CHANGELOG.md and JestObjectAPI.md * Prettier fix on snapshot test * Update runJest to support jest-circus environment override * Update docs and use skipSuiteOnJasmine * Update retryTimes tests * Remove useJestCircus boolean on runTest * Remove outdated comment. Revert runJest environment override logic. * Removed outdated comment from test_retries test * Update snapshot tests * Update Jest Object docs for retryTimes. Use symbol for global lookup.
- Loading branch information
1 parent
efc79ba
commit 812dc12
Showing
16 changed files
with
217 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const runJest = require('../runJest'); | ||
|
||
const ConditionalTest = require('../../scripts/ConditionalTest'); | ||
|
||
ConditionalTest.skipSuiteOnJasmine(); | ||
|
||
describe('Test Retries', () => { | ||
const outputFileName = 'retries.result.json'; | ||
const outputFilePath = path.join( | ||
process.cwd(), | ||
'e2e/test-retries/', | ||
outputFileName, | ||
); | ||
|
||
afterAll(() => { | ||
fs.unlinkSync(outputFilePath); | ||
}); | ||
|
||
it('retries failed tests if configured', () => { | ||
let jsonResult; | ||
|
||
const reporterConfig = { | ||
reporters: [ | ||
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}], | ||
], | ||
}; | ||
|
||
runJest('test-retries', [ | ||
'--config', | ||
JSON.stringify(reporterConfig), | ||
'retry.test.js', | ||
]); | ||
|
||
const testOutput = fs.readFileSync(outputFilePath, 'utf8'); | ||
|
||
try { | ||
jsonResult = JSON.parse(testOutput); | ||
} catch (err) { | ||
throw new Error( | ||
`Can't parse the JSON result from ${outputFileName}, ${err.toString()}`, | ||
); | ||
} | ||
|
||
expect(jsonResult.numPassedTests).toBe(0); | ||
expect(jsonResult.numFailedTests).toBe(1); | ||
expect(jsonResult.numPendingTests).toBe(0); | ||
expect(jsonResult.testResults[0].testResults[0].invocations).toBe(4); | ||
}); | ||
|
||
it('does not retry by default', () => { | ||
let jsonResult; | ||
|
||
const reporterConfig = { | ||
reporters: [ | ||
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}], | ||
], | ||
}; | ||
|
||
runJest('test-retries', [ | ||
'--config', | ||
JSON.stringify(reporterConfig), | ||
'control.test.js', | ||
]); | ||
|
||
const testOutput = fs.readFileSync(outputFilePath, 'utf8'); | ||
|
||
try { | ||
jsonResult = JSON.parse(testOutput); | ||
} catch (err) { | ||
throw new Error( | ||
`Can't parse the JSON result from ${outputFileName}, ${err.toString()}`, | ||
); | ||
} | ||
|
||
expect(jsonResult.numPassedTests).toBe(0); | ||
expect(jsonResult.numFailedTests).toBe(1); | ||
expect(jsonResult.numPendingTests).toBe(0); | ||
expect(jsonResult.testResults[0].testResults[0].invocations).toBe(1); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 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'; | ||
|
||
it('retryTimes not set', () => { | ||
expect(true).toBeFalsy(); | ||
}); |
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,13 @@ | ||
/** | ||
* 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'; | ||
|
||
jest.retryTimes(3); | ||
|
||
it('retryTimes set', () => { | ||
expect(true).toBeFalsy(); | ||
}); |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
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,30 @@ | ||
/** | ||
* 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'; | ||
|
||
const fs = require('fs'); | ||
|
||
/** | ||
* RetryReporter | ||
* Reporter for testing output of onRunComplete | ||
*/ | ||
class RetryReporter { | ||
constructor(globalConfig, options) { | ||
this._options = options; | ||
} | ||
|
||
onRunComplete(contexts, results) { | ||
if (this._options.output) { | ||
fs.writeFileSync(this._options.output, JSON.stringify(results, null, 2), { | ||
encoding: 'utf8', | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = RetryReporter; |
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
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
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