Skip to content

Commit

Permalink
improve test performance
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhousley committed Jun 17, 2023
1 parent 93ca6e0 commit 8169bff
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 15 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ on:
description: 'The collection of jest tests to run'
required: true
type: choice
options:
options:
- unit
- component
default: 'unit'
coverage:
description: 'Enable code coverage'
required: false
type: boolean
default: false
workflow_call:
inputs:
ref:
Expand All @@ -25,6 +30,11 @@ on:
required: false
type: string
default: 'unit'
coverage:
description: 'Enable code coverage'
required: false
type: boolean
default: false

jobs:
run:
Expand All @@ -36,6 +46,8 @@ jobs:
defaults:
run:
shell: bash
env:
COVERAGE: ${{ inputs.coverage }}
steps:
- name: Setup container
run: apt update && apt install -y git
Expand All @@ -51,11 +63,12 @@ jobs:
run: npm run test:${{ inputs.collection }} -- --coverage
- name: Find pull request
id: pull-request-target
if: ${{ inputs.coverage }}
uses: ./.github/actions/find-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload pr code coverage
if: ${{ steps.pull-request-target.outputs.results }}
if: ${{ inputs.coverage && steps.pull-request-target.outputs.results }}
uses: codecov/codecov-action@v3
env:
GITHUB_HEAD_REF: ${{ inputs.ref }}
Expand All @@ -65,13 +78,14 @@ jobs:
flags: jest-${{ inputs.collection }}
verbose: true
- name: Upload branch code coverage
if: ${{ !steps.pull-request-target.outputs.results }}
if: ${{ inputs.coverage && steps.pull-request-target.outputs.results }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: jest-${{ inputs.collection }}
verbose: true
- name: Archive code coverage results
if: ${{ inputs.coverage }}
uses: actions/upload-artifact@v3
with:
name: jest-${{ inputs.collection }}-code-coverage-report
Expand Down
65 changes: 62 additions & 3 deletions .github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
pr_required: true

comment-pull-request:
name: Comment pull request
pending-comment-pull-request:
name: Pending comment pull request
needs: [find-pull-request]
runs-on: ubuntu-latest
container:
Expand All @@ -53,7 +53,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}
comment: |
[![Pull Request Checks](https://github.com/newrelic/newrelic-browser-agent/actions/workflows/pull-request-checks.yml/badge.svg?branch=${{ github.ref_name }})](https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }})
[![Static Badge](https://img.shields.io/badge/Pull_Request_Checks-Pending-yellow)](https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }})
Last ran on `${{ steps.workflow-time.outputs.results }}`
Checking merge of (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}) into [${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_ref }}](https://github.com/newrelic/newrelic-browser-agent/compare/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}..${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }}) (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }})
Expand All @@ -66,6 +66,7 @@ jobs:
with:
ref: 'refs/pull/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}/merge'
collection: 'unit'
coverage: true
secrets: inherit

jest-component:
Expand All @@ -75,6 +76,7 @@ jobs:
with:
ref: 'refs/pull/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}/merge'
collection: 'component'
coverage: true
secrets: inherit

eslint:
Expand Down Expand Up @@ -147,3 +149,60 @@ jobs:
build/size_report.*
build/*.stats.html
build/*.stats.json
status-comment-pull-request:
name: Comment pull request
needs: [find-pull-request,jest-unit,jest-component,eslint,wdio-coverage]
if: ${{ always() && needs.find-pull-request.result == 'success' }}
runs-on: ubuntu-latest
container:
image: ubuntu:latest
defaults:
run:
shell: bash
steps:
- name: Setup container
run: apt update && DEBIAN_FRONTEND=noninteractive apt install -y git tzdata
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Get workflow time
id: workflow-time
run: echo "results=$(TZ=America/Chicago date +'%B %d, %Y %H:%M:%S %Z')" >> $GITHUB_OUTPUT
- name: Comment pull request success
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
uses: ./.github/actions/comment-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}
comment: |
[![Static Badge](https://img.shields.io/badge/Pull_Request_Checks-Success-green)](https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }})
Last ran on `${{ steps.workflow-time.outputs.results }}`
Checking merge of (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}) into [${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_ref }}](https://github.com/newrelic/newrelic-browser-agent/compare/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}..${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }}) (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }})
comment_tag: <!-- browser_agent pull request checks -->
- name: Comment pull request failed
if: ${{ contains(needs.*.result, 'failure') }}
uses: ./.github/actions/comment-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}
comment: |
[![Static Badge](https://img.shields.io/badge/Pull_Request_Checks-Failure-red)](https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }})
Last ran on `${{ steps.workflow-time.outputs.results }}`
Checking merge of (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}) into [${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_ref }}](https://github.com/newrelic/newrelic-browser-agent/compare/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}..${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }}) (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }})
comment_tag: <!-- browser_agent pull request checks -->
- name: Comment pull request cancelled
if: ${{ contains(needs.*.result, 'cancelled') }}
uses: ./.github/actions/comment-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).pr_number }}
comment: |
[![Static Badge](https://img.shields.io/badge/Pull_Request_Checks-Cancelled-orange)](https://github.com/newrelic/newrelic-browser-agent/actions/runs/${{ github.run_id }})
Last ran on `${{ steps.workflow-time.outputs.results }}`
Checking merge of (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}) into [${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_ref }}](https://github.com/newrelic/newrelic-browser-agent/compare/${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).head_sha }}..${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }}) (${{ fromJSON(needs.find-pull-request.outputs.pull-request-target).base_sha }})
comment_tag: <!-- browser_agent pull request checks -->
8 changes: 8 additions & 0 deletions .github/workflows/wdio-all-browsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ jobs:
browser-target: android@*
build-number: $BUILD_NUMBER
secrets: inherit

ie:
uses: ./.github/workflows/wdio-single-browser.yml
with:
browser-target: ie@11
build-number: $BUILD_NUMBER
additional-flags: -P
secrets: inherit
6 changes: 4 additions & 2 deletions .github/workflows/wdio-single-browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
required: false
type: string
coverage:
description: 'Flag indicating if code coverage should be collected and reported to codecov'
description: 'Enable code coverage'
required: false
type: boolean
default: false
Expand All @@ -35,7 +35,7 @@ on:
required: false
type: string
coverage:
description: 'Flag indicating if code coverage should be collected and reported to codecov'
description: 'Enable code coverage'
required: false
type: boolean
default: false
Expand All @@ -56,6 +56,7 @@ jobs:
shell: bash
env:
BUILD_NUMBER: ${{ inputs.build-number }}
COVERAGE: ${{ inputs.coverage }}
NEWRELIC_ENVIRONMENT: ci
JIL_SAUCE_LABS_USERNAME: ${{ secrets.JIL_SAUCE_LABS_USERNAME }}
JIL_SAUCE_LABS_ACCESS_KEY: ${{ secrets.JIL_SAUCE_LABS_ACCESS_KEY }}
Expand Down Expand Up @@ -84,6 +85,7 @@ jobs:
${{ inputs.additional-flags || '' }}
- name: Find pull request
id: pull-request-target
if: ${{ inputs.coverage }}
uses: ./.github/actions/find-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flag_management:
default_rules:
carryforward: true
7 changes: 2 additions & 5 deletions tests/functional/pvt/timings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,8 @@ function runLongTasksTest (loader) {
const timings = body && body.length ? body : querypack.decode(query.e)

const ltEvents = timings.filter(t => t.name === 'lt')

/* Istanbul (for wdio code cov) adds a long task to the loader for webpack LOCAL testing, so we account for that here. It may be taken off in the future.
* TODO - This should be changed from 3 to 2 once Istanbul is no longer included by default in the test agent build.
*/
t.ok(ltEvents.length == 3, 'expected number of long tasks (2 -> temp 3) observed')

t.ok(ltEvents.length == 2, 'expected number of long tasks')

ltEvents.forEach((lt) => {
t.ok(lt.value >= 59, 'task duration is roughly as expected') // defined in some-long-task.js -- duration should be at least that value +/- 1ms
Expand Down
5 changes: 3 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const pkg = require('./package.json')

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

let { PUBLISH, SOURCEMAPS = true, PR_NAME, BRANCH_NAME, VERSION_OVERRIDE } = process.env
let { PUBLISH, SOURCEMAPS = true, COVERAGE = 'false', PR_NAME, BRANCH_NAME, VERSION_OVERRIDE } = process.env
// this will change to package.json.version when it is aligned between all the packages
let VERSION = VERSION_OVERRIDE || pkg.version
let PATH_VERSION, SUBVERSION, PUBLIC_PATH, MAP_PATH
Expand Down Expand Up @@ -79,6 +79,7 @@ console.log('SUBVERSION', SUBVERSION)
console.log('PUBLIC_PATH', PUBLIC_PATH)
console.log('MAP_PATH', MAP_PATH)
console.log('IS_LOCAL', IS_LOCAL)
console.log('COVERAGE', COVERAGE)
if (PR_NAME) console.log('PR_NAME', PR_NAME)
if (BRANCH_NAME) console.log('BRANCH_NAME', BRANCH_NAME)
process.env.BUILD_VERSION = VERSION
Expand Down Expand Up @@ -169,7 +170,7 @@ const standardConfig = merge(commonConfig, {
{
test: /\.js$/,
exclude: /(node_modules)/,
use: SUBVERSION === 'LOCAL'
use: COVERAGE === 'true'
? [
{ loader: './tools/webpack/loaders/istanbul/index.mjs' },
{
Expand Down

0 comments on commit 8169bff

Please sign in to comment.