Skip to content

Commit

Permalink
Fix jestTransformer for moved cache + config firs
Browse files Browse the repository at this point in the history
Partially addresses piglovesyou#605 

Sets a new cwd context in cases where the config file does not reside in the jest root directory. This is necessary because the config file can then give the cache location, but it will be relative to its own location (not that of the jest config)
  • Loading branch information
comp615 authored May 5, 2022
1 parent 741deff commit 4460e13
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/jestTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SyncTransformer } from '@jest/transform';
import { ProjectConfig } from '@jest/types/build/Config';
import { readFileSync } from 'fs';
import { relative } from 'path';
import { loadConfigSync } from './lib/config';
import { createExecContextSync } from './lib/exec-context';
import { createHash } from './lib/hash';
import { createPaths } from './lib/paths';
import { dirName, relative, resolve } from 'path';

export type JestTransformerOptions = {
configFile?: string;
Expand Down Expand Up @@ -38,8 +38,11 @@ const jestTransformer: SyncTransformer<JestTransformerOptions> = {
const [__compatJestConfig] = rest;
const jestConfig = __compatJestConfig?.config ?? __compatJestConfig;
// jest v26 vs v27 changes to support both formats: end
const { rootDir: cwd } = jestConfig;
let { rootDir: cwd } = jestConfig;
const { configFile, subsequentTransformer } = getOption(jestConfig);
// If the congFile is in another directory from jest's rootDir, reset the working path since
// since the cache and transforms will operate relative to that config's location
const cwd = resolve(cwd, dirname(configFile));
const [config, configHash] = loadConfigSync(cwd, configFile);
const { execContext } = createExecContextSync(cwd, config, configHash);

Expand Down

0 comments on commit 4460e13

Please sign in to comment.