diff --git a/.gitignore b/.gitignore index 82539a8b8d..b1dc0a4c62 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ jspm_packages # Optional REPL history .node_repl_history + +# We need to include this folders, because they are mocks for integration tests +!tests/**/node_modules diff --git a/.npmignore b/.npmignore index 3b6328d017..fd050273ec 100644 --- a/.npmignore +++ b/.npmignore @@ -17,6 +17,9 @@ pids *.pid *.seed +# nodist config for testing in different versions of node +.node-version + # Directory for instrumented libs generated by jscoverage/JSCover lib-cov diff --git a/README.md b/README.md index 8bfc9a2798..a84bb29beb 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Build Status for node v7](https://travis-badges.herokuapp.com/repos/kulshekhar/ts-jest/branches/master?job=0)](https://travis-ci.org/kulshekhar/ts-jest) [![Build Status for node v6](https://travis-badges.herokuapp.com/repos/kulshekhar/ts-jest/branches/master?job=1)](https://travis-ci.org/kulshekhar/ts-jest) [![Build Status for node v4](https://travis-badges.herokuapp.com/repos/kulshekhar/ts-jest/branches/master?job=2)](https://travis-ci.org/kulshekhar/ts-jest) +[![Build Status for Windows](https://ci.appveyor.com/api/projects/status/gknb1pl72o0w0coc?svg=true)](https://ci.appveyor.com/project/Igmat/ts-jest) ## Table of Contents diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..a3d68361a8 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,31 @@ +# appveyor file +# http://www.appveyor.com/docs/appveyor-yml + +# build version format +version: "{build}" + +# fix lineendings in Windows +init: + - git config --global core.autocrlf input + +# what combinations to test +environment: + matrix: + - nodejs_version: 4 + - nodejs_version: 6 + - nodejs_version: 7 + +# get the latest stable version of Node 0.STABLE.latest +install: + - ps: Install-Product node $env:nodejs_version + - set CI=true + - npm i -g npm@latest + - set PATH=%APPDATA%\npm;%PATH% + - npm install + +build: off + +test_script: + - node --version + - npm --version + - cmd: npm test --no-color \ No newline at end of file diff --git a/package.json b/package.json index 033ca8cb65..e7a9c48012 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-jest", - "version": "0.1.12", + "version": "0.1.13", "main": "index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", diff --git a/src/default-retrieve-file-handler.ts b/src/default-retrieve-file-handler.ts new file mode 100644 index 0000000000..af3b5f44b3 --- /dev/null +++ b/src/default-retrieve-file-handler.ts @@ -0,0 +1,23 @@ +import * as fs from 'fs'; +import { transpileIfTypescript } from './transpile-if-ts'; + +export function defaultRetrieveFileHandler(path) { + // Trim the path to make sure there is no extra whitespace. + path = path.trim(); + + // This was removed because it seems that we can't use cache while expecting correct results + // TODO: check correctness and performance with file caching + // if (path in fileContentsCache) { + // return fileContentsCache[path]; + // } + + var contents: string; + try { + contents = fs.readFileSync(path, 'utf8'); + contents = transpileIfTypescript(path, contents); + } catch (e) { + contents = null; + } + + return contents; +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 755dc771ec..1f8bc46ab0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,9 @@ +import { defaultRetrieveFileHandler } from './default-retrieve-file-handler'; import * as sourceMapSupport from 'source-map-support'; export function install() { var options: sourceMapSupport.Options = {}; + options.retrieveFile = defaultRetrieveFileHandler; options.emptyCacheBetweenOperations = true; // left here only for sourceMapCache TODO: check this for correctness and performance with false velue options['environment'] = 'node'; diff --git a/src/transpile-if-ts.ts b/src/transpile-if-ts.ts new file mode 100644 index 0000000000..2c9c596ef0 --- /dev/null +++ b/src/transpile-if-ts.ts @@ -0,0 +1,15 @@ +import * as tsc from 'typescript'; +import { getTSConfig } from './utils'; + +export function transpileIfTypescript(path, contents) { + if (path && (path.endsWith('.tsx') || path.endsWith('.ts'))) { + + let transpiled = tsc.transpileModule(contents, { + compilerOptions: getTSConfig({ __TS_CONFIG__: global['__TS_CONFIG__'] }, true), + fileName: path + }); + + return transpiled.outputText; + } + return contents; +} \ No newline at end of file diff --git a/tests/__tests__/watch.spec.ts b/tests/__tests__/watch.spec.ts index d74919f726..b6d4ada4da 100644 --- a/tests/__tests__/watch.spec.ts +++ b/tests/__tests__/watch.spec.ts @@ -48,9 +48,12 @@ describe('Hello Class', () => { describe('hello_world', () => { let result: { childProcess: ChildProcess, getStderrAsync: () => Promise }; + let DEFAULT_TIMEOUT_INTERVAL: number; beforeAll(() => { result = runJestInWatchMode('../watch-test'); + DEFAULT_TIMEOUT_INTERVAL = jasmine['DEFAULT_TIMEOUT_INTERVAL']; + jasmine['DEFAULT_TIMEOUT_INTERVAL'] = 10000; }); it('should show the correct error locations in the typescript files without changes', () => { @@ -81,6 +84,7 @@ describe('hello_world', () => { afterAll(() => { result.childProcess.kill(); // revert changes back + jasmine['DEFAULT_TIMEOUT_INTERVAL'] = DEFAULT_TIMEOUT_INTERVAL; fs.writeFileSync(path.resolve(__dirname, '../watch-test/Hello.ts'), helloFile); fs.writeFileSync(path.resolve(__dirname, '../watch-test/__tests__/Hello.test.ts'), testFile); }); diff --git a/tests/button/__mocks__/ts-jest.ts b/tests/button/__mocks__/ts-jest.ts deleted file mode 100644 index d8807e2a35..0000000000 --- a/tests/button/__mocks__/ts-jest.ts +++ /dev/null @@ -1,2 +0,0 @@ -// we have to mock ts-jest package here, because we don't want create extra node_modules folders -module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/button/node_modules/ts-jest.js b/tests/button/node_modules/ts-jest.js new file mode 100644 index 0000000000..6bb2ded8c1 --- /dev/null +++ b/tests/button/node_modules/ts-jest.js @@ -0,0 +1 @@ +module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/simple/__mocks__/ts-jest.ts b/tests/simple/__mocks__/ts-jest.ts deleted file mode 100644 index d8807e2a35..0000000000 --- a/tests/simple/__mocks__/ts-jest.ts +++ /dev/null @@ -1,2 +0,0 @@ -// we have to mock ts-jest package here, because we don't want create extra node_modules folders -module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/simple/node_modules/ts-jest.js b/tests/simple/node_modules/ts-jest.js new file mode 100644 index 0000000000..6bb2ded8c1 --- /dev/null +++ b/tests/simple/node_modules/ts-jest.js @@ -0,0 +1 @@ +module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/tsconfig-test/__mocks__/ts-jest.ts b/tests/tsconfig-test/__mocks__/ts-jest.ts deleted file mode 100644 index d8807e2a35..0000000000 --- a/tests/tsconfig-test/__mocks__/ts-jest.ts +++ /dev/null @@ -1,2 +0,0 @@ -// we have to mock ts-jest package here, because we don't want create extra node_modules folders -module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/watch-test/__mocks__/ts-jest.ts b/tests/watch-test/__mocks__/ts-jest.ts deleted file mode 100644 index d8807e2a35..0000000000 --- a/tests/watch-test/__mocks__/ts-jest.ts +++ /dev/null @@ -1,2 +0,0 @@ -// we have to mock ts-jest package here, because we don't want create extra node_modules folders -module.exports = require('../../../'); \ No newline at end of file diff --git a/tests/watch-test/node_modules/ts-jest.js b/tests/watch-test/node_modules/ts-jest.js new file mode 100644 index 0000000000..6bb2ded8c1 --- /dev/null +++ b/tests/watch-test/node_modules/ts-jest.js @@ -0,0 +1 @@ +module.exports = require('../../../'); \ No newline at end of file