{"name":"mutation-testing-metrics","version":"3.7.0","license":"Apache-2.0","_id":"mutation-testing-metrics@3.7.0","maintainers":[{"name":"nicojs","email":"jansennico@gmail.com"},{"name":"strykermutator-npa","email":"strykermutator.npa@gmail.com"}],"homepage":"https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/metrics#readme","bugs":{"url":"https://github.com/stryker-mutator/mutation-testing-elements/issues"},"nx":{"name":"metrics"},"dist":{"shasum":"bdf71131002ab52a2307446eb8588adfb50b8612","tarball":"http://registry-npm.ywwl.com/mutation-testing-metrics/download/mutation-testing-metrics-3.7.0.tgz","fileCount":88,"integrity":"sha512-JZVIhe0HVWevSC/dm4sgG/FnDU9WZM8iji4eVm9v84Bp+km1yt41TImUaYrsWDf+d4NxN8dGrf9UaAJtYOfZqw==","signatures":[{"sig":"MEYCIQCooxwgvdVkm5Sx6ca9Vd9MooqjIZzNQ+D5RT1ixW6XuwIhAO3TAEl6CYbflfBrxMGkrLvAZdDiAAsY1bH/rOgcZdjq","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/mutation-testing-metrics@3.7.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":118159,"size":28733,"noattachment":false,"key":"/mutation-testing-metrics/-/mutation-testing-metrics-3.7.0.tgz"},"main":"dist/src/index.js","type":"module","types":"./dist/src/index.d.ts","exports":{".":"./dist/src/index.js"},"gitHead":"22a0cd186ad483c7d2aba9f065776bf78933f9dd","scripts":{"lint":"eslint .","test":"mocha --node-option enable-source-maps --forbid-only --forbid-pending --retries 2 dist/test/**/*.js","stryker":"stryker run"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9f75b4ba-5cd0-4c3b-aa69-a46597188612"}},"repository":{"url":"git+https://github.com/stryker-mutator/mutation-testing-elements.git","type":"git","directory":"packages/metrics"},"_npmVersion":"lerna/9.0.1/node@v24.11.1+x64 (linux)","description":"Utility functions to calculate mutation testing metrics.","directories":{},"_nodeVersion":"24.11.1","dependencies":{"mutation-testing-report-schema":"3.7.0"},"_hasShrinkwrap":false,"devDependencies":{"eslint-config-mte":"3.7.0"},"_npmOperationalInternal":{"tmp":"tmp/mutation-testing-metrics_3.7.0_1763745271218_0.5379007790107142","host":"s3://npm-registry-packages-npm-production"},"readme":"[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fstryker-mutator%2Fmutation-testing-elements%2Fmaster%3Fmodule%3Dmetrics)](https://badge-api.stryker-mutator.io/github.com/stryker-mutator/mutation-testing-elements/master?module=metrics)\n[![Build Status](https://github.com/stryker-mutator/mutation-testing-elements/workflows/CI/badge.svg)](https://github.com/stryker-mutator/mutation-testing-elements/actions?query=workflow%3ACI+branch%3Amaster)\n\n# Mutation testing metrics\n\nUtility function to calculate mutation testing metrics..\n\nSee [mutant states and metrics on the Stryker website](https://stryker-mutator.io/docs/mutation-testing-elements/mutant-states-and-metrics/) for more details about mutation testing metrics.\n\n## Usage example\n\nSee the below example (uses TypeScript):\n\n```ts\nimport { MetricsResult, calculateMutationTestMetrics } from 'mutation-testing-metrics';\nimport { MutationTestResult } from 'mutation-testing-report-schema';\n\nconst mutationTestReport: MutationTestResult = {/*... Get a holds of mutation test results somehow */};\n\nconst result: MetricsResult = calculateMutationTestMetrics(mutationTestReport);\n\nconsole.log('Mutation score', result.metrics.mutationScore);\n```\n\n## API Reference\n\n### `calculateMutationTestMetrics` [`(MutationTestResult) => MutationTestMetricsResult`]\n\nCalculates the full mutation test metrics from both the files-under-test as well as (optionally) the test files.\n\nThe input is a mutation test result valid according to the [https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/report-schema#readme]\n\nReturns A `MutationTestMetricsResult` that contains both the `systemUnderTestMetrics` as well as the `testMetrics`\n\n### `calculateMetrics` [`(MutationTestResult) => MetricsResult`]\n\nCalculates the files-under-test metrics inside of a mutation testing report.\n\nThe input is a mutation test result valid according to the [https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/report-schema#readme]\n\n### `aggregateResultsByModule` [`(Record<string, MutationTestResult>) => MutationTestResult`]\n\nAggregates multiple reports together into a single report, grouped by module.\n\nInput: `resultsByModule` The MutationTestResult objects by module name.\n\n### Types\n\nTypes are included and documented with TypeScript.\n\n## Use case: merging multiple JSON reports\n\nYou can use this script to merge multiple JSON reports together.\n\n```js\nconst { aggregateResultsByModule } = require('mutation-testing-metrics');\nconst fs = require('fs');\n\nconst packagesRoot = './packages';\nconst reportsPerModule = fs\n  .readdirSync(packagesRoot)\n  .map((pkg) => [pkg, `${packagesRoot}/${pkg}/reports/mutation/mutation.json`])\n  .filter(([, report]) => fs.existsSync(report))\n  .map(([pkg, report]) => [pkg, require(report)])\n  .reduce((acc, [pkg, report]) => {\n    acc[pkg] = report;\n    return acc;\n  }, {});\n\nconst monoReport = aggregateResultsByModule(reportsPerModule);\nfs.writeFileSync('./mono-report.html', reportTemplate(monoReport), 'utf-8');\n\nfunction reportTemplate(report) {\n  const scriptContent = fs.readFileSync(require.resolve('mutation-testing-elements/dist/mutation-test-elements.js'), 'utf-8');\n\n  return `<!DOCTYPE html>\n  <html>\n  <head>\n    <meta charset=\"utf-8\">\n    <script>\n      ${scriptContent}\n    </script>\n  </head>\n  <body>\n    <mutation-test-report-app>\n      Your browser doesn't support <a href=\"https://caniuse.com/#search=custom%20elements\">custom elements</a>.\n      Please use a latest version of an evergreen browser (Firefox, Chrome, Safari, Opera, Edge, etc).\n    </mutation-test-report-app>\n    <script>\n      const app = document.querySelector('mutation-test-report-app');\n      app.report = ${escapeHtmlTags(JSON.stringify(report))};\n      function updateTheme() {\n        document.body.style.backgroundColor = app.theme === 'dark' ? '#222' : '#fff';\n      }\n      app.addEventListener('theme-changed', updateTheme);\n      updateTheme();\n    </script>\n  </body>\n  </html>`;\n}\nfunction escapeHtmlTags(json) {\n  return json.replace(/</g, '<\" + \"');\n}\n```\n","publish_time":1763745271409,"_cnpm_publish_time":1763745271409,"dist-tags":{"latest":"3.9.0"}}