Skip to content
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

improved collection of failed specs #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/failed-spec-parser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const FAILED_LINE = /at \[object Object\]\.<anonymous> \((.*)\)/g;
const FAILED_LINES = /at \[object Object\]\.<anonymous> \((.*?):.*\)/g;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should define this as a non-constant within the body of the function, since exec modifies the state of the regex it is invoked on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


export default function (output = '') {
// this could all probably fit into one regex...
var failedSpecLines = output.match(FAILED_LINE);
var output = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for this? output should always just be a giant blob of text (although perhaps it is different for multi capabilities?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually copy&pasted from the code that npm install protractor-flake delivered. Otherwise I agree that it's not necessary.


if (!failedSpecLines) { return []; }

return failedSpecLines.map(function (line) {
let path = line.match(/\((.*):/)[1];
return path.slice(0, [path.length - 2]);
});
}
var failedSpecLines = [];
var match;
//iterate over all matches and prevent adding a spec twice (e.g. when using multiCapabilities)
while (match = FAILED_LINES.exec(output)) {
if (failedSpecLines.indexOf(match[1]) == -1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome improvement. I wonder if this might be a good use case for a Set which would accomplish the same thing without the need for indexOf checking

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Set would basically be the same, seeing how internally it also has to check for duplicates when adding a new element, but might improve code readability.

failedSpecLines.push(match[1]);
}
}
return failedSpecLines;
};