Skip to content

Commit

Permalink
verify requireOrImportModule path must be absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiAnAn committed Mar 15, 2021
1 parent cb22e4f commit 4784cc7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/jest-util/src/requireOrImportModule.ts
@@ -1,3 +1,4 @@
import {isAbsolute} from 'path';
import {pathToFileURL} from 'url';
import type {Config} from '@jest/types';
import interopRequireDefault from './interopRequireDefault';
Expand All @@ -6,6 +7,9 @@ export default async function requireOrImportModule<T>(
filePath: Config.Path,
): Promise<T> {
let module: T;
if (!isAbsolute(filePath) && filePath[0] === '.') {
throw new Error(`Jest: requireOrImportModule path must be absolute`);
}
try {
module = interopRequireDefault(require(filePath)).default;
} catch (error) {
Expand Down

0 comments on commit 4784cc7

Please sign in to comment.