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

test(mutation): [Hackweek] experiment with mutation testing #13439

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7f09a2e
add jest-config dev package
Lms24 Aug 19, 2024
49c8673
add stryke config file
Lms24 Aug 19, 2024
53fb7f5
add `/reports` to .gitignore
Lms24 Aug 19, 2024
9d66abe
add stryker to browser and node
Lms24 Aug 19, 2024
2229b63
add top-level script
Lms24 Aug 19, 2024
b7c5672
clean stryker dirs
Lms24 Aug 19, 2024
e967907
test(core): Switch to vitest
Lms24 Aug 20, 2024
8d97a05
test(core): Improve offline transport test performance
Lms24 Aug 20, 2024
e27d70c
add summary script
Lms24 Aug 20, 2024
ad9a65b
add dashboard upload
Lms24 Aug 20, 2024
d77d9e3
add svelte, sveltekit, unify config
Lms24 Aug 20, 2024
13a918e
add github workflow
Lms24 Aug 20, 2024
02aaa7e
simplify install deps
Lms24 Aug 20, 2024
a9542c1
increase timeout
Lms24 Aug 20, 2024
7281739
sentry runner, adjust ci
Lms24 Aug 21, 2024
25f82d6
start trace later
Lms24 Aug 21, 2024
13e2868
rm nx cache
Lms24 Aug 21, 2024
8078e66
fix dependency tree
Lms24 Aug 21, 2024
360e87d
Revert "rm nx cache"
Lms24 Aug 21, 2024
721d72f
maybe pls fix dep error
Lms24 Aug 21, 2024
feaa498
fix test command in ci
Lms24 Aug 21, 2024
12e776e
maybe fix missing runner issue
Lms24 Aug 21, 2024
40e167f
.
Lms24 Aug 21, 2024
d829ec4
check dir content
Lms24 Aug 21, 2024
4c1934e
.
Lms24 Aug 21, 2024
17e56cc
..
Lms24 Aug 21, 2024
5593843
esm
Lms24 Aug 21, 2024
8f4cc7a
...
Lms24 Aug 21, 2024
80d069c
maybe now?
Lms24 Aug 21, 2024
43089e6
use script instead of package
Lms24 Aug 23, 2024
f1a5fd3
fix scripts
Lms24 Aug 23, 2024
470807c
remove runner from ci
Lms24 Aug 23, 2024
079780c
debug missing traceid
Lms24 Aug 23, 2024
1b0ef5d
fix baggage
Lms24 Aug 23, 2024
40008fb
fix job outputs for sentry_trace and baggage
Lms24 Aug 23, 2024
30eed17
dumb mistake
Lms24 Aug 23, 2024
4fd1695
y u no work :(
Lms24 Aug 23, 2024
b6ed714
write to github output in node script
Lms24 Aug 23, 2024
fe21686
fs import
Lms24 Aug 23, 2024
22a0ea9
units and flush
Lms24 Aug 23, 2024
b7935c6
disable dashboard for now
Lms24 Aug 23, 2024
c942f0b
add utils
Lms24 Aug 23, 2024
d9e6ec4
fix report upload name
Lms24 Aug 23, 2024
7ed9b1d
matrix change
Lms24 Aug 23, 2024
f4d74b5
add angular
Lms24 Aug 23, 2024
264f8a1
add astro
Lms24 Aug 23, 2024
3d2860c
aws-serverless
Lms24 Aug 23, 2024
d7194d4
formatting
Lms24 Aug 23, 2024
b1c00fe
add gatsby
Lms24 Aug 23, 2024
7452382
add google-cloud-serverless
Lms24 Aug 23, 2024
29c675b
add nestjs
Lms24 Aug 23, 2024
59f326a
add nextjs
Lms24 Aug 26, 2024
f6a05b8
add nextjs run to ci
Lms24 Aug 26, 2024
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
195 changes: 195 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: 'Mutation Testing'
on:
push:
branches:
- lms/test-hackweek-mutation-testing
workflow_dispatch:
inputs:
commit:
description: If the commit you want to test isn't the head of a branch, provide its SHA here
required: false
schedule:
# run every sunday at midnight:
- cron: '0 0 * * 0'

# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
HEAD_COMMIT: ${{ github.event.inputs.commit || github.sha }}

# WARNING: this disables cross os caching as ~ and
# github.workspace evaluate to differents paths
CACHED_DEPENDENCY_PATHS: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/packages/*/node_modules
${{ github.workspace }}/dev-packages/*/node_modules
~/.cache/mongodb-binaries/

# DEPENDENCY_CACHE_KEY: can't be set here because we don't have access to yarn.lock

# WARNING: this disables cross os caching as ~ and
# github.workspace evaluate to differents paths
# packages/utils/cjs and packages/utils/esm: Symlinks to the folders inside of `build`, needed for tests
CACHED_BUILD_PATHS: |
${{ github.workspace }}/dev-packages/*/build
${{ github.workspace }}/packages/*/build
${{ github.workspace }}/packages/ember/*.d.ts
${{ github.workspace }}/packages/gatsby/*.d.ts
${{ github.workspace }}/packages/core/src/version.ts
${{ github.workspace }}/packages/utils/cjs
${{ github.workspace }}/packages/utils/esm

BUILD_CACHE_KEY: build-cache-${{ github.event.inputs.commit || github.sha }}
BUILD_CACHE_TARBALL_KEY: tarball-${{ github.event.inputs.commit || github.sha }}

# GH will use the first restore-key it finds that matches
# So it will start by looking for one from the same branch, else take the newest one it can find elsewhere
# We want to prefer the cache from the current develop branch, if we don't find any on the current branch
NX_CACHE_RESTORE_KEYS: |
nx-Linux-${{ github.ref }}-${{ github.event.inputs.commit || github.sha }}
nx-Linux-${{ github.ref }}
nx-Linux

jobs:
job_get_metadata:
name: Get Metadata
runs-on: ubuntu-20.04
permissions:
pull-requests: read
steps:
- name: Check out current commit
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}
# We need to check out not only the fake merge commit between the PR and the base branch which GH creates, but
# also its parents, so that we can pull the commit message from the head commit of the PR
fetch-depth: 2

- name: Get metadata
id: get_metadata
# We need to try a number of different options for finding the head commit, because each kind of trigger event
# stores it in a different location
run: |
COMMIT_SHA=$(git rev-parse --short ${{ github.event.head_commit.id || env.HEAD_COMMIT }})
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=$(git log -n 1 --pretty=format:%s $COMMIT_SHA)" >> $GITHUB_ENV

outputs:
commit_label: '${{ env.COMMIT_SHA }}: ${{ env.COMMIT_MESSAGE }}'

job_build:
name: Build
needs: job_get_metadata
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: 'Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})'
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
id: install_dependencies

- name: Check build cache
uses: actions/cache@v4
id: cache_built_packages
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}

- name: NX cache
uses: actions/cache@v4
with:
path: .nxcache
key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT || github.sha }}
restore-keys:
${{ env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}

- name: Build packages
run: yarn build

- name: Generate Sentry Trace
id: step_sentry_trace
run: |
node ./scripts/stryker/start-trace.mjs
echo output=${{ env.GITHUB_OUTPUT }}

outputs:
dependency_cache_key: ${{ steps.install_dependencies.outputs.cache_key }}
sentry_trace: ${{ steps.step_sentry_trace.outputs.sentry_trace }}
baggage: ${{ steps.step_sentry_trace.outputs.baggage }}

job_mutation_test:
name: Mutation Test (${{ matrix.package }})
needs: [job_get_metadata, job_build]
timeout-minutes: 180
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
package: [
'angular',
'astro',
'aws-serverless',
'browser',
'core',
'gatsby',
'google-cloud-serverless',
'nextjs',
'node',
'svelte',
'sveltekit',
'utils'
]
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: NX cache
uses: actions/cache@v4
with:
path: .nxcache
key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT || github.sha }}
restore-keys:
${{ env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}

- name: Set trace propagation data
run: |
echo "SENTRY_MUT_SENTRY_TRACE=${{ needs.job_build.outputs.sentry_trace }}" >> $GITHUB_ENV
echo "SENTRY_MUT_BAGGAGE=${{ needs.job_build.outputs.baggage }}" >> $GITHUB_ENV

- name: Run mutation test
run: yarn nx run @sentry/${{ matrix.package }}:test:mutation
env:
NODE_VERSION: ${{ matrix.node }}

- name: Upload Results
uses: actions/upload-artifact@v4
with:
name: test-reports ${{ matrix.package }}
path: |
${{ github.workspace }}/packages/**/mutation.json
${{ github.workspace }}/packages/**/mutation.html
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build/
# various integration test builds
dist/
coverage/
reports/
scratch/
*.js.map
*.pyc
Expand Down Expand Up @@ -42,6 +43,8 @@ local.log

.rpt2_cache

.stryker-tmp

lint-results.json

# legacy
Expand Down
3 changes: 3 additions & 0 deletions dev-packages/jest-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@sentry-internal/jest-config`

A package containing the base Jest config for the sentry-javascript SDK repo
26 changes: 26 additions & 0 deletions dev-packages/jest-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"version": "8.26.0",
"name": "@sentry-internal/jest-config",
"author": "Sentry",
"license": "MIT",
"main": "./src/jest.config.js",
"files": [
"src"
],
"exports": {
"./package.json": "./package.json",
".": {
"require": {
"default": "./src/jest.config.js"
}
}
},
"sideEffects": false,
"engines": {
"node": ">=14.18"
},
"volta": {
"extends": "../../package.json"
}
}
29 changes: 29 additions & 0 deletions dev-packages/jest-config/src/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
// this is the package root, even when tests are being run at the repo level
rootDir: process.cwd(),
collectCoverage: true,
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.tsx$': 'ts-jest',
},
coverageDirectory: '<rootDir>/coverage',
moduleFileExtensions: ['js', 'ts', 'tsx'],
testMatch: ['<rootDir>/**/*.test.ts', '<rootDir>/**/*.test.tsx'],
moduleNameMapper: {
'^axios$': require.resolve('axios'),
},
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
__DEBUG_BUILD__: true,
},
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/node_modules/', '<rootDir>/.stryker-tmp/'],

// On CI, we do not need the pretty CLI output, as it makes logs harder to parse
...(process.env.CI
? {
coverageReporters: ['json', 'lcov', 'clover'],
}
: {}),
};
3 changes: 3 additions & 0 deletions dev-packages/stryker-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@sentry-internal/stryker-config`

A package containing the base Stryker config for the sentry-javascript SDK repo
26 changes: 26 additions & 0 deletions dev-packages/stryker-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"version": "8.26.0",
"name": "@sentry-internal/stryker-config",
"author": "Sentry",
"license": "MIT",
"files": [
"src"
],
"exports": {
"./package.json": "./package.json",
"./config": {
"import": {
"default": "./src/stryker.config.mjs"
}
}
},
"sideEffects": false,
"engines": {
"node": ">=14.18"
},
"volta": {
"extends": "../../package.json"
},
"type": "module"
}
25 changes: 25 additions & 0 deletions dev-packages/stryker-config/src/stryker.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import child_process from 'child_process';

