{"id":14660,"library":"lab-transform-typescript","title":"Lab Transform TypeScript","description":"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.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/garthk/lab-transform-typescript","tags":["javascript","lab","typescript","coverage","test"],"install":[{"cmd":"npm install lab-transform-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add lab-transform-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add lab-transform-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for transforming TypeScript code. Moved to peerDependencies in v2.0.0.","package":"typescript","optional":false}],"imports":[{"note":"The package's main export is a CommonJS function, directly assignable to a variable. While Node.js ESM can often import CJS defaults, explicit `require` is the guaranteed correct way for direct programmatic usage in CJS environments.","wrong":"import transform from 'lab-transform-typescript';","symbol":"transformFunction","correct":"const transform = require('lab-transform-typescript');"},{"note":"The primary and most common way developers 'use' this package is by configuring the `lab` CLI to apply it as a transform, not by importing its symbols into userland JavaScript/TypeScript code.","symbol":"LabCLIUsage","correct":"/* No JS import; used via CLI: */\nlab --sourcemaps --transform node_modules/lab-transform-typescript"},{"note":"While `lab-transform-typescript` provides typings for `lab` and `code`, these are installed via `typings install` from specific GitHub paths and are not directly imported from the `lab-transform-typescript` npm package itself. This entry highlights the *availability* of these types, not a direct programmatic import from this package.","wrong":"import { LabTypings } from 'lab-transform-typescript/typings-local/lab.d.ts'","symbol":"TypeScriptTypes","correct":"/* No direct JS import for these types; they are installed separately */"}],"quickstart":{"code":"npm install --save-dev lab-transform-typescript typescript\n\n// In a TypeScript test file (e.g., test/example.test.ts):\n// import { expect } from '@hapi/code';\n// import { describe, it } from '@hapi/lab';\n\n// describe('My Test Suite', () => {\n//   it('should pass', () => {\n//     expect(1 + 1).to.equal(2);\n//   });\n// });\n\n// To run tests, execute in your terminal:\n// (Ensure 'lab' is installed globally or in node_modules/.bin)\nprocess.env.TSCONFIG = process.env.TSCONFIG ?? './tsconfig.json'; // Optional: specify tsconfig path\nconsole.log(`Running tests with lab transform and TSCONFIG: ${process.env.TSCONFIG}`);\n// Execute this command via package.json 'test' script or directly if lab is global:\n// lab --sourcemaps --transform node_modules/lab-transform-typescript --verbose\n// To make it runnable in a script: \n// const { spawn } = require('child_process');\n// const lab = spawn('npx', [\n//   'lab',\n//   '--sourcemaps',\n//   '--transform',\n//   'node_modules/lab-transform-typescript',\n//   '--verbose',\n//   'test/**/*.ts' // Example glob for test files\n// ], { stdio: 'inherit' });\n// lab.on('close', (code) => process.exit(code));","lang":"typescript","description":"Demonstrates installation and configuration of `lab-transform-typescript` to enable direct execution of TypeScript test files using the `lab` CLI."},"warnings":[{"fix":"Review your `tsconfig.json` and ensure it's compatible with TypeScript's standard parsing. The `TSCONFIG` environment variable can be used to explicitly override the `tsconfig.json` location.","message":"Version 3.0.0 switched to TypeScript's official configuration loader and parser. This might affect how `tsconfig.json` files are resolved and parsed, especially in complex project setups.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure `typescript` is installed as a `devDependency` in your project (`npm install typescript --save-dev`). The version of `typescript` used will be the one from your project's `node_modules`.","message":"Version 2.0.0 moved `typescript` from `dependencies` to `peerDependencies`. This means `typescript` is no longer automatically installed by `lab-transform-typescript` and must be explicitly installed by the consuming project.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"There is no direct fix for this known issue (#1 in the project's issue tracker, linked to `hapijs/lab#614`). It's a limitation of how `lab` processes transformed output for coverage.","message":"When using `lab --coverage` with `lab-transform-typescript`, the coverage report may display transpiled JavaScript code instead of the original TypeScript source, making it harder to interpret results in terms of the original source.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For consistent behavior, install `lab-transform-typescript` directly via `npm install --save-dev` rather than `npm link` in production or shared development environments, ensuring `typescript` is a direct `devDependency` of your project.","message":"The version of `typescript` used by the transform depends on how `lab-transform-typescript` itself is installed. If linked via `npm link`, it uses its own `node_modules` `typescript` version; otherwise, it uses the `typescript` from the project's `node_modules`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"`npm install typescript --save-dev` to add `typescript` to your project's development dependencies.","cause":"`typescript` is a peer dependency and was not installed in the consuming project.","error":"Error: Cannot find module 'typescript' from 'node_modules/lab-transform-typescript'"},{"fix":"Ensure `lab --transform node_modules/lab-transform-typescript` is correctly specified in your test command and that the path to the transform is accurate. Also, ensure `lab` itself is configured to process the correct file extensions (e.g., `.ts`).","cause":"This typically occurs if `lab` is trying to run a TypeScript file directly without the transform, or if the transform is misconfigured.","error":"SyntaxError: Unexpected token 'import' (or 'export') when running tests."},{"fix":"Double-check the path provided to `TSCONFIG`. Ensure the `tsconfig.json` file exists at the specified path or in a location where TypeScript's default search mechanism would find it (e.g., project root). Ensure you are on `lab-transform-typescript` v3 or newer for this feature.","cause":"The `TSCONFIG` environment variable might be incorrectly set, or TypeScript's default `tsconfig.json` search (which the transform uses since v3.0.0) isn't finding the desired file.","error":"TSCONFIG environment variable ignored or tsconfig.json not found."}],"ecosystem":"npm"}