-
-
Notifications
You must be signed in to change notification settings - Fork 752
Option to Run the Failed scripts only & to run selected scripts #2777
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
903ced8
Rerun of Failed Tests
87bc433
Rerun Failed Tests in Sequential and Parallel mode
83ac714
Rerun of the failed scripts
e74fb6d
Rerun Of the Failed scripts
8783ca7
Rerun Selected or Failed Tests
0fa25aa
Fixed eslint issues
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,112 @@ | ||
| const fs = require('fs'); | ||
| const { print } = require('codeceptjs/lib/output'); | ||
|
|
||
| class FailedTestsRerun { | ||
| /** | ||
| * Initial Check To Find the Existence Of Failed Cases JSON File | ||
| * and Content | ||
| * @param options | ||
| */ | ||
| checkForFailedTestsExist(options) { | ||
| if (options.rerunTests) { | ||
| if (!fs.existsSync('failedCases.json')) { | ||
| print('There Are No Failed Tests In Previous Execution'); | ||
| process.exit(); | ||
| } else { | ||
| const failedTests = this.getFailedTestContent(); | ||
| if (failedTests.length === 0 || failedTests.toString() === '') { | ||
| print('There Are No Files Present In the Failed Cases Json File'); | ||
| process.exit(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks If The Valid Files are Passed in Failed Cases Json File | ||
| *@param testFiles | ||
| */ | ||
| checkForFileExistence(testFiles) { | ||
| const invalidTest = []; | ||
| let flag = 0; | ||
| for (let i = 0; i < testFiles.length; i++) { | ||
| const path = testFiles[i]; | ||
| if (!fs.existsSync(path)) { | ||
| invalidTest.push(path); | ||
| flag++; | ||
| } | ||
| } | ||
| if (flag > 0) { | ||
| // eslint-disable-next-line no-useless-concat | ||
| print('\nInvalid File(s) Found :' + '\n'); | ||
| for (let j = 0; j < invalidTest.length; j++) { | ||
| print(invalidTest[j]); | ||
| } | ||
| process.exit(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns The Content In JSON File For File/Content existence Check | ||
| * @return {string[]} | ||
| */ | ||
| getFailedTestContent() { | ||
| return fs.readFileSync('failedCases.json', { encoding: 'utf8' }).split(','); | ||
| } | ||
|
|
||
| /** | ||
| * Returns The Failed/Selected Tests | ||
| * @return {any} | ||
| */ | ||
| getFailedTests() { | ||
| return JSON.parse(fs.readFileSync('failedCases.json', 'utf8')); | ||
| } | ||
|
|
||
| /** | ||
| * Writes The Failed Tests in The Failed Cases JSON File Post Execution | ||
| * @param failedTests | ||
| */ | ||
| writeFailedTests(failedTests) { | ||
| if (failedTests.length > 0) { | ||
| fs.writeFileSync('failedCases.json', JSON.stringify(failedTests), (err) => { | ||
| if (err) { return print(err); } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes The Passed Test From The Failed Cases JSON During the Execution | ||
| * Deletes the File When All Tests Are Passed | ||
| * @param passedTest | ||
| */ | ||
| removePassedTests(passedTest) { | ||
| if (fs.existsSync('failedCases.json')) { | ||
| const currentFile = JSON.parse(fs.readFileSync('failedCases.json', 'utf8')); | ||
| currentFile.forEach((t) => { | ||
| if (currentFile.includes(passedTest)) { | ||
| const index = currentFile.indexOf(t); | ||
| if (index > -1) { | ||
| currentFile.splice(index, 1); | ||
| } | ||
| } | ||
| }); | ||
| fs.writeFile('failedCases.json', JSON.stringify(currentFile), (err) => { | ||
| if (err) throw err; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * To Remove The Failed Cases JSON file if No Tests Are There | ||
| * @param failedTests | ||
| */ | ||
| checkAndRemoveFailedCasesFile(failedTests) { | ||
| if (failedTests.length < 1) { | ||
| if (fs.existsSync('failedCases.json')) { | ||
| fs.unlinkSync('failedCases.json'); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = FailedTestsRerun; |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,14 @@ const recorder = require('./recorder'); | |
| const runHook = require('./hooks'); | ||
| const WorkerStorage = require('./workerStorage'); | ||
|
|
||
| const FailedTestRerun = require('./rerunFailed'); | ||
|
|
||
| const failedTestRerun = new FailedTestRerun(); | ||
|
|
||
| const testsArrObj = []; | ||
| const failedTests = []; | ||
| const passedTests = []; | ||
|
|
||
| const pathToWorker = path.join(__dirname, 'command', 'workers', 'runTests.js'); | ||
|
|
||
| const initializeCodecept = (configPath, options = {}) => { | ||
|
|
@@ -56,7 +64,6 @@ const createWorker = (workerObject) => { | |
| }, | ||
| }); | ||
| worker.on('error', err => output.error(`Worker Error: ${err.stack}`)); | ||
|
|
||
| WorkerStorage.addWorker(worker); | ||
| return worker; | ||
| }; | ||
|
|
@@ -241,6 +248,7 @@ class Workers extends EventEmitter { | |
| mocha.suite.eachTest((test) => { | ||
| const i = groupCounter % groups.length; | ||
| if (test) { | ||
| testsArrObj.push(test); | ||
| const { id } = test; | ||
| groups[i].push(id); | ||
| groupCounter++; | ||
|
|
@@ -263,6 +271,7 @@ class Workers extends EventEmitter { | |
| const i = indexOfSmallestElement(groups); | ||
| suite.tests.forEach((test) => { | ||
| if (test) { | ||
| testsArrObj.push(test); | ||
| const { id } = test; | ||
| groups[i].push(id); | ||
| } | ||
|
|
@@ -325,10 +334,16 @@ class Workers extends EventEmitter { | |
| break; | ||
| case event.test.failed: | ||
| this._updateFinishedTests(repackTest(message.data)); | ||
| // eslint-disable-next-line no-case-declarations | ||
| const failTest = testsArrObj.filter(t => t.id === message.data.id); | ||
| failedTests.push(failTest[0].file); | ||
| this.emit(event.test.failed, repackTest(message.data)); | ||
| break; | ||
| case event.test.passed: | ||
| this._updateFinishedTests(repackTest(message.data)); | ||
| // eslint-disable-next-line no-case-declarations | ||
| const passTest = testsArrObj.filter(t => t.id === message.data.id); | ||
| passedTests.push(passTest[0].file); | ||
| this.emit(event.test.passed, repackTest(message.data)); | ||
| break; | ||
| case event.test.skipped: | ||
|
|
@@ -340,6 +355,7 @@ class Workers extends EventEmitter { | |
| this.emit(event.test.after, repackTest(message.data)); | ||
| break; | ||
| case event.all.after: | ||
| failedTestRerun.writeFailedTests(failedTests); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this looks like breaking the abstraction hierarchy. |
||
| this._appendStats(message.data); break; | ||
| } | ||
| }); | ||
|
|
||
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.
this is not a correct place to put this logic
this listener only sets the exit code for failed tests