# @typed-macro/test-utils

> **For basic concepts, see [documentation for typed-macro](https://github.com/typed-macro/typed-macro/blob/master/DOCUMENTATION.md).**

Latest version **1.0.0-alpha** (published 2021-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @typed-macro/test-utils
pnpm add @typed-macro/test-utils
yarn add @typed-macro/test-utils
bun add @typed-macro/test-utils
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha |
| Published | 2021-12-17 |
| First published | 2021-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | unbyte |
| Maintainers | unbyte |

## Links

- npm: https://www.npmjs.com/package/@typed-macro/test-utils
- Repository: https://github.com/typed-macro/typed-macro
- Homepage: https://github.com/typed-macro/typed-macro/tree/master/packages/test-utils#readme
- Issues: https://github.com/typed-macro/typed-macro/issues/new
- npm.io page: https://npm.io/package/@typed-macro/test-utils

## Dependencies (4)

- [chokidar](https://npm.io/package/chokidar.md) ^3.5.2
- [@typed-macro/core](https://npm.io/package/@typed-macro/core.md) 1.0.0-alpha
- [@typed-macro/shared](https://npm.io/package/@typed-macro/shared.md) 1.0.0-alpha
- [@typed-macro/runtime](https://npm.io/package/@typed-macro/runtime.md) 1.0.0-alpha

## Recent versions

- 1.0.0-alpha (latest) — 2021-12-17
- 1.0.0-alpha.1 (alpha) — 2022-01-13

## README

# @typed-macro/test-utils

**For basic concepts, see [documentation for typed-macro](https://github.com/typed-macro/typed-macro/blob/master/DOCUMENTATION.md).**

## Utils

### TestTransformer

TestTransformer is a wrapper of the Transformer inside the Runtime.

```typescript
type TestTransformer = {
  (ctx: TestTransformerContext): string
  (code: string): string
}
```

Here is an example about using TestTransformer with Jest:

```typescript
import {
  createTestEnvContext,
  createTestTransformer,
} from '@typed-macro/test-utils'

const devEnv = createTestEnvContext({ dev: true })
const transform = createTestTransformer({
  macros: {
    '@macros': [...someMacros],
  },
})
expect(transform(`...some code`)).toMatchSnapshot()
expect(transform({ code: `...some code`, env: devEnv })).toMatchSnapshot()
```

### TestTypeRenderer

TestTypeRenderer is a wrapper of the type renderer in Runtime,
returning the result as a string rather than writing to a file.

Here is an example about using TestTypeRenderer with Jest:

```typescript
import { createTestTypeRenderer } from '@typed-macro/test-utils'

const yourExports = {
  '@load': {
    macros: [...someMacros],
  },
  '@helper': {
    code: `export const a = 1`,
    customTypes: `export const a: number`,
  },
}
const render = createTestTypeRenderer()
expect(render(yourExports)).toMatchSnapshot()
```

### TestRuntime

TestRuntime is a wrapper of the Runtime
with more options and more friendly methods for test.

```typescript
const runtime = createTestRuntime({
  provider: [yourProvider],
  env: createTestEnvContext({ dev: false }),
})

expect(await runtime.transform(`...`, 'test.ts')).toMatchSnapshot()
```

---
_Source: https://npm.io/package/@typed-macro/test-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
