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

vitest-fs

v0.1.0

Published

Custom Vitest file system matchers

Downloads

3

Readme

A set of custom Vitest matchers for interactions with the file system.

Usage

Install vitest-fs with your favorite package manager:

$ pnpm add -D vitest-fs

Add a setup file to your Vitest configuration:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    setupFiles: ['tests-setup.ts'],
  },
})

Extends the built-in Vitest matchers with some or all matchers of vitest-fs in your setup file:

import { expect } from 'vitest'

// Use all matchers of `vitest-fs`.
import * as matchers from 'vitest-fs'
expect.extend(matchers)

// Use some matchers of `vitest-fs`.
import { toBeFile, toEqualFile } from 'vitest-fs'
expect.extend({ toBeFile, toEqualFile })

Matchers

toBeDirectory

Asserts that the specified path is a directory.

import { expect, test } from 'vitest'

test('should test if a path is a directory', () => {
  expect('path/to/directory').toBeDirectory()
})

toBeEmptyDirectory

Asserts that the specified path is an empty directory.

import { expect, test } from 'vitest'

test('should test if a path is an empty directory', () => {
  expect('path/to/empty/directory').toBeEmptyDirectory()
})

toBeEmptyFile

Asserts that the specified path is an empty file.

import { expect, test } from 'vitest'

test('should test if a path is an empty file', () => {
  expect('path/to/empty/file').toBeEmptyFile()
})

toBeExecutable

Asserts that the specified path is an executable.

import { expect, test } from 'vitest'

test('should test if a path is an executable', () => {
  expect('path/to/executable').toBeExecutable()
})

toBeFile

Asserts that the specified path is a file.

import { expect, test } from 'vitest'

test('should test if a path is a file', () => {
  expect('path/to/file').toBeFile()
})

toBeJsonFile

Asserts that the specified path is a valid JSON file.

import { expect, test } from 'vitest'

test('should test if a path is a valid JSON file', () => {
  expect('path/to/json/file').toBeJsonFile()
})

toBeSymbolicLink

Asserts that the specified path is a symbolic link.

import { expect, test } from 'vitest'

test('should test if a path is a symbolic link', () => {
  expect('path/to/symbolic/link').toBeSymbolicLink()
})

toEqualDirectory

Asserts that the directory structure of the specified path is equal to another one.

Note Only the directory structures should be equal for this matcher to pass, not the content of the files in the directories.

import { expect, test } from 'vitest'

test('should test if directory structures are the same', () => {
  expect('path/to/directory').toEqualDirectory('path/to/other/directory')
})

toEqualFile

Asserts that a file content is equal to the content of another file.

import { expect, test } from 'vitest'

test('should test if two files are the same', () => {
  expect('path/to/file').toEqualFile('path/to/other/file')
})

You can also remove whitespaces for the assertion.

import { expect, test } from 'vitest'

test('should test if two files are the same with whitespaces removed', () => {
  expect('path/to/file').toEqualFile('path/to/other/file', { removeWhitespaces: true })
})

toEqualFileContent

Asserts that a file content is equal to a specific content.

import { expect, test } from 'vitest'

test('should test if a file content is equal to a specific content', () => {
  expect('path/to/file').toEqualFileContent('file content')
})

You can also remove whitespaces for the assertion.

import { expect, test } from 'vitest'

test('should test if a file content is equal to a specific content with whitespaces removed', () => {
  expect('path/to/file').toEqualFileContent('filecontent', { removeWhitespaces: true })
})

toEqualJsonFile

Asserts that a JSON file is equal to another JSON file.

import { expect, test } from 'vitest'

test('should test if two JSON files are the same', () => {
  expect('path/to/json/file').toEqualJsonFile('path/to/other/json/file')
})

toEqualJsonFileContent

Asserts that a JSON file is equal to a specific JSON content.

import { expect, test } from 'vitest'

test('should test if two files are the same', () => {
  expect('path/to/file').toEqualJsonFileContent({ key: 'value' })
})

License

Licensed under the MIT License, Copyright © HiDeoo.

See LICENSE for more information.