Skip to content

Commit

Permalink
fix(caching): fixes a possible cache collision
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 2, 2018
1 parent 097f867 commit 9c38694
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
32 changes: 16 additions & 16 deletions e2e/__helpers__/test-case/__hooks-source__.js.hbs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// this is a template!

const fs = require('fs');
const path = require('path');
const root = __dirname;
const writeProcessIoTo = {{writeProcessIoTo}};
const fs = require('fs')
const path = require('path')
const root = __dirname
const writeProcessIoTo = {{writeProcessIoTo}}

exports.afterProcess = function (args, result) {
// const source = args[0];
const filePath = args[1];
const relPath = path.relative(root, filePath);
// const source = args[0]
const filePath = args[1]
const relPath = path.relative(root, filePath)
if (writeProcessIoTo && filePath.startsWith(`${root}${path.sep}`)) {
const dest = `${path.join(writeProcessIoTo, relPath)}.json`;
const segments = relPath.split(path.sep);
segments.pop();
const madeSegments = [];
const dest = `${path.join(writeProcessIoTo, relPath)}.json`
const segments = relPath.split(path.sep)
segments.pop()
const madeSegments = []
segments.forEach(segment => {
madeSegments.push(segment);
const p = join(writeProcessIoTo, madeSegments.join(sep));
if (!fs.existsSync(p)) fs.mkdirSync(p);
});
madeSegments.push(segment)
const p = path.join(writeProcessIoTo, madeSegments.join(path.sep))
if (!fs.existsSync(p)) fs.mkdirSync(p)
})
fs.writeFileSync(dest, JSON.stringify({
in: args,
out: result,
}), 'utf8');
}), 'utf8')
}
}
22 changes: 19 additions & 3 deletions src/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { version as myVersion } from '..'
import semver from 'semver'
import { rootLogger } from '../util/logger'
import { Logger } from 'bs-logger'
import { getPackageVersion } from '../util/get-package-version'

const logger = rootLogger.child({ namespace: 'config' })

Expand Down Expand Up @@ -235,7 +236,7 @@ export class ConfigSet {
tsConfig,
babelConfig,
diagnostics,
typeCheck: !!options.typeCheck,
isolatedModules: !!options.isolatedModules,
compiler: options.compiler || 'typescript',
stringifyContentPathRegex,
}
Expand All @@ -251,6 +252,21 @@ export class ConfigSet {
return this._typescript.input
}

@Memoize()
get versions(): Record<string, string> {
const modules = ['jest', this.tsJest.compiler, 'tslib']
if (this.tsJest.babelConfig) {
modules.push('@babel/core', 'babel-core', 'babel-jest')
}
return modules.reduce(
(map, name) => {
map[name] = getPackageVersion(name) || '-'
return map
},
{ 'ts-jest': myVersion } as Record<string, string>,
)
}

@Memoize()
private get _typescript(): ReadTsConfigResult {
const {
Expand Down Expand Up @@ -423,7 +439,7 @@ export class ConfigSet {
version: this.compilerModule.version,
compiler: this.tsJest.compiler,
compilerOptions: this.typescript.options,
typeCheck: this.tsJest.typeCheck,
isolatedModules: this.tsJest.isolatedModules,
ignoreDiagnostics: this.tsJest.diagnostics.ignoreCodes,
}),
)
Expand Down Expand Up @@ -555,7 +571,7 @@ export class ConfigSet {
delete globals['ts-jest']

return new JsonableValue({
version: myVersion,
versions: this.versions,
jest,
tsJest: this.tsJest,
babel: this.babel,
Expand Down

0 comments on commit 9c38694

Please sign in to comment.