-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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-case-reporting] Implement PoC for e2e test reporter #29768
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b0711de
Implement PoC for e2e test reporter
Rafer45 4304f89
Improve wording in comment & err message
Rafer45 f32d9a8
Lint
Rafer45 c1bdd8a
Refactor for clarity, fix fullTitle typo
Rafer45 52b1939
Move reporters to e2e folder, allowing imports to break for now
Rafer45 cec228b
Fix broken imports
Rafer45 739b4d7
Rename mocha ci reporter, breaking imports
Rafer45 1f19482
Make ci reporter that joins together the reporters
Rafer45 8f84767
Rename KarmaMimicReporter in files
Rafer45 0e222fa
Rename karma-mimic-reporter file
Rafer45 35a1bd5
Rename private _karmaMimicReporter
Rafer45 01480c6
Simplify event insertion
Rafer45 ad65609
Only write json report if report flag set
Rafer45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const JsonReporter = require('./mocha-custom-json-reporter'); | ||
const mocha = require('mocha'); | ||
const MochaDotsReporter = require('./mocha-dots-reporter'); | ||
const {Base} = mocha.reporters; | ||
|
||
function ciReporter(runner, options) { | ||
Base.call(this, runner, options); | ||
this._mochaDotsReporter = new MochaDotsReporter(runner, options); | ||
this._jsonReporter = new JsonReporter(runner, options); | ||
return this; | ||
} | ||
ciReporter.prototype.__proto__ = Base.prototype; | ||
|
||
module.exports = ciReporter; |
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,93 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs').promises; | ||
const { | ||
EVENT_TEST_PASS, | ||
EVENT_TEST_FAIL, | ||
EVENT_RUN_END, | ||
EVENT_TEST_PENDING, | ||
EVENT_SUITE_BEGIN, | ||
EVENT_SUITE_END, | ||
} = require('mocha').Runner; | ||
const {Base} = require('mocha').reporters; | ||
const {inherits} = require('mocha').utils; | ||
|
||
async function writeOutput(output, filename) { | ||
try { | ||
await fs.writeFile(filename, JSON.stringify(output, null, 4)); | ||
} catch (error) { | ||
process.stdout.write( | ||
Base.color( | ||
'fail', | ||
`Could not write test result report to file '${filename}'` | ||
) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Custom Mocha reporter for CI builds. | ||
* Mimics the structured karma reporter, but for Mocha. | ||
* @param {*} runner | ||
*/ | ||
function JsonReporter(runner) { | ||
Base.call(this, runner); | ||
const testEvents = []; | ||
let suiteList = []; | ||
|
||
runner.on(EVENT_SUITE_BEGIN, function (suite) { | ||
suiteList.push(suite.title); | ||
}); | ||
|
||
runner.on(EVENT_SUITE_END, function () { | ||
// We need a fresh copy every time we make a new suite, | ||
// so we can't use pop here (or the suiteList info of previous | ||
// tests would be changed) | ||
suiteList = suiteList.slice(0, -1); | ||
}); | ||
|
||
runner.on(EVENT_TEST_PASS, function (test) { | ||
testEvents.push({test, suiteList, EVENT_TEST_PASS}); | ||
}); | ||
|
||
runner.on(EVENT_TEST_FAIL, function (test) { | ||
testEvents.push({test, suiteList, EVENT_TEST_FAIL}); | ||
}); | ||
|
||
runner.on(EVENT_TEST_PENDING, function (test) { | ||
testEvents.push({test, suiteList, EVENT_TEST_PENDING}); | ||
}); | ||
Rafer45 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
runner.on(EVENT_RUN_END, async function () { | ||
const testResults = testEvents.map(({test, suiteList, event}) => ({ | ||
description: test.title, | ||
suite: suiteList, | ||
success: event === EVENT_TEST_PASS, | ||
skipped: event === EVENT_TEST_PENDING, | ||
time: test.duration, // in milliseconds | ||
})); | ||
|
||
// Apparently we'll need to add a --no-exit flag when calling this | ||
// to allow for the asynchronous reporter. | ||
// See https://github.com/mochajs/mocha/issues/812 | ||
await writeOutput({testResults}, `result-reports/e2e.json`); | ||
}); | ||
} | ||
|
||
inherits(JsonReporter, Base); | ||
module.exports = JsonReporter; |
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.
We'll probably want to skip the json reporter depending on whether a certain flag is set; I'm not familiar with this part of the codebase, what would be the cleanest way to do this?
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 suspect the same argv pattern you used for the gulp upload-report task (or whatever it was called) would work here