HTML-Validate jest preset.
Jest is configured to:
- Run tests from
*.spec.[jt]s
. - Collect coverage from
.js
and.ts
insrc
and ignore tests (**/*.spec.[jt]s
) and index (**/index.[jt]s
). - Report results as junit in
temp/jest.xml
. - Transform typescript with
ts-jest
. - Transform js with
babel-jest
if babel is detected. - Ignores spec-files from Cypress.
npm install --save-dev @html-validate/jest-config
In your package.json
file:
{
"jest": {
"preset": "@html-validate/jest-config"
}
}
Preset | Description |
---|---|
@html-validate/jest-config | Alias for presets/default |
@html-validate/jest-config/presets/default | Default preset |
@html-validate/jest-config/presets/esm | Experimental ESM support |
If you need to import and use ESM-only libraries you need to install @babel/core. You do not need a
babel.config.jsor
.babelrcas the preset passes the required configuration directly to
babel-jest`.
npm install --save-dev @babel/core
When babel is detect the preset sets transformIgnorePatterns
to transpile everything under node_modules
.
You can include a more specific list of packages to transform (potential speed gain) by manually setting transformIgnorePatterns
:
Optionally you can set transformIgnorePatterns
in package.json
:
{
"jest": {
"preset": "@html-validate/jest-config",
+ "transformIgnorePatterns": ["node_modules/(?!(foo|bar|baz)/)"]
}
}
This will transform only the foo
, bar
and baz
packages.
Importing *.html
is supported by jest configuration but requires additional typescript config by creating a declaration:
shim-html.d.ts
:
declare module "*.html" {
const value: string;
export default value;
}
This preset searches the project folder for typescript configuration in the following order:
tsconfig.jest.json
tsconfig.json