Skip to content

Commit

Permalink
fix: remove require.requireActual
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 22, 2020
1 parent fc5a6ca commit 7f3cd83
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Chore & Maintenance

- `[jest-runtime]` [**BREAKING**] Remove long-deprecated `require.requireActual` and `require.requireMock` methods ([#9854](https://github.com/facebook/jest/pull/9854))

### Performance

## 25.4.0
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export declare class JestEnvironment {

export type Module = NodeModule;

export interface LocalModuleRequire extends NodeRequire {
requireActual(moduleName: string): unknown;
requireMock(moduleName: string): unknown;
}

// TODO: Move to some separate package
export interface Jest {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,46 +184,6 @@ describe('dependencyExtractor', () => {
expect(extract(code)).toEqual(new Set(['dep1', 'dep2', 'dep3']));
});

it('should extract dependencies from `require.requireActual` calls', () => {
const code = `
// Good
require.requireActual('dep1');
const dep2 = require.requireActual(
"dep2",
);
if (require.requireActual(\`dep3\`).cond) {}
require
.requireActual('dep4');
// Bad
${COMMENT_NO_NEG_LB} foo . require.requireActual('inv1')
xrequire.requireActual('inv2');
require.requireActualx('inv3');
require.requireActual('inv4', 'inv5');
`;
expect(extract(code)).toEqual(new Set(['dep1', 'dep2', 'dep3', 'dep4']));
});

it('should extract dependencies from `require.requireMock` calls', () => {
const code = `
// Good
require.requireMock('dep1');
const dep2 = require.requireMock(
"dep2",
);
if (require.requireMock(\`dep3\`).cond) {}
require
.requireMock('dep4');
// Bad
${COMMENT_NO_NEG_LB} foo . require.requireMock('inv1')
xrequire.requireMock('inv2');
require.requireMockx('inv3');
require.requireMock('inv4', 'inv5');
`;
expect(extract(code)).toEqual(new Set(['dep1', 'dep2', 'dep3', 'dep4']));
});

it('should extract dependencies from `jest.requireActual` calls', () => {
const code = `
// Good
Expand Down
1 change: 0 additions & 1 deletion packages/jest-haste-map/src/lib/dependencyExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const IMPORT_OR_EXPORT_RE = createRegExp(
const JEST_EXTENSIONS_RE = createRegExp(
[
...functionCallStart(
'require\\s*\\.\\s*(?:requireActual|requireMock)',
'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule)',
),
CAPTURE_STRING_LITERAL(1),
Expand Down
10 changes: 2 additions & 8 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {Config} from '@jest/types';
import type {
Jest,
JestEnvironment,
LocalModuleRequire,
Module,
ModuleWrapper,
} from '@jest/environment';
Expand Down Expand Up @@ -1250,7 +1249,7 @@ class Runtime {
private _createRequireImplementation(
from: InitialModule,
options?: InternalModuleOptions,
): LocalModuleRequire {
): NodeRequire {
// TODO: somehow avoid having to type the arguments - they should come from `NodeRequire/LocalModuleRequire.resolve`
const resolve = (moduleName: string, options: ResolveOptions) =>
this._requireResolve(from.filename, moduleName, options);
Expand All @@ -1260,13 +1259,8 @@ class Runtime {
const moduleRequire = (options && options.isInternalModule
? (moduleName: string) =>
this.requireInternalModule(from.filename, moduleName)
: this.requireModuleOrMock.bind(
this,
from.filename,
)) as LocalModuleRequire;
: this.requireModuleOrMock.bind(this, from.filename)) as NodeRequire;
moduleRequire.extensions = Object.create(null);
moduleRequire.requireActual = this.requireActual.bind(this, from.filename);
moduleRequire.requireMock = this.requireMock.bind(this, from.filename);
moduleRequire.resolve = resolve;
moduleRequire.cache = (() => {
const notPermittedMethod = () => {
Expand Down

0 comments on commit 7f3cd83

Please sign in to comment.