Skip to content

Commit

Permalink
test: Honeycomb system-test reporter (#19855)
Browse files Browse the repository at this point in the history
* Mocha performance reporter

Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
  • Loading branch information
Blue F and tgriesser committed Jan 27, 2022
1 parent 10c6e5a commit f5cb2b9
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 26 deletions.
4 changes: 4 additions & 0 deletions circle.yml
Expand Up @@ -2088,15 +2088,19 @@ linux-workflow: &linux-workflow
requires:
- build
- system-tests-chrome:
context: test-runner:performance-tracking
requires:
- system-tests-node-modules-install
- system-tests-electron:
context: test-runner:performance-tracking
requires:
- system-tests-node-modules-install
- system-tests-firefox:
context: test-runner:performance-tracking
requires:
- system-tests-node-modules-install
- system-tests-non-root:
context: test-runner:performance-tracking
executor: non-root-docker-user
requires:
- system-tests-node-modules-install
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Expand Up @@ -147,6 +147,7 @@
"@types/chai-as-promised": "7.1.2",
"@types/chrome": "0.0.101",
"@types/http-proxy": "1.17.4",
"@types/node": "14.14.31",
"awesome-typescript-loader": "5.2.1",
"babel-loader": "8.1.0",
"body-parser": "1.19.0",
Expand Down
81 changes: 81 additions & 0 deletions system-tests/lib/performance-reporter.js
@@ -0,0 +1,81 @@
const path = require('path')
const chalk = require('chalk')
const Libhoney = require('libhoney')

const pkg = require('@packages/root')
const ciProvider = require('@packages/server/lib/util/ci_provider')
const { commitInfo } = require('@cypress/commit-info')

class StatsdReporter {
constructor (runner) {
if (!process.env.HONEYCOMB_API_KEY) {
return
}

console.log(chalk.green('Reporting to honeycomb'))

let branch; let commitSha

this.honey = new Libhoney({
dataset: 'systemtest-performance',
writeKey: process.env.HONEYCOMB_API_KEY,
})

commitInfo().then((commitInformation) => {
const ciInformation = ciProvider.commitParams() || {}

this.branch = commitInformation.branch || ciInformation.branch
this.commitSha = commitInformation.sha || ciInformation.sha
})

runner.on('test', (test) => {
test.wallclockStart = Date.now()
})

runner.on('test end', (test) => {
// Skipped tests never get a 'start' event, but they still get 'test end' somehow.
if (!test.state || test.state === 'skipped') {
return
}

const title = test.titlePath().join(' / ')
// This regex pulls apart a string like `e2e async timeouts / failing1 [electron]`
// into `e2e async timeouts / failing1` and `electron`, letting us use the same
// test name for all browsers, with the browser as a separate field.
// The browser capture group is optional because some tests aren't browser specific,
// in which case it will be undefined and not passed as a field to honeycomb.
const [, testTitle, browser] = title.match(/(.+?)(?: \[([a-z]+)\])?$/)

const honeycombEvent = this.honey.newEvent()

honeycombEvent.timestamp = test.wallclockStart
honeycombEvent.add({
test: testTitle,
specFile: path.basename(test.file),
browser,
state: test.state,
err: test.err && test.err.message,
errStack: test.err && test.err.stack,
durationMs: Date.now() - test.wallclockStart,
mochaDurationMs: test.duration,
branch,
commitSha,
buildUrl: process.env.CIRCLE_BUILD_URL,
platform: process.platform,
arch: process.arch,
version: pkg.version,
})

honeycombEvent.send()
})
}

// If there is no done callback, then mocha-multi-reporter will kill the process without waiting for our honeycomb post to complete.
done (failures, callback) {
if (this.honey) {
this.honey.flush().then(callback)
}
}
}

module.exports = StatsdReporter
1 change: 1 addition & 0 deletions system-tests/lib/spec_helper.js
Expand Up @@ -103,6 +103,7 @@ beforeEach(function () {

nock.disableNetConnect()
nock.enableNetConnect(/localhost/)
nock.enableNetConnect(/api.honeycomb.io/)

// always clean up the cache
// before each test
Expand Down
1 change: 1 addition & 0 deletions system-tests/package.json
Expand Up @@ -55,6 +55,7 @@
"human-interval": "1.0.0",
"image-size": "0.8.3",
"lazy-ass": "1.6.0",
"libhoney": "3.0.0",
"lodash": "^4.17.21",
"mocha": "7.1.0",
"mocha-banner": "1.1.2",
Expand Down
6 changes: 6 additions & 0 deletions system-tests/scripts/mocha-reporter-config.json
@@ -0,0 +1,6 @@
{
"reporterEnabled": "spec, mocha-junit-reporter, ../../system-tests/lib/performance-reporter.js",
"mochaJunitReporterReporterOptions": {
"mochaFile": "/tmp/cypress/junit/test-results.[hash].xml"
}
}
2 changes: 1 addition & 1 deletion system-tests/scripts/run.js
Expand Up @@ -109,7 +109,7 @@ commandAndArguments.args.push(
'--reporter',
'mocha-multi-reporters',
'--reporter-options',
'configFile=../../mocha-reporter-config.json',
'configFile=../../system-tests/scripts/mocha-reporter-config.json',
'--extension=js,ts',
// restore mocha 2.x behavior to force end process after spec run
'--exit',
Expand Down

3 comments on commit f5cb2b9

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5cb2b9 Jan 27, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.4.0/circle-develop-f5cb2b9a7b836075669663ea6dbd97d13dcb4ba1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5cb2b9 Jan 27, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.4.0/circle-develop-f5cb2b9a7b836075669663ea6dbd97d13dcb4ba1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f5cb2b9 Jan 27, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.4.0/circle-develop-f5cb2b9a7b836075669663ea6dbd97d13dcb4ba1/cypress.tgz

Please sign in to comment.