diff --git a/AUTHORS b/AUTHORS index 439c363b55..5cb2531244 100644 --- a/AUTHORS +++ b/AUTHORS @@ -32,6 +32,7 @@ Mohammad Rajabifard OJ Kwon Oliver Joseph Ash Orta Therox +Patrick Housley Tom Crockett Umidbek Karimov diff --git a/package.json b/package.json index 17b814772c..851dbd0d1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-jest", - "version": "20.0.9", + "version": "20.0.10", "main": "index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", diff --git a/src/preprocessor.ts b/src/preprocessor.ts index f1463bd7c7..99c9d3c959 100644 --- a/src/preprocessor.ts +++ b/src/preprocessor.ts @@ -21,8 +21,6 @@ export function process( ); const tsJestConfig = getTSJestConfig(config.globals); - const root = pkgDir.sync(); - const isTsFile = path.endsWith('.ts') || path.endsWith('.tsx'); const isJsFile = path.endsWith('.js') || path.endsWith('.jsx'); const isHtmlFile = path.endsWith('.html'); @@ -49,18 +47,12 @@ export function process( transformOptions, ); - // strip root part from path - // this results in a shorter filename which will also make the encoded base64 filename for the cache shorter - // long file names could be problematic in some OS - // see https://github.com/kulshekhar/ts-jest/issues/158 - path = path.startsWith(root) ? path.substr(root.length) : path; - // store transpiled code contains source map into cache, except test cases if (!config.testRegex || !path.match(config.testRegex)) { const outputFilePath = nodepath.join( config.cacheDirectory, '/ts-jest/', - new Buffer(path).toString('base64'), + crypto.createHash('md5').update(path).digest('hex'), ); fs.outputFileSync(outputFilePath, outputText); diff --git a/tests/__tests__/long-path.spec.ts b/tests/__tests__/long-path.spec.ts new file mode 100644 index 0000000000..9737afc65f --- /dev/null +++ b/tests/__tests__/long-path.spec.ts @@ -0,0 +1,12 @@ +import runJest from '../__helpers__/runJest'; + +describe('Long path', () => { + it('should work as expected', () => { + const result = runJest('../simple-long-path/', [ + '--no-cache', + '--coverage', + ]); + + expect(result.status).toBe(0); + }); +}); diff --git a/tests/simple-long-path/__tests__/Hello.test.ts b/tests/simple-long-path/__tests__/Hello.test.ts new file mode 100644 index 0000000000..12b5063601 --- /dev/null +++ b/tests/simple-long-path/__tests__/Hello.test.ts @@ -0,0 +1,7 @@ +import { Hello } from '../long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/Hello'; + +describe('Hello test in long path', () => { + it('should work', () => { + expect(new Hello().name).toEqual('John Doe'); + }); +}); diff --git a/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/Hello.ts b/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/Hello.ts new file mode 100644 index 0000000000..9c4322b72b --- /dev/null +++ b/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/Hello.ts @@ -0,0 +1,3 @@ +export class Hello { + name: string = 'John Doe'; +} diff --git a/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/NullCoverage.js b/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/NullCoverage.js new file mode 100644 index 0000000000..c59dbbdef3 --- /dev/null +++ b/tests/simple-long-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/long-src-path/NullCoverage.js @@ -0,0 +1,6 @@ +function nullCoverageFunction(value) { + if (value) { + return value; + } + return null; +} diff --git a/tests/simple-long-path/package.json b/tests/simple-long-path/package.json new file mode 100644 index 0000000000..d033ac811a --- /dev/null +++ b/tests/simple-long-path/package.json @@ -0,0 +1,20 @@ +{ + "jest": { + "transform": { + ".(ts|tsx)": "../../preprocessor.js" + }, + "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", + "coverageReporters": [ + "json" + ], + "collectCoverageFrom": [ + "long-src-path/**/*.ts", + "long-src-path/**/*.js" + ], + "moduleFileExtensions": [ + "ts", + "tsx", + "js" + ] + } +} diff --git a/tests/simple-long-path/tsconfig.json b/tests/simple-long-path/tsconfig.json new file mode 100644 index 0000000000..55f8667f97 --- /dev/null +++ b/tests/simple-long-path/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "moduleResolution": "node", + "noEmitOnError": false, + "jsx": "react", + "allowJs": true + } +}