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

@sap-ux/jest-file-matchers

v0.2.0

Published

Jest matchers for files and folders

Downloads

12

Readme

@sap-ux/jest-file-matchers

Library of jest matchers

Installation

Npm npm install --save @sap-ux/jest-file-matchers

Yarn yarn add @sap-ux/jest-file-matchers

Pnpm pnpm add @sap-ux/jest-file-matchers

Configuration

There are various ways of making the matchers available in your tests.

  1. Setup code in a single file testSetup.[js|ts]:
// ./testSetup.[js|ts]

// Add all the matchers
import * as matchers from '@sap-ux/jest-file-matchers';
expect.extend(matchers);

// Or just add specific matchers
import { toMatchFolder } from '@sap-ux/jest-file-matchers';
expect.extend({ toMatchFolder });

Add the file to your jest config file:

"jest": {
  "setupFilesAfterEnv": ["./testSetup.js"]
}
  1. Call setup code from @sap-ux/jest-file-matchers:
"jest": {
  "setupFilesAfterEnv": ["@sap-ux/jest-file-matchers/dist/setup"]
}

This will make all the matchers available in all your tests.

  1. Extend the expect object only in the files where the matchers are needed:
import { toMatchFolder } from  '@sap/ux-jest-matcher';

expect.extend({ toMatchFolder });

Option 2 is the easiest.

Usage

toMatchFolder()

Import the matchers to get the type definitions loaded:

import '@sap-ux/jest-file-matchers';

expect(folderA).toMatchFolder(snapShotFolderA);

This will perform snapshot tests of the files under folderA. snapShotFolderA contains snapshots of the files as seperate files. Both folders need to be full paths, to be unambiguous.

Use with .not:

import '@sap-ux/jest-file-matchers';

expect(folderA).not.toMatchFolder(snapShotFolderA);

toMatchFolder accepts optional include/exclude filters. These filters are basic minimatch glob patterns. Exclude filters have a higher precedence over include filters, i.e if a file path matches both include and exclude glob patterns, it will be excluded.

Example:

//  Only include Javascript files
expect(folderA).not.toMatchFolder(snapShotFolderA, { include: ['**/.js'] });

//  Only include Javascript files & HTML, exclude setup.js
expect(folderA).not.toMatchFolder(snapShotFolderA, { include: ['**/.js', '**.htm?(l)'], exclude: ['**/setup.js'] });

//  Ignore .DS_Store files
expect(folderA).not.toMatchFolder(snapShotFolderA, { exclude: ['**/.DS_Store'] });

//  Ignore everything in the dist folder
expect(folderA).not.toMatchFolder(snapShotFolderA, { exclude: ['**/dist/**'] });

toMatchFolder uses two other matchers internally. They are also available to be used on their own:

  • toContainAllFilesIn: asserts that the received folder contains all the files the expected folder (matches on filenames only)
  • toMatchFilesIn: asserts that the file contents match the contents of files with the same relative path wrt the snapshot folder.

These two matchers have an identical function signature.

Update snapshots

Pass -u or --update to update the snapshot folder. Please use this with care and verify the contents are actually correct.

Keywords

SAP Fiori Tools