Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
mutation-testing-elements
Advanced tools
A suite of web components for a mutation testing report.
The mutation-testing-elements package is a web component library that provides a user interface for visualizing mutation testing results. Mutation testing is a method of software testing where certain statements in the source code are changed (mutated) to check if the test cases can detect the errors. This package helps in rendering these results in a human-readable format, making it easier to analyze the effectiveness of the test cases.
Rendering Mutation Testing Report
This feature allows you to embed a mutation testing report in a web page. By providing the path to a JSON report generated by a mutation testing tool, the component will render an interactive report that can be explored by users to understand the mutation testing results.
<mutation-test-report-app src='path/to/mutation-report.json'></mutation-test-report-app>
Customizable Themes
The package supports different themes for the report viewer. By setting the 'theme' attribute, users can switch between different visual styles, such as a dark theme, to better suit their preferences or the design of their application.
<mutation-test-report-app theme='dark'></mutation-test-report-app>
Stryker is a mutation testing framework for JavaScript and TypeScript. It provides the core functionality to perform mutation testing, generating reports that can be visualized using mutation-testing-elements. While Stryker focuses on the testing and report generation, mutation-testing-elements is specifically for rendering those reports in a user-friendly way.
A suite of elements designed to display a mutation testing report.
*Note: Please see https://stryker-mutator.io for an introduction to mutation testing.*
The mutation test report supports the following features:
📊 Calculates and displays the mutation score and other metrics
📁 Group results into directories
👓 Show mutants directly in your source code
😎 Code highlighting with Prism
🧙 Filter mutants based on the outcome
🌑 Switch between light and dark theme
🔗 Deep linking using anchors (uses fragment, so path will not be contaminated)
💅 A beautifully crafted UI made with tailwind CSS
🎓 Adheres to custom element best practices
Install with npm:
$ npm install mutation-testing-elements
Add to your page:
<script defer src="mutation-test-elements/dist/mutation-test-elements.js"></script>
Or you can use the unpkg as your CDN:
<script defer src="https://www.unpkg.com/mutation-testing-elements"></script>
Use the mutation-test-report-app
element to load the mutation test report.
<mutation-test-report-app src="mutation-report.json" title-postfix="Mutation Test Report"></mutation-test-report-app>
This loads the report from the source (src
) and displays it.
Alternatively, you can use property binding directly:
<mutation-test-report-app></mutation-test-report-app>
<script>
document.getElementsByTagName('mutation-test-report-app').item(0).report = {
/* ... */
};
</script>
Add this snippet to change the background color of the whole page when the theme is changed from light to dark:
<script>
const app = document.getElementsByTagName('mutation-test-report-app').item(0);
function updateTheme() {
document.body.style.backgroundColor = app.themeBackgroundColor;
}
app.addEventListener('theme-changed', updateTheme);
updateTheme();
</script>
Feel free to use other ways to bind the report
property. For example, you can use <mutation-test-report-app [report]="myReport"></mutation-test-report-app>
to bind report
to the myReport
property in an Angular component.
The mutation testing report data is expected to be in the format of a the mutation-testing-report-schema. Please view that readme to understand the structure.
For some examples, please see the testResources.
src
[string
]Default: undefined
Specify a source to load the mutation testing report from. The source is expected to be in JSON format and adhere to the mutation-testing-report-schema.
report
[object
]Default: undefined
Specify the mutation testing report directly by binding it to this property. It is expected to adhere to the mutation-testing-report-schema.
titlePostfix
[string
]Default: undefined
Specify the postfix to append to the title of the current page. It us reflected as attribute: title-postfix
.
theme
['light' | 'dark'
]Default: user preference (OS setting)
Specify in which theme the report needs to be shown. Possibilities: 'light'
or 'dark'
.
themeBackgroundColor
[string
]Read-only property with the hex code of the background-color from the current theme.
theme-changed
[CustomEvent<{ theme: string, themeBackgroundColor: string }>
]Add an event listener that will raise an event when the theme is changed.
const app = document.querySelector('mutation-test-report-app');
app.addEventListener('theme-changed', (event) => {
console.log('new theme is', event.detail.theme);
console.log('backgroundColor hex is', event.detail.themeBackgroundColor);
// You can also use `app.theme` or `app.themeBackgroundColor` here.
});
These elements are built with LitElement, which uses the Web Components set of standards. They are currently supported by all major browsers with the exception of Edge.
For compatibility with older browsers and Edge, load the Web Components polyfills: https://lit-element.polymer-project.org/guide/use#polyfills
There are unit tests with Vitest (browser mode) and integration tests using playwright. You can run them with npx nx test
or by running npx nx test:unit
or npx nx test:integration
respectively. There is also a launch configuration so you can debug from vscode.
The integration tests also do screenshot comparisons. Currently, they only run when you're running in a headless browser, because the screenshots differ ever so slightly with the snapshots. You can run npm run test:integration:headless
to run locally with screenshot comparison. It will compare and show you a diff file if the diff is deemed to large. Screenshot tests can be updated for your environment with npm run test:integration:update
.
Screenshot snapshots are OS dependent, because, again, the screenshots differ ever so slightly on linux vs windows. You can update the screenshot for both linux and windows by running the "Update screenshots" workflow on your branch (with github). Use with caution always double check the diff before updating!
3.4.0 (2024-11-22)
FAQs
A suite of web components for a mutation testing report.
We found that mutation-testing-elements demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.