Installations
npm install @curefatih-jf/jest-environment
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.13.0
NPM Version
lerna/4.0.0/node@v16.13.0+x64 (darwin)
Releases
Contributors
Languages
TypeScript (99.37%)
JavaScript (0.63%)
Developer
capricorn86
Download Statistics
Total Downloads
792
Last Day
1
Last Week
2
Last Month
7
Last Year
111
GitHub Statistics
3,492 Stars
2,120 Commits
210 Forks
13 Watching
3 Branches
124 Contributors
Bundle Size
759.21 kB
Minified
299.52 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.3
Package Id
@curefatih-jf/jest-environment@0.1.3
Unpacked Size
29.76 kB
Size
9.60 kB
File Count
26
NPM Version
lerna/4.0.0/node@v16.13.0+x64 (darwin)
Node Version
16.13.0
Total Downloads
Cumulative downloads
Total Downloads
792
Last day
-80%
1
Compared to previous day
Last week
-60%
2
Compared to previous week
Last month
133.3%
7
Compared to previous month
Last year
-54.5%
111
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
32
About
Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.
The goal of Happy DOM is to emulate enough of a web browser to be useful for testing, scraping web sites and server-side rendering.
Happy DOM focuses heavily on performance and can be used as an alternative to JSDOM.
This package makes it possible to use Happy DOM with Jest.
DOM Features
-
Custom Elements (Web Components)
-
Shadow Root (Shadow DOM)
-
Declarative Shadow DOM
-
Mutation Observer
-
Tree Walker
-
Fetch
And much more..
Works With
Installation
1npm install @happy-dom/jest-environment --save-dev
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
-
Edit your "package.json" file.
-
Add "--env=@happy-dom/jest-environment" as an attribute to your Jest command.
1{ 2 "scripts": { 3 "test": "jest --env=@happy-dom/jest-environment" 4 } 5}
-
Save the file.
In "package.json"
-
Edit your "package.json" file.
-
Add the following to it:
1{ 2 "jest": { 3 "testEnvironment": "@happy-dom/jest-environment" 4 } 5}
-
Save the file.
Configuration File
-
Edit your Jest config file (usually jest.config.js)
-
Add the following to it:
1{ 2 "testEnvironment": "@happy-dom/jest-environment" 3}
-
Save the file.
Additional Features
Happy DOM exposes two functions that may be useful when testing asynchrounous code.
whenAsyncComplete()
Returns a Promise that is resolved when all async tasks has been completed.
1describe('scrollToTop()', () => { 2 it('scrolls to top using the built in browser animation', async () => { 3 element.scrollToTop(); 4 5 // Waits for asynchronous tasks like setTimeout(), requestAnimationFrame() etc. to complete 6 await happyDOM.whenAsyncComplete(); 7 8 expect(document.documentElement.scrollTop).toBe(0); 9 }); 10});
cancelAsync()
This method will cancel all running async tasks.
1describe('runAnimation()', () => { 2 it('runs animation', () => { 3 element.runAnimation(); 4 5 // Cancels all asynchronous tasks like setTimeout(), requestAnimationFrame() etc. 6 happyDOM.cancelAsync(); 7 8 expect(element.animationCompleted).toBe(true); 9 }); 10});
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 |
No vulnerabilities found.
Reason
30 commit(s) and 18 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool is not run on all commits -- score normalized to 6
Details
- Warn: 18 commits out of 30 are checked with a SAST tool
Reason
Found 12/29 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/pull_request.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:87: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:129: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:135: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:140: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:159: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/capricorn86/happy-dom/release.yml/master?enable=pin
- Info: 0 out of 16 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 4 out of 4 npmCommand dependencies pinned
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-96g7-g7g9-jxw8
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/auto-assign.yml:1
- Warn: no topLevel permission defined: .github/workflows/pull_request.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More