0.5.0 • Published 4 months ago

@ms-cloudpack/test-utilities v0.5.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@ms-cloudpack/test-utilities

Utilities for testing libraries within the Cloudpack repo.

APIs

createTempDir(options)

Creates a temporary directory and returns the normalized path.

This directory should be deleted automatically when the program exits, but it's more reliable to include manual cleanup in your code.

Options:

  • prefix?: string: Prefix for the temp directory (a random suffix will be added). Default is cloudpack-test-.

Example:

import { createTempDir } from '@ms-cloudpack/test-utilities';

const testFolder = createTempDir({
  prefix: 'some-prefix-', // default is 'cloudpack-test-'
});

createTestFileStructure(files, options)

Creates a test folder and populates it with content. For each key in files, create a test folder and write a file of that filename, where the content is the value.

Returns the path to the test folder.

Parameters:

  • files: Record<string, string | Record<string, unknown>>: Mapping from file path to contents. String contents will be written as-is; objects will be written with JSON.stringify.
  • options object (optional):
    • testName?: string: Test name to use in the temp directory name (cloudpack-test-<testName>-).
    • parentDir?: string: Absolute path to a parent directory for the test file structure (will be created if needed), to be used instead of creating a random temporary directory.
    • links?: Record<string, string>: Create these links in the temp directory. Keys are link paths and values are source paths (both relative).

Example:

import { createTestFileStructure } from '@ms-cloudpack/test-utilities';

const testFolder = await createTestFileStructure({
  './package.json': { name: 'asdf' },
  './src/bar.ts': "export default 'hi';",
});

console.log(readJson(path.join(testFolder, 'package.json')));
0.5.0

4 months ago

0.4.4

8 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.4.1

11 months ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago