Skip to content

Commit

Permalink
Change the package entry point to preprocessor.js itself
Browse files Browse the repository at this point in the history
This way, the `"ts-jest"` package name can be used as Jest transform, instead of specifying the path to preprocessor.js.
The latter did not work when the ts-jest package had been hoisted to a parent folder (for example by lerna).

Fixes #361
  • Loading branch information
Martijn The committed Nov 6, 2017
1 parent 2b13c2e commit bad01ec
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -30,6 +30,7 @@ Justin Bay <jwbay@users.noreply.github.com>
Kulshekhar Kabra <kulshekhar@users.noreply.github.com>
Kyle Roach <kroach.work@gmail.com>
Marshall Bowers <elliott.codes@gmail.com>
Martijn The <post@martijnthe.nl>
Matheus Gambati <matheusgambati@gmail.com>
Maxim Samoilov <samoilowmaxim@gmail.com>
Mohammad Rajabifard <mo.rajbi@gmail.com>
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -58,7 +58,7 @@ Modify your project's `package.json` so that the `jest` section looks something
{
"jest": {
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
Expand Down Expand Up @@ -226,7 +226,7 @@ In `package.json`, inside `jest` section, the `transform` should be like this:
```json
"transform": {
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
"^.+\\.tsx?$": "ts-jest"
}
```

Expand All @@ -237,7 +237,7 @@ Fully completed jest section should look like this:
"preset": "react-native",
"transform": {
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
Expand Down Expand Up @@ -269,7 +269,7 @@ You'll also need to extend your `transform` regex with `html` extension:
{
"jest": {
"transform": {
"^.+\\.(tsx?|html)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
"^.+\\.(tsx?|html)$": "ts-jest"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
@@ -1,8 +1,8 @@
{
"name": "ts-jest",
"version": "21.1.4",
"main": "index.js",
"types": "./dist/index.d.ts",
"version": "21.2.0",
"main": "preprocessor.js",
"types": "./dist/preprocessor.d.ts",
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
"scripts": {
"build": "tsc -p .",
Expand Down
1 change: 0 additions & 1 deletion src/index.ts → src/install.ts
@@ -1,7 +1,6 @@
import * as sourceMapSupport from 'source-map-support';
import { defaultRetrieveFileHandler } from './default-retrieve-file-handler';

export { transpileIfTypescript } from './transpile-if-ts';
export function install() {
const options: sourceMapSupport.Options = {};

Expand Down
2 changes: 2 additions & 0 deletions src/preprocessor.ts
Expand Up @@ -6,6 +6,8 @@ import { JestConfig, Path, TransformOptions } from './jest-types';
import { getPostProcessHook } from './postprocess';
import { getTSConfig, getTSJestConfig } from './utils';

export { install } from './install';

export function process(
src: string,
path: Path,
Expand Down
2 changes: 1 addition & 1 deletion tests/__tests__/transpile-if-ts.spec.ts
@@ -1,4 +1,4 @@
import { transpileIfTypescript } from '../../src';
import { transpileIfTypescript } from '../../src/transpile-if-ts';

describe('transpileIfTypescript', () => {
it('should ignore anything non-TS', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/jestconfig-test/jest.json
@@ -1,7 +1,7 @@
{
"rootDir": "./",
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
"^.+\\.tsx?$": "ts-jest"
},
"mapCoverage": true,
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
Expand Down

0 comments on commit bad01ec

Please sign in to comment.