@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-',
});
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')));