Lab Transform TypeScript

3.0.1 · active · verified Sun Apr 19

lab-transform-typescript is a utility that enables the `lab` testing framework to directly execute TypeScript test files without requiring a separate pre-compilation step. This allows for a more streamlined `npm test` workflow for projects using TypeScript with `lab`. The current stable version is 3.0.1, which includes inlined source maps for better error reporting. The package's release cadence is not fixed, typically driven by updates to the `lab` framework or `typescript` itself. Key differentiators include its tight integration with `lab`, support for source maps, and the provision of optional type definitions for `lab` and `code` (the assertion library used with `lab`), enhancing the development experience for TypeScript users within the `lab` ecosystem. It leverages TypeScript's official configuration loader and parser since version 3.0.0.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates installation and configuration of `lab-transform-typescript` to enable direct execution of TypeScript test files using the `lab` CLI.

npm install --save-dev lab-transform-typescript typescript

// In a TypeScript test file (e.g., test/example.test.ts):
// import { expect } from '@hapi/code';
// import { describe, it } from '@hapi/lab';

// describe('My Test Suite', () => {
//   it('should pass', () => {
//     expect(1 + 1).to.equal(2);
//   });
// });

// To run tests, execute in your terminal:
// (Ensure 'lab' is installed globally or in node_modules/.bin)
process.env.TSCONFIG = process.env.TSCONFIG ?? './tsconfig.json'; // Optional: specify tsconfig path
console.log(`Running tests with lab transform and TSCONFIG: ${process.env.TSCONFIG}`);
// Execute this command via package.json 'test' script or directly if lab is global:
// lab --sourcemaps --transform node_modules/lab-transform-typescript --verbose
// To make it runnable in a script: 
// const { spawn } = require('child_process');
// const lab = spawn('npx', [
//   'lab',
//   '--sourcemaps',
//   '--transform',
//   'node_modules/lab-transform-typescript',
//   '--verbose',
//   'test/**/*.ts' // Example glob for test files
// ], { stdio: 'inherit' });
// lab.on('close', (code) => process.exit(code));

view raw JSON →