Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for all variations of jest.resetModules #10628

Merged
merged 4 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
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});