npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-environment-obsidian

v0.0.1

Published

A Jest environment to facilitate unit testing for Obsidian plugins.

Downloads

12

Readme

jest-environment-obsidian

Obsidian Version Supported: v1.1.16 NPM Downloads MIT License Checks

A Jest environment to facilitate unit testing for Obsidian plugins.

Notice:
This project is a work-in-progress.

Obsidian's API is fairly large, and it will take time to implement all of it in a test-friendly way. If some function doesn't work, please open an issue or pull request.

Installation

This package is available on the npm registry. You can install it using npm or yarn.

npm install --save-dev jest-environment-obsidian

Requirements

These are the minimum requirements that we test for. You may have luck with earlier versions of the required software, but we won't be able to provide support for it.

  • NodeJS >= 15.0.0
  • Jest >= 29.0.0

Usage

There are two ways to use jest-environment-obsidian in your project: for all unit tests, or for specific unit test files. If you're not sure about what you want to do, you can see our examples for inspiration.

For All Tests

If you want to use jest-environment-obsidian for all your unit tests, you can use jest-environment-obsidian as a preset. This will add the required setup files and module resolver.

module.exports = {
	// ...
	preset: 'jest-environment-obsidian',
};

If you want to provide your own configuration on top of jest-environment-obsidian's preset, we recommend using the extend function provided in our preset:

const { extend } = require('jest-environment-obsidian/jest-preset');
module.exports = extend({
	setupFiles: ['...'],
});

For Individual Tests

If you only want to test a specific files under the jest-environment-obsidian environment, you can add a multi-line pragma comment at the top your unit test file:

/**
 * @jest-environment jest-environment-obsidian
 */

Features

Obsidian's Prototype Extensions

Obsidian adds custom functions and properties to existing DOM and ECMAScript types. These have been reimplemented under jest-environment-obsidian and are available within unit tests.

Obsidian Module

The Obsidian module is automatically shimmed for you. While it's still good practice to isolate code, as long as you use jest-environment-obsidian, having import {...} from "obsidian" in source files no longer prevents unit tests from running.

Warnings

As a way to help with test-driven-development and identify why certain unit tests may be failing, jest-environment-obsidian creates and prints warning messages after running tests.

Individual warnings can be disabled by adding a @obsidian-jest-ignore node-must-be-within-document <warningName> pragma comment in a file. Multiple comments can be added to disable different warnings.

Configuration

The test environment can be configured globally with the testEnvironmentOptions option inside your Jest config, or on a per-file basis using one of the supported doc block pragmas.

conformance

Configures how strictly the test environment tries to conform to Obsidian's implementation of its API.

When set to strict, certain functions and behaviours will work as though they were running within the real Obsidian environment. As a consequence, more boilerplate code will be needed for certain unit tests to pass.

Pragma: @obsidian-conformance
Options: "lax", "strict"
Default: "lax"

version

Configures the reported apiVersion inside the obsidian module.

Pragma: @obsidian-version
Options: string
Default: 1.1.16

ignoreWarnings

Disables printing of specific warning messages.

Pragma: @obsidian-jest-ignore
Options: A string array of warning IDs, or a single string ID if within a pragma comment.
Default: []

missingExports

Changes how jest-environment-obsidian handles missing exports from shimmed modules. By default, a warning will be emitted to let you know that your tests may behave unexpectedly.

Options: "warning", "error", "undef"
Default: "warning"

Contributing

Want to help out? Check out the contributing guide!