-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Test retries #6498
Merged
Merged
Test retries #6498
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e99dd90
Enable configurable retries for failed test cases
palmerj3 b265a8b
Update tests
palmerj3 ee92c95
Remove testRetries CLI and config option. Add as jest.retryTimes with…
palmerj3 7d6f27b
Add jest.retryTimes to CHANGELOG.md and JestObjectAPI.md
palmerj3 38ba329
Prettier fix on snapshot test
palmerj3 262e34d
Update runJest to support jest-circus environment override
palmerj3 e9762af
Update docs and use skipSuiteOnJasmine
palmerj3 d1edc37
Update retryTimes tests
palmerj3 09fb974
Remove useJestCircus boolean on runTest
palmerj3 b346cc2
Remove outdated comment. Revert runJest environment override logic.
palmerj3 b9d65f8
Removed outdated comment from test_retries test
palmerj3 20667aa
Update snapshot tests
palmerj3 19bf8a6
Update Jest Object docs for retryTimes. Use symbol for global lookup.
palmerj3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should mention it just works with circus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mention in that section that it works with jest-circus. Should I be more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my mistake sorry. I mentioned it in the changelog not the docs. Will update.