marionebl / ts-transformer-testing-library

Make testing custom TypeScript transformers a breeze

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-transformer-testing-libray

Make testing custom TypeScript transformers a breeze

  • ⚑ Avoid tsc work
  • πŸ”Œ Work with multiple modules
  • πŸ„ Mock source modules as required

Custom TypeScript transformers are a powerful way to work with your source code, but coming up with a good unit testing setup for them is hard.

This library does the heavy lifting for you.

Installation

yarn add -D ts-transformer-testing-library

Usage

// Transform a standalone TypeScript source
import { transform } from "ts-transformer-testing-library";

const result = transform(`console.log('Hello, World!');`, {
  transform() { /* Imaginary transform World ➞ You */ }
});

console.log(result); // "Hello, You!";
// Transform a standalone TypeScript source
import { transformFile } from "ts-transformer-testing-library";

const result = transformFile({ 
  path: '/index.ts', 
  contents: `import {phrase} from './phrase'; console.log(phrase);`
}, {
  sources: [{ path: '/phrase.ts', contents: `export const phrase = 'Hello, World!'` }],
  transform() { /* Imaginary transform World ➞ You */ }
});

console.log(result); // "Hello, You!";

API

⚠️ API is still in flux. Consult interfaces in source for details.

License

MIT. Copyright 2019 - present Mario Nebl

About

Make testing custom TypeScript transformers a breeze

License:MIT License


Languages

Language:TypeScript 100.0%