Socket
Socket
Sign inDemoInstall

jest-environment-node

Package Overview
Dependencies
44
Maintainers
6
Versions
272
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-environment-node


Version published
Weekly downloads
24M
decreased by-0.73%
Maintainers
6
Install size
4.83 MB
Created
Weekly downloads
 

Package description

What is jest-environment-node?

The jest-environment-node npm package is a test environment for Jest that simulates a Node.js environment. It is used when testing Node.js specific code. It provides a global environment that's set up for each test file to be executed in a Node-like environment, with all the necessary globals like `process` and `Buffer` available.

What are jest-environment-node's main functionalities?

Simulating Node.js Environment

This configuration in Jest's setup file tells Jest to use the Node environment for testing. It is useful when you want to test code that relies on Node.js APIs.

module.exports = { testEnvironment: 'jest-environment-node' };

Global Setup and Teardown

This feature allows you to extend the Node environment to add custom setup and teardown logic that runs before and after each test suite.

class CustomEnvironment extends NodeEnvironment {
  async setup() {
    await super.setup();
    // Your setup code here
  }

  async teardown() {
    // Your teardown code here
    await super.teardown();
  }
}

Custom Module Mocking

In a Node environment, you can mock Node modules like 'fs' to control their behavior during tests, which is useful for testing code that interacts with the filesystem without actually reading or writing files.

jest.mock('fs', () => ({
  readFileSync: jest.fn().mockReturnValue('mocked content'),
}));

Other packages similar to jest-environment-node

Changelog

Source

28.1.3

Features

  • [jest-leak-detector] Use native FinalizationRegistry when it exists to get rid of external C dependency (#12973)

Fixes

  • [jest-changed-files] Fix a lock-up after repeated invocations (#12757)
  • [@jest/expect-utils] Fix deep equality of ImmutableJS OrderedSets (#12977)
  • [jest-mock] Add index signature support for spyOn types (#13013, #13020)
  • [jest-snapshot] Fix indentation of awaited inline snapshots (#12986)

Chore & Maintenance

  • [*] Replace internal usage of pretty-format/ConvertAnsi with jest-serializer-ansi-escapes (#12935, #13004)
  • [docs] Update spyOn docs (#13000)

FAQs

Last updated on 13 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc