Skip to content

Commit

Permalink
Add tests for all variations of jest.resetModules (#10628)
Browse files Browse the repository at this point in the history
  • Loading branch information
flozender committed Oct 13, 2020
1 parent 3641e3c commit ac2b289
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
4 changes: 2 additions & 2 deletions e2e/__tests__/requireMainResetModules.test.ts
Expand Up @@ -10,14 +10,14 @@ import runJest from '../runJest';
test("`require.main` on using `--resetModules='true'` should not be undefined", () => {
const {exitCode} = runJest('require-main-reset-modules', [
`--resetModules='true'`,
'index.test.js',
'resetModulesFlag',
]);
expect(exitCode).toBe(0);
});

test('`require.main` on using `jest.resetModules()` should not be undefined', () => {
const {exitCode} = runJest('require-main-reset-modules', [
'callJestResetModules.test.js',
'resetModulesCall',
]);
expect(exitCode).toBe(0);
});
@@ -0,0 +1,23 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
jest.resetModules();
});

test('require.main is set on requiring directly', () => {
const {getMain} = require('../direct.js');
expect(getMain()).toBeTruthy();
});

test('require from main works on requiring directly', () => {
const {requireFromMain} = require('../direct.js');
expect(requireFromMain('../package.json')).toBeTruthy();
});
@@ -0,0 +1,23 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
jest.resetModules();
});

test('require.main is set on requiring indirectly', () => {
const {getMain} = require('../indirect.js');
expect(getMain()).toBeTruthy();
});

test('require from main works on requiring indirectly', () => {
const {requireFromMain} = require('../indirect.js');
expect(requireFromMain('../package.json')).toBeTruthy();
});
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/
test('require.main is set', () => {
const {getMain} = require('../index.js');
const {getMain} = require('../direct.js');
expect(getMain()).toBeTruthy();
});

test('require from main works', () => {
const {requireFromMain} = require('../index.js');
const {requireFromMain} = require('../direct.js');
expect(requireFromMain('../package.json')).toBeTruthy();
});
Expand Up @@ -4,20 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
jest.resetModules();
});

test('require.main is set', () => {
const {getMain} = require('../index.js');
const {getMain} = require('../indirect.js');
expect(getMain()).toBeTruthy();
});

test('require from main works', () => {
const {requireFromMain} = require('../index.js');
const {requireFromMain} = require('../indirect.js');
expect(requireFromMain('../package.json')).toBeTruthy();
});
File renamed without changes.
8 changes: 8 additions & 0 deletions e2e/require-main-reset-modules/indirect.js
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const {getMain, requireFromMain} = require('./direct');
Object.assign(exports, {getMain, requireFromMain});

0 comments on commit ac2b289

Please sign in to comment.