@code-to-json/test-helpers
This package contains a variety of test helpers, useful for testing tools built on top of the TypeScript compiler API in general, and code-to-json in particular
Usage
createTempFixtureFolder
Create collection of files and folders in your OS system temp folder
You may either refer to an existing folder on disk
import { createTempFixtureFolder } from '@code-to-json/test-helpers';
const { rootPath, cleanup } = await createTempFixtureFolder('path/to/my/fixture/on/disk');
cleanup();
or describe your fixture using a plain JS/TS object
import { createTempFixtureFolder } from '@code-to-json/test-helpers';
const { rootPath, cleanup } = await createTempFixtureFolder({
'tsconfig.json': `
{
"compilerOptions": {
"noEmit": true,
"module": "es6",
"target": "es2015"
},
"include": ["src"]
}
`,
src: {
'index.ts': `
/**
* This is a variable with an explicit type
*/
const constWithExplicitType: string = 'foo';
`,
},
});
cleanup();
setupTestCase
Create the same folder structure described above for createTempFixtureFolder
, and also initialize it as a TypeScript program.
import * as ts from 'typescript';
import { setupTestCase } from '@code-to-json/test-helpers';
const program: ts.Program = await setupTestCase(
'path/to/my/fixture/on/disk',
['src/index.ts'],
);
Versioning & Conventions
This library has a very strong commitment to semantic versioning, and makes use of conventional commits to automatically generate changelogs, and to increment version numbers appropriately when publishing.
© 2018 LinkedIn