# @code-to-json/test-helpers

> Test helpers for code-to-json

Latest version **1.0.0-rc.48** (published 2019-04-16) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @code-to-json/test-helpers
pnpm add @code-to-json/test-helpers
yarn add @code-to-json/test-helpers
bun add @code-to-json/test-helpers
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.48 |
| Published | 2019-04-16 |
| First published | 2018-10-26 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 112.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mike North |
| Maintainers | mike-north-bot, northm |

## Links

- npm: https://www.npmjs.com/package/@code-to-json/test-helpers
- Repository: https://github.com/mike-north/code-to-json
- Homepage: https://github.com/mike-north/code-to-json/tree/master/packages/test-helpers
- Issues: https://github.com/mike-north/code-to-json/issues
- npm.io page: https://npm.io/package/@code-to-json/test-helpers

## Dependencies (8)

- [debug](https://npm.io/package/debug.md) ^4.1.0
- [treeify](https://npm.io/package/treeify.md) ^1.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.0
- [typescript](https://npm.io/package/typescript.md) ^3.4.3
- [node-cleanup](https://npm.io/package/node-cleanup.md) ^2.1.2
- [directory-tree](https://npm.io/package/directory-tree.md) ^2.2.1
- [@mike-north/types](https://npm.io/package/@mike-north/types.md) ^1.0.7
- [@code-to-json/utils](https://npm.io/package/@code-to-json/utils.md) ^1.0.0-rc.41

## Recent versions

- 1.0.0-rc.48 (latest) — 2019-04-16
- 1.0.0-rc.47 — 2019-04-15
- 1.0.0-rc.46 — 2019-04-13
- 1.0.0-rc.45 — 2019-04-12
- 1.0.0-rc.44 — 2019-04-12
- 1.0.0-rc.43 — 2019-04-11
- 1.0.0-rc.42 — 2019-03-28
- 1.0.0-rc.41 — 2019-03-20
- 1.0.0-rc.40 — 2019-03-18
- 1.0.0-rc.39 — 2019-03-08
- 1.0.0-rc.38 — 2019-03-07
- 1.0.0-rc.37 — 2019-03-05
- 1.0.0-rc.36 — 2019-03-02
- 1.0.0-rc.35 — 2019-02-26
- 1.0.0-rc.34 — 2019-02-26
- … 147 more at https://npm.io/package/@code-to-json/test-helpers/versions

## README

# @code-to-json/test-helpers

[![Build Status](https://travis-ci.org/code-to-json/code-to-json.svg?branch=master)](https://travis-ci.org/code-to-json/code-to-json)
[![Build Status](https://dev.azure.com/code-to-json/code-to-json/_apis/build/status/code-to-json.code-to-json)](https://dev.azure.com/code-to-json/code-to-json/_build/latest?definitionId=1)
[![Version](https://img.shields.io/npm/v/@code-to-json/test-helpers.svg)](https://www.npmjs.com/package/@code-to-json/test-helpers)
[![codecov](https://codecov.io/gh/code-to-json/code-to-json/branch/master/graph/badge.svg)](https://codecov.io/gh/code-to-json/code-to-json/tree/master/packages/test-helpers/src)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/code-to-json/code-to-json.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/code-to-json/code-to-json/alerts/)

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](https://github.com/code-to-json/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

```ts
import { createTempFixtureFolder } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const { rootPath, cleanup } = await createTempFixtureFolder('path/to/my/fixture/on/disk');

cleanup(); // Completely delete the test case from disk
```

or describe your fixture using a plain JS/TS object

```ts
import { createTempFixtureFolder } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const { rootPath, cleanup } = await createTempFixtureFolder({
  // ./tsconfig.json
  'tsconfig.json': `
{
  "compilerOptions": {
    "noEmit": true,
    "module": "es6",
    "target": "es2015"
  },
  "include": ["src"]
}
  `,
  src: {
    // ./src/index.ts
    'index.ts': `
/**
* This is a variable with an explicit type
*/
const constWithExplicitType: string = 'foo';
`,
  },
});

cleanup(); // Completely delete the test case from disk
```

### `setupTestCase`

Create the same folder structure described above for `createTempFixtureFolder`, and also initialize it as a TypeScript program.

```ts
import * as ts from 'typescript';
import { setupTestCase } from '@code-to-json/test-helpers';

// Create the test case in your system temp folder
const program: ts.Program = await setupTestCase(
  /**
   * Root folder of the fixture on disk
   * (you can also provide a "fixture object" as described above)
   */
  'path/to/my/fixture/on/disk',
  /**
   * One or more entry points of your application. Any imports will be included
   * in the TS program as well
   */
  ['src/index.ts'],
);
```

## Versioning & Conventions

This library has a very strong commitment to [semantic versioning](https://semver.org/), and makes use of [conventional commits](https://conventionalcommits.org) to automatically generate changelogs, and to increment version numbers appropriately when publishing.

---

© 2018 LinkedIn

---
_Source: https://npm.io/package/@code-to-json/test-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
