react / wstein / node_modules / jest-cli / src / HasteModuleLoader / __tests__ / HasteModuleLoader-genMockFromModule-test.js
80679 views/**1* Copyright (c) 2014, Facebook, Inc. All rights reserved.2*3* This source code is licensed under the BSD-style license found in the4* LICENSE file in the root directory of this source tree. An additional grant5* of patent rights can be found in the PATENTS file in the same directory.6*/7'use strict';89jest.autoMockOff();1011var path = require('path');12var q = require('q');13var utils = require('../../lib/utils');1415describe('nodeHasteModuleLoader', function() {16var HasteModuleLoader;17var mockEnvironment;18var resourceMap;1920var CONFIG = utils.normalizeConfig({21name: 'nodeHasteModuleLoader-tests',22rootDir: path.resolve(__dirname, 'test_root')23});2425function buildLoader() {26if (!resourceMap) {27return HasteModuleLoader.loadResourceMap(CONFIG).then(function(map) {28resourceMap = map;29return buildLoader();30});31} else {32return q(new HasteModuleLoader(CONFIG, mockEnvironment, resourceMap));33}34}3536beforeEach(function() {37HasteModuleLoader = require('../HasteModuleLoader');3839mockEnvironment = {40global: {41console: {},42mockClearTimers: jest.genMockFn()43},44runSourceText: jest.genMockFn().mockImplementation(function(codeStr) {45/* jshint evil:true */46return (new Function('return ' + codeStr))();47})48};49});5051describe('genMockFromModule', function() {52pit('does not cause side effects in the rest of the module system when ' +53'generating a mock', function() {54return buildLoader().then(function(loader) {55var testRequire = loader.requireModule.bind(loader, __filename);5657var regularModule = testRequire('RegularModule');58var origModuleStateValue = regularModule.getModuleStateValue();5960testRequire('jest-runtime').dontMock('RegularModule');6162// Generate a mock for a module with side effects63testRequire('jest-runtime').genMockFromModule('ModuleWithSideEffects');6465expect(regularModule.getModuleStateValue()).toBe(origModuleStateValue);66});67});68});69});707172