Adjust mocking to ensure coverage in modularized builds.

This commit is contained in:
John-David Dalton
2014-08-26 09:33:03 -07:00
parent cc4fdfd852
commit 81d0d5c59f
2 changed files with 33 additions and 26 deletions

View File

@@ -115,9 +115,6 @@
setProperty(stringProto, '_contains', stringProto.contains); setProperty(stringProto, '_contains', stringProto.contains);
setProperty(stringProto, 'contains', stringProto._contains ? noop : Boolean); setProperty(stringProto, 'contains', stringProto._contains ? noop : Boolean);
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
document.createDocumentFragment = noop;
setProperty(window, '_ArrayBuffer', window.ArrayBuffer); setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
if (window.ArrayBuffer && window.Uint8Array) { if (window.ArrayBuffer && window.Uint8Array) {
ArrayBuffer = (function(_ArrayBuffer) { ArrayBuffer = (function(_ArrayBuffer) {
@@ -175,6 +172,10 @@
}; };
}(_parseInt))); }(_parseInt)));
// fake lack of DOM support
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
document.createDocumentFragment = noop;
// fake `WinRTError` // fake `WinRTError`
setProperty(window, 'WinRTError', Error); setProperty(window, 'WinRTError', Error);
@@ -224,11 +225,6 @@
} else { } else {
delete stringProto.contains; delete stringProto.contains;
} }
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
document.createDocumentFragment = document._createDocumentFragment;
setProperty(document, '_createDocumentFragment', undefined);
if (window._ArrayBuffer) { if (window._ArrayBuffer) {
ArrayBuffer = _ArrayBuffer; ArrayBuffer = _ArrayBuffer;
} }
@@ -247,12 +243,17 @@
setProperty(window, 'parseInt', window._parseInt); setProperty(window, 'parseInt', window._parseInt);
setProperty(window, '_parseInt', undefined); setProperty(window, '_parseInt', undefined);
document.createDocumentFragment = document._createDocumentFragment;
setProperty(document, '_createDocumentFragment', undefined);
setProperty(window, 'WinRTError', undefined); setProperty(window, 'WinRTError', undefined);
setProperty(window, 'exports', undefined); setProperty(window, 'exports', undefined);
setProperty(window, 'global', undefined); setProperty(window, 'global', undefined);
setProperty(window, 'module', undefined); setProperty(window, 'module', undefined);
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
delete Array._isArray; delete Array._isArray;
delete Date._now; delete Date._now;
delete funcProto._method; delete funcProto._method;

View File

@@ -38,12 +38,10 @@
noop = function() {}, noop = function() {},
params = root.arguments, params = root.arguments,
push = arrayProto.push, push = arrayProto.push,
Set = root.Set,
slice = arrayProto.slice, slice = arrayProto.slice,
system = root.system, system = root.system,
toString = objectProto.toString, toString = objectProto.toString,
Uint8Array = root.Uint8Array, Uint8Array = root.Uint8Array;
WeakMap = root.WeakMap;
/** The file path of the Lo-Dash file to test */ /** The file path of the Lo-Dash file to test */
var filePath = (function() { var filePath = (function() {
@@ -119,6 +117,10 @@
? require ? require
: (isJava && root.load) || noop; : (isJava && root.load) || noop;
/** Load ES6 Set and WeakMap shims */
load('./asset/set.js');
load('./asset/weakmap.js');
/** The unit testing framework */ /** The unit testing framework */
var QUnit = (function() { var QUnit = (function() {
return root.QUnit || ( return root.QUnit || (
@@ -340,9 +342,6 @@
function createToString(funcName) { function createToString(funcName) {
return _.constant(nativeString.replace(reToString, funcName)); return _.constant(nativeString.replace(reToString, funcName));
} }
// load ES6 Set and WeakMap shims
require('./asset/set');
require('./asset/weakmap');
// expose `baseEach` for better code coverage // expose `baseEach` for better code coverage
if (isModularize && !isNpm) { if (isModularize && !isNpm) {
@@ -442,14 +441,11 @@
}; };
}())); }()));
if (Set) { var _Set = root.Set;
setProperty(root, 'Set', _.noop); setProperty(root, 'Set', _.noop);
}
if (WeakMap) { var _WeakMap = root.WeakMap;
setProperty(root, 'WeakMap', _.noop); setProperty(root, 'WeakMap', _.noop);
}
// fake `WinRTError`
setProperty(root, 'WinRTError', Error);
// fake DOM // fake DOM
setProperty(root, 'window', {}); setProperty(root, 'window', {});
@@ -458,6 +454,9 @@
return { 'nodeType': 11 }; return { 'nodeType': 11 };
}); });
// fake `WinRTError`
setProperty(root, 'WinRTError', Error);
// clear cache so Lo-Dash can be reloaded // clear cache so Lo-Dash can be reloaded
emptyObject(require.cache); emptyObject(require.cache);
@@ -490,12 +489,12 @@
} else { } else {
delete root.ArrayBuffer; delete root.ArrayBuffer;
} }
if (Set) { if (_Set) {
setProperty(root, 'Set', Set); setProperty(root, 'Set', Set);
} else { } else {
delete root.Set; delete root.Set;
} }
if (WeakMap) { if (_WeakMap) {
setProperty(root, 'WeakMap', WeakMap); setProperty(root, 'WeakMap', WeakMap);
} else { } else {
delete root.WeakMap; delete root.WeakMap;
@@ -614,7 +613,7 @@
} }
}); });
test('should avoid overwritten native methods', 14, function() { test('should avoid overwritten native methods', 15, function() {
function Foo() {} function Foo() {}
function message(lodashMethod, nativeMethod) { function message(lodashMethod, nativeMethod) {
@@ -648,6 +647,13 @@
ok(actual[0] instanceof Foo, message('_.create', 'Object.create')); ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
deepEqual(actual[1], {}, message('_.create', 'Object.create')); deepEqual(actual[1], {}, message('_.create', 'Object.create'));
try {
actual = lodashBizarro.curry(function(a, b) { return [a, b]; })(1)(2);
} catch(e) {
actual = null;
}
deepEqual(actual, [1, 2], message('_.curry', 'Object.defineProperty'));
try { try {
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])]; actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
} catch(e) { } catch(e) {
@@ -716,7 +722,7 @@
} }
} }
else { else {
skipTest(14); skipTest(15);
} }
}); });
}()); }());