Gathering detailed insights and metrics for @curefatih-jf/jest-environment
Gathering detailed insights and metrics for @curefatih-jf/jest-environment
npm install @curefatih-jf/jest-environment
Typescript
Module System
Node Version
NPM Version
TypeScript (99.37%)
JavaScript (0.63%)
Total Downloads
792
Last Day
1
Last Week
2
Last Month
7
Last Year
111
3,492 Stars
2,120 Commits
210 Forks
13 Watching
3 Branches
124 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
32
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.
Custom Elements (Web Components)
Shadow Root (Shadow DOM)
Declarative Shadow DOM
Mutation Observer
Tree Walker
Fetch
And much more..
1npm install @happy-dom/jest-environment --save-dev
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.
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.
Edit your "package.json" file.
Add the following to it:
1{ 2 "jest": { 3 "testEnvironment": "@happy-dom/jest-environment" 4 } 5}
Save the 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.
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});
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
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 6
Details
Reason
Found 12/29 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
6 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
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