Socket
Socket
Sign inDemoInstall

@raegen/vite-plugin-vitest-cache

Package Overview
Dependencies
6
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@raegen/vite-plugin-vitest-cache

Run Vitest with test result caching.


Version published
Maintainers
0
Created

Readme

Source

vite-plugin-vitest-cache npm (vCache)

vitest-cache-example

[!NOTE] In vitest terms, the caching covers: transformation, setup, collection, running, environment and preparation of tests. All of those are skipped for cached entries.

Vitest cache provides test caching for Vitest. This vite plugin is useful for running non-trivial, complex, resource-intensive, or otherwise slow tests, as it enables running only the tests that are actually affected by code changes.

How it Works

It uses the same toolkit used for building your sources to build the test files. Hashes of these files are then used for cache matching. When running the tests, only the test files without a cache-hit (test files affected by the latest code changes for example) are run, the rest are simply restored from cache.

Installation

npm install --save-dev @raegen/vite-plugin-vitest-cache
yarn add --dev @raegen/vite-plugin-vitest-cache

Usage

import { defineConfig } from "vitest";
import vitestCache from '@raegen/vite-plugin-vitest-cache';

export default defineConfig({
  plugins: [vitestCache()],
});

Usage with CI

The only potential obstacle here, is cache persistence across runs, contexts. Since we use filesystem for cache storage, it's just a matter of configuring the respective CI cache to include the paths used by vCache (See dir).

Github Actions
jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: vCache
      id: v-cache
      uses: actions/cache@v4
      with:
        path: **/.tests
        key: v-cache

    - name: Test
      run: ...run tests
Gitlab CI/CD
job:
  script: ...run tests
  artifacts:
    name: v-cache
    paths:
      - **/.tests

Options

dir

Control where the caches are saved.

@default ".tests" (relative to the project root)

vitestCache({ dir: ".tests" });

states

Control which result states to cache. Possible values are "pass" and "fail".

@default ["pass"]

vitestCache({ states: ["pass"] });

silent

Control whether vCache should write any logs to stdout.

@default false

vitestCache({ silent: true });

Note

[!CAUTION] The purpose of this plugin is not to promote what are ultimately bad test practices. Your unit tests should NOT be non-trivial, complex, resource-intensive, or otherwise slow. If you find yourself in need of such tests, first and foremost evaluate whether unit testing is what you need and look into integration, E2E testing etc.

Keywords

FAQs

Last updated on 11 Jul 2024

Did you know?

Socket

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc