{"name":"mutation-testing-metrics","version":"1.7.4","license":"Apache-2.0","_id":"mutation-testing-metrics@1.7.4","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"},"dist":{"shasum":"27d42aeeb2bd54650b8c20f1f0b5a45222a9c43f","tarball":"http://registry-npm.ywwl.com/mutation-testing-metrics/download/mutation-testing-metrics-1.7.4.tgz","fileCount":36,"integrity":"sha512-OLXiu419XwYWdUOh8UtteJ3mh6qWhftimWzBrbi+PhaPnEnGx9GTdWSRsE8Ub5Y3PP94GQgyhSalKJaj50YXaw==","signatures":[{"sig":"MEYCIQC22mrEwn5x/IXsYV6tS3HoandaIMzMYYoDo6IDze2jmQIhAMe6yGo91f7rKxFwvlWgBYtie5VCGWjVArpPbJHjOqfZ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":54718,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg7Zh3CRA9TVsSAnZWagAALHMP/iarOysN6LrAYllT855m\nB9lJlZraI+KhEbsTZhE0B3IqE63wbYlbxSXJnbCsddY/UVBAa6z3dRKouWJO\nsrhkBz+An2CyH8+sHviLB0/jW/ZC5JNr2Y2AHKEhlxSbjjWqdd7v4ATPSPca\nEslDZz+iBO6Aayj9VRBiF/4uLnF7D0H6HISN0PyKlYius+ryFapn7C60qyM+\nAb6hmFZ1sK840O1E9tYzLNojPM8cOFdR5vdpwCq24ie9fjqbkohZ7xMUTGnv\n2oYjYXc3x9gKJGHZqGRe9sZ3dUOi8+oJizHoIvAEjozrhygSui4jNOpMclwr\nFuENtc/cDQCjkXXCtGAEPrH/a+PhZsiJ7ZNOaD3OWdBwl9hPM0nvf2YvTXSb\nEgFN19Kz3dtEUlchpaf2Gs8BD4s6cIMxWTbQCz5IuzhZ9Zha7KDiX3fCMJ+j\nlb04l86PBiM+auggPXeJXeksuMsPS+Of9POf1p2AkkWTV0m+Rn8yJUdk25z0\nPryh0Wzfzv6cvvfZOkV5JZ+/a/8NPfZBQcJUefDEnREbSOeVzzNkhR6muJdW\nVg6+jQvb4oxJ7TWvErbmh+JqKjwmzhIMV8J9l/A6OSlRT62vpRQuz4pbIVDu\nq3GZtxHsqYIvjXYMKU7ZQ13pCLYC6VBsVdKKtKtZyg316dND2TJY3xWkMHt9\n/CSJ\r\n=yShb\r\n-----END PGP SIGNATURE-----\r\n","size":14697,"noattachment":false,"key":"/mutation-testing-metrics/-/mutation-testing-metrics-1.7.4.tgz"},"main":"dist/src/index.js","gitHead":"6efdfe3d48712ff800bc096c8d1c22756185c464","scripts":{"test":"mocha --forbid-only --forbid-pending -r source-map-support/register dist/test/**/*.js","stryker":"stryker run"},"typings":"dist/src/index.d.ts","_npmUser":{"name":"strykermutator-npa","email":"strykermutator.npa@gmail.com"},"repository":{"url":"git+https://github.com/stryker-mutator/mutation-testing-elements.git","type":"git"},"_npmVersion":"lerna/4.0.0/node@v14.17.1+x64 (linux)","description":"Utility functions to calculate mutation testing metrics.","directories":{},"_nodeVersion":"14.17.1","dependencies":{"mutation-testing-report-schema":"1.7.4"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mutation-testing-metrics_1.7.4_1626183798715_0.5302446616550525","host":"s3://npm-registry-packages"},"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":1626183798838,"maintainers":[{"name":"nicojs","email":"jansennico@gmail.com"},{"name":"strykermutator-npa","email":"strykermutator.npa@gmail.com"}],"_cnpm_publish_time":1626183798838,"dist-tags":{"latest":"3.9.0"}}