// STRYKER_DASHBOARD_API_KEY env variable needs to be set to upload to dashboard

/** @type {import('@stryker-mutator/api/core').PartialStrykerOptions} */
const config = {
packageManager: 'yarn',
reporters: ['html', 'clear-text', 'progress', 'json'],
testRunner: 'vitest',
coverageAnalysis: 'perTest',
ignoreStatic: true,
dashboard: {
// TODO: change to getsentry/sentry-javascript if we ship this into production
project: 'github.com/Lms24/sentry-javascript-test-fork',
version: child_process.execSync('git rev-parse HEAD').toString().trim(),
},
clearTextReporter: {
logTests: false,
reportMutants: false,
reportScoreTable: true,
skipFull: false,
},
};

export default config;
3 changes: 3 additions & 0 deletions dev-packages/stryker-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@sentry-internal/stryker-runner`

A runner to run stryker with Sentry instrumentation to catch errors during test runs, as well as performance data
33 changes: 33 additions & 0 deletions dev-packages/stryker-runner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"private": true,
"version": "8.26.0",
"name": "@sentry-internal/stryker-runner",
"author": "Sentry",
"license": "MIT",
"files": [
"build"
],
"exports": {
"./package.json": "./package.json"
},
"engines": {
"node": ">=14.18"
},
"volta": {
"extends": "../../package.json"
},
"dependencies": {
"@stryker-mutator/core": "^8.5.0",
"typescript": "^4.9.5"
},
"devDependencies": {
"@stryker-mutator/api": "^8.5.0"
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"start": "node ./build/esm/run.js"
},
"type": "module",
"bin": "./build/esm/run.js"
}
Loading
Loading