Shared jest configuration for Obsidian plugins: defineObsidianPluginJestConfig, the jest counterpart of defineObsidianPluginVitestConfig’s unit-tests project.
It is the generic defineJestConfig from @mnaoumov/typescript-dev-toolkit plus what a plugin’s unit tests need on top: the jsdom environment, obsidian resolved onto obsidian-test-mocks (the obsidian npm package carries types only), the two per-test setup files, and the integration tests left to their own runner. A plugin runs it with test / testCoverage / testWatch from @mnaoumov/typescript-dev-toolkit/test-runners/auto, which picks jest whenever a jest configuration file exists.
| Function |
Description |
| defineObsidianPluginJestConfig |
Defines an Obsidian plugin’s jest configuration. On top of defineJestConfig‘s defaults: the jsdom environment (the mocks’ setup writes to Document.prototype, Element.prototype and window), obsidian mapped onto obsidian-test-mocks/obsidian, the OBSIDIAN_JEST_SETUP_FILES_AFTER_ENV setup files and *.integration.test.ts left out. Every jest option in options replaces its default, except moduleNameMapper, whose entries are added to the obsidian one, and setupFilesAfterEnv and testPathIgnorePatterns, whose entries are appended to this function’s own. The jsdom environment needs jest-environment-jsdom installed beside jest and ts-jest. |
| Variable |
Description |
| OBSIDIAN_JEST_INTEGRATION_TEST_PATH_IGNORE_PATTERN |
The integration tests, which run in a real Obsidian through obsidian-integration-testing and never under jest. |
| OBSIDIAN_JEST_MODULE_NAME_MAPPER |
Resolves obsidian onto the mocks, as the vitest configuration’s obsidian alias does. |
| OBSIDIAN_JEST_SETUP_FILES_AFTER_ENV |
The per-test setup files, in the order the vitest configuration loads them: the mocks’ globals and mocked app first, then this package’s reset of the shared state before each test. They go in setupFilesAfterEnv, not setupFiles, because this package’s setup registers beforeEach and afterEach hooks, which exist only once the test framework is installed. |