@happy-dom/jest-environment 13.8.6 → 13.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +43 -120
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,144 +1,67 @@
1
1
  ![Happy DOM Logo](https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg)
2
2
 
3
- # About
4
-
5
- [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/).
6
-
7
- 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.
8
-
9
- [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).
10
-
11
3
  This package makes it possible to use [Happy DOM](https://github.com/capricorn86/happy-dom) with [Jest](https://jestjs.io/).
12
4
 
13
- ### DOM Features
14
-
15
- - Custom Elements (Web Components)
16
-
17
- - Shadow Root (Shadow DOM)
18
-
19
- - Declarative Shadow DOM
20
-
21
- - Mutation Observer
5
+ ## Installation
22
6
 
23
- - Tree Walker
24
-
25
- - Fetch
7
+ ```bash
8
+ npm install @happy-dom/jest-environment --save-dev
9
+ ```
26
10
 
27
- And much more..
11
+ ## Setup
28
12
 
29
- ### Works With
13
+ 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.
30
14
 
31
- - [Google LitHTML](https://lit-html.polymer-project.org)
15
+ #### CLI
32
16
 
33
- - [Google LitElement](https://lit-element.polymer-project.org)
17
+ When calling the "jest" command, add `--env=@happy-dom/jest-environment` as an attribute.
34
18
 
35
- - [React](https://reactjs.org)
19
+ ```bash
20
+ jest --env=@happy-dom/jest-environment
21
+ ```
36
22
 
37
- - [Angular](https://angular.io/)
23
+ #### Package.json
38
24
 
39
- - [Vue](https://vuejs.org/)
25
+ It is possible to add your Jest config to your `package.json`.
40
26
 
41
- ### Module Systems
27
+ ```json
28
+ {
29
+ "jest": {
30
+ "testEnvironment": "@happy-dom/jest-environment"
31
+ }
32
+ }
33
+ ```
42
34
 
43
- - [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules) (ESM is not supported due to limitations with Jest)
35
+ #### Jest Config File
44
36
 
45
- # Installation
37
+ When using a Jest config file (usually jest.config.js), add the snippet below to it.
46
38
 
47
- ```bash
48
- npm install @happy-dom/jest-environment --save-dev
39
+ ```json
40
+ {
41
+ "testEnvironment": "@happy-dom/jest-environment"
42
+ }
49
43
  ```
50
44
 
51
- # Setup
45
+ ## Options
52
46
 
53
- 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.
47
+ 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/).
54
48
 
55
- ## CLI
56
-
57
- 1. Edit your "package.json" file.
58
- 2. Add "--env=@happy-dom/jest-environment" as an attribute to your Jest command.
59
-
60
- ```json
61
- {
62
- "scripts": {
63
- "test": "jest --env=@happy-dom/jest-environment"
64
- }
65
- }
66
- ```
67
-
68
- 3. Save the file.
69
-
70
- ## In "package.json"
71
-
72
- 1. Edit your "package.json" file.
73
- 2. Add the following to it:
74
-
75
- ```json
76
- {
77
- "jest": {
78
- "testEnvironment": "@happy-dom/jest-environment",
79
- "testEnvironmentOptions": {
80
- "url": "http://localhost",
81
- "width": 1920,
82
- "height": 1080,
83
- "settings": {
84
- "navigator": {
85
- "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
86
- }
87
- }
49
+ ```json
50
+ {
51
+ "testEnvironment": "@happy-dom/jest-environment",
52
+ "testEnvironmentOptions": {
53
+ "url": "http://localhost",
54
+ "width": 1920,
55
+ "height": 1080,
56
+ "settings": {
57
+ "navigator": {
58
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
88
59
  }
89
60
  }
90
- }
91
- ```
92
-
93
- 3. Save the file.
94
-
95
- ## Configuration File
96
-
97
- 1. Edit your Jest config file (usually jest.config.js)
98
- 2. Add the following to it:
99
-
100
- ```json
101
- {
102
- "testEnvironment": "@happy-dom/jest-environment",
103
- "testEnvironmentOptions": {
104
- "url": "http://localhost",
105
- "width": 1920,
106
- "height": 1080,
107
- "settings": {
108
- "navigator": {
109
- "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
110
- }
111
- }
112
- }
113
- }
114
- ```
115
-
116
- 3. Save the file.
117
-
118
- # Documentation
119
-
120
- Read more about how Happy DOM works in our [documentation](https://github.com/capricorn86/happy-dom/wiki).
121
-
122
- # Performance
123
-
124
- | Operation | JSDOM | Happy DOM |
125
- | ------------------------------------ | ------- | --------- |
126
- | Import / Require | 333 ms | 45 ms |
127
- | Parse HTML | 256 ms | 26 ms |
128
- | Serialize HTML | 65 ms | 8 ms |
129
- | Render custom element | 214 ms | 19 ms |
130
- | querySelectorAll('tagname') | 4.9 ms | 0.7 ms |
131
- | querySelectorAll('.class') | 6.4 ms | 3.7 ms |
132
- | querySelectorAll('[attribute]') | 4.0 ms | 1.7 ms |
133
- | querySelectorAll('[class~="name"]') | 5.5 ms | 2.9 ms |
134
- | querySelectorAll(':nth-child(2n+1)') | 10.4 ms | 3.8 ms |
135
-
136
- See how the test was done [here](https://github.com/capricorn86/happy-dom-performance-test)
137
-
138
- # Sister Projects
139
-
140
- [<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)
61
+ }
62
+ }
63
+ ```
141
64
 
142
- # Sponsors
65
+ ## Happy DOM
143
66
 
144
- [<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com)
67
+ [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/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happy-dom/jest-environment",
3
- "version": "13.8.6",
3
+ "version": "13.10.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment",
6
6
  "repository": "https://github.com/capricorn86/happy-dom",
@@ -50,7 +50,7 @@
50
50
  "@jest/environment": "^29.4.0",
51
51
  "@jest/fake-timers": "^29.4.0",
52
52
  "@jest/types": "^29.4.0",
53
- "happy-dom": "^13.8.6",
53
+ "happy-dom": "^13.10.0",
54
54
  "jest-mock": "^29.4.0",
55
55
  "jest-util": "^29.4.0"
56
56
  },