Removing automatically reset modules between test run
Reviewed By: bestander Differential Revision: D3886125 fbshipit-source-id: c8f47c3466add1e2c89649a1c6f47b01f0d7a89e
This commit is contained in:
parent
d41c3950eb
commit
7b2080e118
|
@ -17,8 +17,12 @@ jest
|
||||||
.setMock('React', {Component: class {}});
|
.setMock('React', {Component: class {}});
|
||||||
|
|
||||||
var Animated = require('Animated');
|
var Animated = require('Animated');
|
||||||
|
describe('Animated tests', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
});
|
||||||
|
|
||||||
describe('Animated', () => {
|
describe('Animated', () => {
|
||||||
|
|
||||||
it('works end to end', () => {
|
it('works end to end', () => {
|
||||||
var anim = new Animated.Value(0);
|
var anim = new Animated.Value(0);
|
||||||
|
@ -147,10 +151,10 @@ describe('Animated', () => {
|
||||||
it('convert to JSON', () => {
|
it('convert to JSON', () => {
|
||||||
expect(JSON.stringify(new Animated.Value(10))).toBe('10');
|
expect(JSON.stringify(new Animated.Value(10))).toBe('10');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Animated Sequence', () => {
|
describe('Animated Sequence', () => {
|
||||||
|
|
||||||
it('works with an empty sequence', () => {
|
it('works with an empty sequence', () => {
|
||||||
var cb = jest.fn();
|
var cb = jest.fn();
|
||||||
|
@ -214,10 +218,9 @@ describe('Animated Sequence', () => {
|
||||||
|
|
||||||
expect(cb).toBeCalledWith({finished: false});
|
expect(cb).toBeCalledWith({finished: false});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Animated Parallel', () => {
|
||||||
describe('Animated Parallel', () => {
|
|
||||||
|
|
||||||
it('works with an empty parallel', () => {
|
it('works with an empty parallel', () => {
|
||||||
var cb = jest.fn();
|
var cb = jest.fn();
|
||||||
|
@ -307,9 +310,9 @@ describe('Animated Parallel', () => {
|
||||||
expect(anim2.stop.mock.calls.length).toBe(1);
|
expect(anim2.stop.mock.calls.length).toBe(1);
|
||||||
expect(anim3.stop.mock.calls.length).toBe(1);
|
expect(anim3.stop.mock.calls.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated delays', () => {
|
describe('Animated delays', () => {
|
||||||
it('should call anim after delay in sequence', () => {
|
it('should call anim after delay in sequence', () => {
|
||||||
var anim = {start: jest.fn(), stop: jest.fn()};
|
var anim = {start: jest.fn(), stop: jest.fn()};
|
||||||
var cb = jest.fn();
|
var cb = jest.fn();
|
||||||
|
@ -333,9 +336,9 @@ describe('Animated delays', () => {
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
expect(cb).toBeCalledWith({finished: true});
|
expect(cb).toBeCalledWith({finished: true});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Events', () => {
|
describe('Animated Events', () => {
|
||||||
it('should map events', () => {
|
it('should map events', () => {
|
||||||
var value = new Animated.Value(0);
|
var value = new Animated.Value(0);
|
||||||
var handler = Animated.event(
|
var handler = Animated.event(
|
||||||
|
@ -356,9 +359,9 @@ describe('Animated Events', () => {
|
||||||
expect(listener.mock.calls.length).toBe(1);
|
expect(listener.mock.calls.length).toBe(1);
|
||||||
expect(listener).toBeCalledWith({foo: 42});
|
expect(listener).toBeCalledWith({foo: 42});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Interactions', () => {
|
describe('Animated Interactions', () => {
|
||||||
/*eslint-disable no-shadow*/
|
/*eslint-disable no-shadow*/
|
||||||
var Animated;
|
var Animated;
|
||||||
/*eslint-enable*/
|
/*eslint-enable*/
|
||||||
|
@ -404,9 +407,9 @@ describe('Animated Interactions', () => {
|
||||||
expect(InteractionManager.clearInteractionHandle).not.toBeCalled();
|
expect(InteractionManager.clearInteractionHandle).not.toBeCalled();
|
||||||
expect(callback).toBeCalledWith({finished: true});
|
expect(callback).toBeCalledWith({finished: true});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Tracking', () => {
|
describe('Animated Tracking', () => {
|
||||||
it('should track values', () => {
|
it('should track values', () => {
|
||||||
var value1 = new Animated.Value(0);
|
var value1 = new Animated.Value(0);
|
||||||
var value2 = new Animated.Value(0);
|
var value2 = new Animated.Value(0);
|
||||||
|
@ -450,9 +453,9 @@ describe('Animated Tracking', () => {
|
||||||
value1.setValue(1492);
|
value1.setValue(1492);
|
||||||
expect(value2.__getValue()).toBe(7);
|
expect(value2.__getValue()).toBe(7);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Vectors', () => {
|
describe('Animated Vectors', () => {
|
||||||
it('should animate vectors', () => {
|
it('should animate vectors', () => {
|
||||||
var vec = new Animated.ValueXY();
|
var vec = new Animated.ValueXY();
|
||||||
|
|
||||||
|
@ -536,9 +539,9 @@ describe('Animated Vectors', () => {
|
||||||
expect(Math.round(value2.__getValue().x)).toEqual(2);
|
expect(Math.round(value2.__getValue().x)).toEqual(2);
|
||||||
expect(Math.round(value2.__getValue().y)).toEqual(2);
|
expect(Math.round(value2.__getValue().y)).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Listeners', () => {
|
describe('Animated Listeners', () => {
|
||||||
it('should get updates', () => {
|
it('should get updates', () => {
|
||||||
var value1 = new Animated.Value(0);
|
var value1 = new Animated.Value(0);
|
||||||
var listener = jest.fn();
|
var listener = jest.fn();
|
||||||
|
@ -568,9 +571,9 @@ describe('Animated Listeners', () => {
|
||||||
value1.setValue(7);
|
value1.setValue(7);
|
||||||
expect(listener.mock.calls.length).toBe(4);
|
expect(listener.mock.calls.length).toBe(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Animated Diff Clamp', () => {
|
describe('Animated Diff Clamp', () => {
|
||||||
it('should get the proper value', () => {
|
it('should get the proper value', () => {
|
||||||
const inputValues = [0, 20, 40, 30, 0, -40, -10, -20, 0];
|
const inputValues = [0, 20, 40, 30, 0, -40, -10, -20, 0];
|
||||||
const expectedValues = [0, 20, 20, 10, 0, 0, 20, 10, 20];
|
const expectedValues = [0, 20, 20, 10, 0, 0, 20, 10, 20];
|
||||||
|
@ -581,4 +584,5 @@ describe('Animated Diff Clamp', () => {
|
||||||
expect(diffClampValue.__getValue()).toBe(expectedValues[i]);
|
expect(diffClampValue.__getValue()).toBe(expectedValues[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
jest.autoMockOff();
|
jest.autoMockOff();
|
||||||
|
@ -6,7 +15,9 @@ const getProjectDependencies = require('../getProjectDependencies');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
describe('getProjectDependencies', () => {
|
describe('getProjectDependencies', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
});
|
||||||
it('should return an array of project dependencies', () => {
|
it('should return an array of project dependencies', () => {
|
||||||
jest.setMock(
|
jest.setMock(
|
||||||
path.join(process.cwd(), './package.json'),
|
path.join(process.cwd(), './package.json'),
|
||||||
|
|
|
@ -21,6 +21,7 @@ jest.setMock(
|
||||||
|
|
||||||
describe('link', () => {
|
describe('link', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
delete require.cache[require.resolve('../link')];
|
delete require.cache[require.resolve('../link')];
|
||||||
log.level = 'silent';
|
log.level = 'silent';
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
"jestSupport/env.js"
|
"jestSupport/env.js"
|
||||||
],
|
],
|
||||||
"timers": "fake",
|
"timers": "fake",
|
||||||
"resetModules": true,
|
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
|
"^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
|
||||||
"^[./a-zA-Z0-9$_-]+\\.png$": "RelativeImageStub"
|
"^[./a-zA-Z0-9$_-]+\\.png$": "RelativeImageStub"
|
||||||
|
|
|
@ -21,6 +21,7 @@ describe('code transformation worker:', () => {
|
||||||
|
|
||||||
let extractDependencies, transform;
|
let extractDependencies, transform;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
({transformCode} = require('..'));
|
({transformCode} = require('..'));
|
||||||
extractDependencies =
|
extractDependencies =
|
||||||
require('../extract-dependencies').mockReturnValue({});
|
require('../extract-dependencies').mockReturnValue({});
|
||||||
|
@ -58,7 +59,10 @@ describe('code transformation worker:', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes the leading assignment to `module.exports` before passing on the result if the file is a JSON file, even if minified', done => {
|
it(
|
||||||
|
'removes the leading assignment to `module.exports` before passing ' +
|
||||||
|
'on the result if the file is a JSON file, even if minified',
|
||||||
|
done => {
|
||||||
const result = {
|
const result = {
|
||||||
code: 'p.exports={a:1,b:2}',
|
code: 'p.exports={a:1,b:2}',
|
||||||
};
|
};
|
||||||
|
@ -69,7 +73,8 @@ describe('code transformation worker:', () => {
|
||||||
expect(data.code).toBe('{a:1,b:2}');
|
expect(data.code).toBe('{a:1,b:2}');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it('removes shebang when present', done => {
|
it('removes shebang when present', done => {
|
||||||
const shebang = '#!/usr/bin/env node';
|
const shebang = '#!/usr/bin/env node';
|
||||||
|
@ -110,7 +115,10 @@ describe('code transformation worker:', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses `dependencies` and `dependencyOffsets` provided by `extractDependencies` for the result', done => {
|
it(
|
||||||
|
'uses `dependencies` and `dependencyOffsets` ' +
|
||||||
|
'provided by `extractDependencies` for the result',
|
||||||
|
done => {
|
||||||
const dependencyData = {
|
const dependencyData = {
|
||||||
dependencies: ['arbitrary', 'list', 'of', 'dependencies'],
|
dependencies: ['arbitrary', 'list', 'of', 'dependencies'],
|
||||||
dependencyOffsets: [12, 119, 185, 328, 471],
|
dependencyOffsets: [12, 119, 185, 328, 471],
|
||||||
|
@ -121,24 +129,37 @@ describe('code transformation worker:', () => {
|
||||||
expect(data).toEqual(objectContaining(dependencyData));
|
expect(data).toEqual(objectContaining(dependencyData));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it('does not extract requires if files are marked as "extern"', done => {
|
it('does not extract requires if files are marked as "extern"', done => {
|
||||||
transformCode(transform, 'filename', 'code', {extern: true}, (_, {dependencies, dependencyOffsets}) => {
|
transformCode(
|
||||||
|
transform,
|
||||||
|
'filename',
|
||||||
|
'code',
|
||||||
|
{extern: true},
|
||||||
|
(_, {dependencies, dependencyOffsets}) => {
|
||||||
expect(extractDependencies).not.toBeCalled();
|
expect(extractDependencies).not.toBeCalled();
|
||||||
expect(dependencies).toEqual([]);
|
expect(dependencies).toEqual([]);
|
||||||
expect(dependencyOffsets).toEqual([]);
|
expect(dependencyOffsets).toEqual([]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not extract requires of JSON files', done => {
|
it('does not extract requires of JSON files', done => {
|
||||||
transformCode(transform, 'arbitrary.json', '{"arbitrary":"json"}', {}, (_, {dependencies, dependencyOffsets}) => {
|
transformCode(
|
||||||
|
transform,
|
||||||
|
'arbitrary.json',
|
||||||
|
'{"arbitrary":"json"}',
|
||||||
|
{},
|
||||||
|
(_, {dependencies, dependencyOffsets}) => {
|
||||||
expect(extractDependencies).not.toBeCalled();
|
expect(extractDependencies).not.toBeCalled();
|
||||||
expect(dependencies).toEqual([]);
|
expect(dependencies).toEqual([]);
|
||||||
expect(dependencyOffsets).toEqual([]);
|
expect(dependencyOffsets).toEqual([]);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ let FileWatcher;
|
||||||
describe('processRequest', () => {
|
describe('processRequest', () => {
|
||||||
let SourceMapConsumer, Bundler, Server, AssetServer, Promise;
|
let SourceMapConsumer, Bundler, Server, AssetServer, Promise;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
SourceMapConsumer = require('source-map').SourceMapConsumer;
|
SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||||
Bundler = require('../../Bundler');
|
Bundler = require('../../Bundler');
|
||||||
Server = require('../');
|
Server = require('../');
|
||||||
|
@ -253,7 +254,10 @@ describe('processRequest', () => {
|
||||||
jest.runAllTicks();
|
jest.runAllTicks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not rebuild the bundles that contain a file when that file is changed, even when hot loading is enabled', () => {
|
it(
|
||||||
|
'does not rebuild the bundles that contain a file ' +
|
||||||
|
'when that file is changed, even when hot loading is enabled',
|
||||||
|
() => {
|
||||||
const bundleFunc = jest.fn();
|
const bundleFunc = jest.fn();
|
||||||
bundleFunc
|
bundleFunc
|
||||||
.mockReturnValueOnce(
|
.mockReturnValueOnce(
|
||||||
|
@ -382,7 +386,10 @@ describe('processRequest', () => {
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
expect(AssetServer.prototype.get).toBeCalledWith('imgs/主页/logo.png', undefined);
|
expect(AssetServer.prototype.get).toBeCalledWith(
|
||||||
|
'imgs/\u{4E3B}\u{9875}/logo.png',
|
||||||
|
undefined
|
||||||
|
);
|
||||||
expect(res.setHeader).toBeCalledWith('Cache-Control', 'max-age=31536000');
|
expect(res.setHeader).toBeCalledWith('Cache-Control', 'max-age=31536000');
|
||||||
expect(res.end).toBeCalledWith('i am image');
|
expect(res.end).toBeCalledWith('i am image');
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,7 @@ describe('FileWatcher', () => {
|
||||||
let config;
|
let config;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
const sane = require('sane');
|
const sane = require('sane');
|
||||||
WatchmanWatcher = sane.WatchmanWatcher;
|
WatchmanWatcher = sane.WatchmanWatcher;
|
||||||
WatchmanWatcher.prototype.once.mockImplementation(
|
WatchmanWatcher.prototype.once.mockImplementation(
|
||||||
|
|
|
@ -40,6 +40,8 @@ describe('DependencyGraph', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
jest.resetModules();
|
||||||
|
|
||||||
Module = require('../Module');
|
Module = require('../Module');
|
||||||
const fileWatcher = {
|
const fileWatcher = {
|
||||||
on: function() {
|
on: function() {
|
||||||
|
@ -245,7 +247,7 @@ describe('DependencyGraph', function() {
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
return getOrderedDependenciesAsJSON(dgraph, '/root/index.js', null, false).then(function(deps) {
|
return getOrderedDependenciesAsJSON(dgraph, '/root/index.js', null, false).then((deps) => {
|
||||||
expect(deps)
|
expect(deps)
|
||||||
.toEqual([
|
.toEqual([
|
||||||
{
|
{
|
||||||
|
@ -1918,7 +1920,7 @@ describe('DependencyGraph', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should support browser mapping of a package to a file ("' + fieldName + '")', function() {
|
pit('should support browser mapping of a package to a file ("' + fieldName + '")', () => {
|
||||||
var root = '/root';
|
var root = '/root';
|
||||||
setMockFileSystem({
|
setMockFileSystem({
|
||||||
'root': {
|
'root': {
|
||||||
|
@ -2337,7 +2339,8 @@ describe('DependencyGraph', function() {
|
||||||
'node-package-c': 'rn-package-c',
|
'node-package-c': 'rn-package-c',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
'index.js': 'require("node-package-a"); require("node-package-b"); require("node-package-c");',
|
'index.js':
|
||||||
|
'require("node-package-a"); require("node-package-b"); require("node-package-c");',
|
||||||
'node_modules': {
|
'node_modules': {
|
||||||
'node-package-a': {
|
'node-package-a': {
|
||||||
'package.json': JSON.stringify({
|
'package.json': JSON.stringify({
|
||||||
|
@ -2510,7 +2513,9 @@ describe('DependencyGraph', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should only use `extraNodeModules` after checking all possible filesystem locations', () => {
|
pit(
|
||||||
|
'should only use `extraNodeModules` after checking all possible filesystem locations',
|
||||||
|
() => {
|
||||||
const root = '/root';
|
const root = '/root';
|
||||||
setMockFileSystem({
|
setMockFileSystem({
|
||||||
[root.slice(1)]: {
|
[root.slice(1)]: {
|
||||||
|
@ -2553,7 +2558,8 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
pit('should be able to resolve paths within `extraNodeModules`', () => {
|
pit('should be able to resolve paths within `extraNodeModules`', () => {
|
||||||
const root = '/root';
|
const root = '/root';
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Joyent, Inc. and other Node contributors.
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
@ -50,6 +59,7 @@ describe('fast-path', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
jest.resetModules();
|
||||||
process.platform = 'linux';
|
process.platform = 'linux';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue