@ms-cloudpack/jest-path-snapshot
TypeScript icon, indicating that this package has built-in type declarations

0.1.98 • Public • Published

@ms-cloudpack/jest-path-snapshot

Allows file trees and content to be written in jest snapshots.

Usage

Initialize it in your test file:

import { pathSnapshotSerializer, fsPath } from '@ms-cloudpack/jest-path-snapshot';

expect.addSnapshotSerializer(pathSnapshotSerializer(options));

Then use in your tests by wrapping your path in the fsPath helper and using the ordinary Jest snapshot api:

const someOutputPath = path.join(os.tmpdir(), 'my-stuff');

describe('file-thing', () => {
  it('writes to the disk', () => {
    fileThing(someOutputPath);
    // wrap your string path in fsPath to identify it as a serialized path.
    expect(fsPath(someOutputPath)).toMatchInlineSnapshot();
  });
});

Example output:

Folder contents of "test-project":
a/
├─ c/
│  └─ test-json.json
└─ test-png.png
b/
├─ test-ts.ts
└─ test-tsx.tsx
test-txt.txt

a/c/test-json.json:
------------------
{}

b/test-ts.ts:
------------
'ts';

b/test-tsx.tsx:
--------------
'tsx';

test-txt.txt:
------------
txt

Options

Name Type Default Description
includeSourceMatches string[] '**/*.{txt,?([cm])[jt]s?(x),json}' Array of globs to include contents in the snapshot (does not impact the path hierarchy tree).
excludeSourceMatches string[] Array of globs to exclude from snapshot, despite matching includeSourceMatches (does not impact the path hierarchy tree).

Readme

Keywords

none

Package Sidebar

Install

npm i @ms-cloudpack/jest-path-snapshot

Weekly Downloads

22

Version

0.1.98

License

MIT

Unpacked Size

20.2 kB

Total Files

23

Last publish

Collaborators

  • ecraig12345_msft
  • uifabricteam
  • dzearing