@tsbb/jest
Version:
TSBB is a zero-config CLI that helps you develop, test, and publish modern TypeScript project.
21 lines (20 loc) • 843 B
JavaScript
import path, { dirname } from 'path';
import { runCLI } from '@jest/core';
import { fileURLToPath } from 'url';
import createJestConfig from './jest.config.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default async function jest(options = {}) {
const { env, coverage = false, rootDir = process.cwd() } = options;
const config = await createJestConfig((relativePath) => path.resolve(__dirname, '..', relativePath), path.resolve(rootDir));
options.config = JSON.stringify(config);
if (coverage) {
options.watchAll = false;
process.env.BABEL_ENV = 'development';
}
else if (!process.env.CI) {
process.env.BABEL_ENV = 'production';
options.watchAll = true;
}
runCLI({ ...options, env, coverage, rootDir }, [process.cwd()]);
}