{"name":"mutation-testing-metrics","version":"1.1.1","license":"Apache-2.0","_id":"mutation-testing-metrics@1.1.1","homepage":"https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/mutation-testing-metrics#readme","bugs":{"url":"https://github.com/stryker-mutator/mutation-testing-elements/issues"},"dist":{"shasum":"716b122e7a62d4dfe40543a30c950fc755976de3","tarball":"http://registry-npm.ywwl.com/mutation-testing-metrics/download/mutation-testing-metrics-1.1.1.tgz","fileCount":14,"integrity":"sha512-yO50rOZnTN3yZ3l0iOQ4JC9rFnmC74o50qxPb4FV+dT7werWgh8NILMYADJ6tbGAlRnDnBVpnaHE8AAZzJoVoA==","signatures":[{"sig":"MEUCIQCaPMttkUKtQ01VEJiuC5aqVRVGUjMUJVBU0ltJA04BSAIgPAB9c+C80LVSy9GAQP/IgzE49HTZwOQOGTbO8Srf26c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":24720,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdLCsUCRA9TVsSAnZWagAAl8oP/3Xe7RXIvXJjUn8IhDIs\n77lH3k0DII7q6+3+im0eYHv7n7WbbsavwJORco+Ons+IAJrBh6ewe9XOY+ap\n6FlGF3iagQ8idBxZIyedOM191GGGgY0ULBCiodi/+EF5tIczvt8qRMor/Eab\nKA/+fmKqPvP6xCctD/FKX6LMbsSGHMee1FvQCD8iv+E3N07JIHXDoLtU8Iqo\nK4U/0XrGFrMFkmZNZg+SEfc87cMITTdtvCbSUO6xe8/JjMUhD5v3cR+SUQHs\njRE3/4gmg/1dRLaRu/LEohdA+NenpKXn7vu2RPmhsbMqoeE1Q1Ds/WdHJdrd\nNKiVsQtDu1JOMzIE1bZZxg2pTGT0no14BIhttQyKKuILBfi91KXu+6RhFPZ+\nZC5aYho0j+cAqALJ3muktuJgNGGt4Ak5eoNzvfxBiu8T89Yna0PoQGzSiivl\najeEOgOBixmLyIGRu8CrFh5vrExM8ml0q9LHuWitU9RiyMUPiKR1nUm4Oe6d\nSM3AlNEKy1NVQ/KujY+VVCRFxUEY1sxnkVmygFEwtgtDIbipMtMeK+qOzLjl\nQyN1QytwIlY2THC2lUV7TAD1F94dfHCrdDOhy2zFjKhJdlPDiMR9aoyAwfbr\n268cQFG8wUISWjeEdSJ21SeeqqQYv1N0x2B+M6qWxYMDh/LWAzA0sUWDkB+v\nB6Lv\r\n=sjxP\r\n-----END PGP SIGNATURE-----\r\n","size":7972,"noattachment":false,"key":"/mutation-testing-metrics/-/mutation-testing-metrics-1.1.1.tgz"},"main":"dist/src/index.js","gitHead":"fa77e5b53e66a603b90ba77c457991bbeddc5181","scripts":{"test":"mocha -r source-map-support/register dist/test/**/*.js"},"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/3.15.0/node@v12.6.0+x64 (linux)","description":"Utility functions to calculate mutation testing metrics.","directories":{},"_nodeVersion":"12.6.0","dependencies":{"lodash.groupby":"^4.6.0","mutation-testing-report-schema":"^1.1.1"},"_hasShrinkwrap":false,"devDependencies":{"@types/lodash.groupby":"^4.6.6"},"_npmOperationalInternal":{"tmp":"tmp/mutation-testing-metrics_1.1.1_1563175698776_0.6919722640691219","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":1563175698977,"maintainers":[{"name":"nicojs","email":"jansennico@gmail.com"},{"name":"strykermutator-npa","email":"strykermutator.npa@gmail.com"}],"_cnpm_publish_time":1563175698977,"dist-tags":{"latest":"3.9.0"}}