@happy-dom/jest-environment
Advanced tools
Comparing version 13.8.6 to 13.9.0
{ | ||
"name": "@happy-dom/jest-environment", | ||
"version": "13.8.6", | ||
"version": "13.9.0", | ||
"license": "MIT", | ||
@@ -53,3 +53,3 @@ "homepage": "https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment", | ||
"@jest/types": "^29.4.0", | ||
"happy-dom": "^13.8.6", | ||
"happy-dom": "^13.9.0", | ||
"jest-mock": "^29.4.0", | ||
@@ -56,0 +56,0 @@ "jest-util": "^29.4.0" |
159
README.md
![Happy DOM Logo](https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg) | ||
# About | ||
[Happy DOM](https://github.com/capricorn86/happy-dom) is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG [DOM](https://dom.spec.whatwg.org/) and [HTML](https://html.spec.whatwg.org/multipage/). | ||
The goal of [Happy DOM](https://github.com/capricorn86/happy-dom) is to emulate enough of a web browser to be useful for testing, scraping web sites and server-side rendering. | ||
[Happy DOM](https://github.com/capricorn86/happy-dom) focuses heavily on performance and can be used as an alternative to [JSDOM](https://github.com/jsdom/jsdom). | ||
This package makes it possible to use [Happy DOM](https://github.com/capricorn86/happy-dom) with [Jest](https://jestjs.io/). | ||
### DOM Features | ||
## Installation | ||
- Custom Elements (Web Components) | ||
- Shadow Root (Shadow DOM) | ||
- Declarative Shadow DOM | ||
- Mutation Observer | ||
- Tree Walker | ||
- Fetch | ||
And much more.. | ||
### Works With | ||
- [Google LitHTML](https://lit-html.polymer-project.org) | ||
- [Google LitElement](https://lit-element.polymer-project.org) | ||
- [React](https://reactjs.org) | ||
- [Angular](https://angular.io/) | ||
- [Vue](https://vuejs.org/) | ||
### Module Systems | ||
- [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules) (ESM is not supported due to limitations with Jest) | ||
# Installation | ||
```bash | ||
@@ -51,95 +11,58 @@ npm install @happy-dom/jest-environment --save-dev | ||
# Setup | ||
## Setup | ||
Jest uses `node` as test environment by default. In order to tell Jest to use a different environment we will either have to set a CLI attribute, define it in "package.json" or add a property to your Jest config file. | ||
## CLI | ||
#### CLI | ||
1. Edit your "package.json" file. | ||
2. Add "--env=@happy-dom/jest-environment" as an attribute to your Jest command. | ||
When calling the "jest" command, add `--env=@happy-dom/jest-environment` as an attribute. | ||
```json | ||
{ | ||
"scripts": { | ||
"test": "jest --env=@happy-dom/jest-environment" | ||
} | ||
} | ||
``` | ||
```bash | ||
jest --env=@happy-dom/jest-environment | ||
``` | ||
3. Save the file. | ||
#### Package.json | ||
## In "package.json" | ||
It is possible to add your Jest config to your `package.json`. | ||
1. Edit your "package.json" file. | ||
2. Add the following to it: | ||
```json | ||
{ | ||
"jest": { | ||
"testEnvironment": "@happy-dom/jest-environment" | ||
} | ||
} | ||
``` | ||
```json | ||
{ | ||
"jest": { | ||
"testEnvironment": "@happy-dom/jest-environment", | ||
"testEnvironmentOptions": { | ||
"url": "http://localhost", | ||
"width": 1920, | ||
"height": 1080, | ||
"settings": { | ||
"navigator": { | ||
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
#### Jest Config File | ||
3. Save the file. | ||
When using a Jest config file (usually jest.config.js), add the snippet below to it. | ||
## Configuration File | ||
```json | ||
{ | ||
"testEnvironment": "@happy-dom/jest-environment" | ||
} | ||
``` | ||
1. Edit your Jest config file (usually jest.config.js) | ||
2. Add the following to it: | ||
## Options | ||
```json | ||
{ | ||
"testEnvironment": "@happy-dom/jest-environment", | ||
"testEnvironmentOptions": { | ||
"url": "http://localhost", | ||
"width": 1920, | ||
"height": 1080, | ||
"settings": { | ||
"navigator": { | ||
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" | ||
} | ||
It is possible to send in Happy DOM [Browser Settings](https://github.com/capricorn86/happy-dom/wiki/IOptionalBrowserSettings) as environment options to [Jest](https://jestjs.io/). | ||
```json | ||
{ | ||
"testEnvironment": "@happy-dom/jest-environment", | ||
"testEnvironmentOptions": { | ||
"url": "http://localhost", | ||
"width": 1920, | ||
"height": 1080, | ||
"settings": { | ||
"navigator": { | ||
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" | ||
} | ||
} | ||
} | ||
``` | ||
} | ||
} | ||
``` | ||
3. Save the file. | ||
## Happy DOM | ||
# Documentation | ||
Read more about how Happy DOM works in our [documentation](https://github.com/capricorn86/happy-dom/wiki). | ||
# Performance | ||
| Operation | JSDOM | Happy DOM | | ||
| ------------------------------------ | ------- | --------- | | ||
| Import / Require | 333 ms | 45 ms | | ||
| Parse HTML | 256 ms | 26 ms | | ||
| Serialize HTML | 65 ms | 8 ms | | ||
| Render custom element | 214 ms | 19 ms | | ||
| querySelectorAll('tagname') | 4.9 ms | 0.7 ms | | ||
| querySelectorAll('.class') | 6.4 ms | 3.7 ms | | ||
| querySelectorAll('[attribute]') | 4.0 ms | 1.7 ms | | ||
| querySelectorAll('[class~="name"]') | 5.5 ms | 2.9 ms | | ||
| querySelectorAll(':nth-child(2n+1)') | 10.4 ms | 3.8 ms | | ||
See how the test was done [here](https://github.com/capricorn86/happy-dom-performance-test) | ||
# Sister Projects | ||
[<img alt="Happy Conventional Commit" width="120px" src="https://raw.githubusercontent.com/capricorn86/happy-conventional-commit/main/docs/logo_thumbnail.jpg" />](https://github.com/capricorn86/happy-conventional-commit) | ||
# Sponsors | ||
[<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com) | ||
[Documentation](https://github.com/capricorn86/happy-dom/wiki/) | [Getting Started](https://github.com/capricorn86/happy-dom/wiki/Getting-started) | [Setup as Test Environment](https://github.com/capricorn86/happy-dom/wiki/Setup-as-Test-Environment) | [GitHub](https://github.com/capricorn86/happy-dom/) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28386
67
Updatedhappy-dom@^13.9.0