yhtml5-test is a front-end test framework designed to simplify unit testing in JavaScript projects, primarily by wrapping and pre-configuring Jest. It aims to reduce the boilerplate and configuration overhead typically associated with setting up a modern testing environment, abstracting away direct interactions with tools like Babel, Node, and Jest itself. The framework includes built-in polyfills, sophisticated file transformers for JavaScript, CSS, and other assets, and a pre-configured environment to simulate browser APIs. It supports testing React components through its integration with Enzyme and `react-test-renderer` (specifically v15.6.x and v2.9.x respectively, as shown in the quickstart). Key features include robust coverage reporting, snapshot testing capabilities, and an opinionated structure for test case organization. Currently at version 1.2.2, its release cadence is not explicitly stated but relies on updates to the underlying `@2dfire/2dfire-scripts` package. It differentiates itself by providing a batteries-included setup focused on immediate productivity for detecting bugs, identifying unused code, and ensuring code quality.
npm install yhtml5-testVerified import paths — ran on the pinned version, not inferred.
This quickstart guides you through setting up `yhtml5-test` by adding required scripts to `package.json`, installing development dependencies, configuring `.config.js` for Jest and Webpack aliases, and writing a basic React component test using Enzyme and snapshot testing.
For React 16+ projects, upgrade `enzyme` to v3.x and install a compatible React adapter (e.g., `enzyme-adapter-react-16`). You may also need to update `@2dfire/2dfire-scripts`.
Ensure your `.config.js` file correctly uses `module.exports = config` to expose its configuration object.
Modify the `transformIgnorePatterns` regex in your `.config.js` to explicitly include specific `node_modules` packages that need Babel processing.
Adhere to standard Jest conventions (`__tests__/**/*.js?(x)`, `*.test.js`, `*.spec.js`), or adjust the `testMatch` array in your `.config.js` to match your project's structure.
Always ensure `@2dfire/2dfire-scripts` is installed as a `devDependency` and refer to its documentation for deeper configuration or troubleshooting.
Ensure `regenerator-runtime` is installed (`npm i regenerator-runtime -D`) and imported in your Jest `setupFiles` (e.g., `import 'regenerator-runtime/runtime';`) or configure Babel to include `@babel/plugin-transform-runtime`.
Modify the `transformIgnorePatterns` array in your `.config.js` to explicitly include the problematic `node_modules` package for Babel transformation.
Verify that your `moduleNameMapper` in `.config.js` accurately reflects your Webpack aliases, mapping them to the correct absolute paths.
Update `react-test-renderer` and `enzyme` to versions compatible with your project's React major version (e.g., `enzyme@3.x` with `enzyme-adapter-react-16` for React 16+), and ensure the adapter is configured in `setupTestFrameworkScriptFile`.