mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Add initial test files from lodash v4. (#4172)
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
151
test/basename.js
Normal file
151
test/basename.js
Normal file
@@ -0,0 +1,151 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
|
||||
import {
|
||||
basename,
|
||||
amd,
|
||||
ui,
|
||||
Worker,
|
||||
QUnit,
|
||||
lodashBizarro,
|
||||
LARGE_ARRAY_SIZE,
|
||||
symbol,
|
||||
setProperty,
|
||||
} from './utils.js';
|
||||
|
||||
import _VERSION from '../.internal/VERSION.js';
|
||||
import VERSION from '../VERSION.js';
|
||||
|
||||
describe(basename, function() {
|
||||
it('should support loading ' + basename + ' as the "lodash" module', function() {
|
||||
if (amd) {
|
||||
assert.strictEqual((lodashModule || {}).moduleName, 'lodash');
|
||||
}
|
||||
});
|
||||
|
||||
it('should support loading ' + basename + ' with the Require.js "shim" configuration option', function() {
|
||||
if (amd && lodashStable.includes(ui.loaderPath, 'requirejs')) {
|
||||
assert.strictEqual((shimmedModule || {}).moduleName, 'shimmed');
|
||||
}
|
||||
});
|
||||
|
||||
it('should support loading ' + basename + ' as the "underscore" module', function() {
|
||||
if (amd) {
|
||||
assert.strictEqual((underscoreModule || {}).moduleName, 'underscore');
|
||||
}
|
||||
});
|
||||
|
||||
it('should support loading ' + basename + ' in a web worker', function(done) {
|
||||
if (Worker) {
|
||||
var limit = 30000 / QUnit.config.asyncRetries,
|
||||
start = +new Date;
|
||||
|
||||
var attempt = function() {
|
||||
var actual = _VERSION;
|
||||
if ((new Date - start) < limit && typeof actual != 'string') {
|
||||
setTimeout(attempt, 16);
|
||||
return;
|
||||
}
|
||||
assert.strictEqual(actual, VERSION);
|
||||
done();
|
||||
};
|
||||
|
||||
attempt();
|
||||
}
|
||||
else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should not add `Function.prototype` extensions to lodash', function() {
|
||||
if (lodashBizarro) {
|
||||
assert.ok(!('_method' in lodashBizarro));
|
||||
}
|
||||
});
|
||||
|
||||
it('should avoid non-native built-ins', function() {
|
||||
function message(lodashMethod, nativeMethod) {
|
||||
return '`' + lodashMethod + '` should avoid overwritten native `' + nativeMethod + '`';
|
||||
}
|
||||
|
||||
function Foo() {
|
||||
this.a = 1;
|
||||
}
|
||||
Foo.prototype.b = 2;
|
||||
|
||||
var object = { 'a': 1 },
|
||||
otherObject = { 'b': 2 },
|
||||
largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(object));
|
||||
|
||||
if (lodashBizarro) {
|
||||
try {
|
||||
var actual = lodashBizarro.create(Foo.prototype);
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
var label = message('_.create', 'Object.create');
|
||||
assert.ok(actual instanceof Foo, label);
|
||||
|
||||
try {
|
||||
actual = [
|
||||
lodashBizarro.difference([object, otherObject], largeArray),
|
||||
lodashBizarro.intersection(largeArray, [object]),
|
||||
lodashBizarro.uniq(largeArray)
|
||||
];
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.difference`, `_.intersection`, and `_.uniq', 'Map');
|
||||
assert.deepStrictEqual(actual, [[otherObject], [object], [object]], label);
|
||||
|
||||
try {
|
||||
if (Symbol) {
|
||||
object[symbol] = {};
|
||||
}
|
||||
actual = [
|
||||
lodashBizarro.clone(object),
|
||||
lodashBizarro.cloneDeep(object)
|
||||
];
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.clone` and `_.cloneDeep', 'Object.getOwnPropertySymbols');
|
||||
assert.deepStrictEqual(actual, [object, object], label);
|
||||
|
||||
try {
|
||||
// Avoid buggy symbol detection in Babel's `_typeof` helper.
|
||||
var symObject = setProperty(Object(symbol), 'constructor', Object);
|
||||
actual = [
|
||||
Symbol ? lodashBizarro.clone(symObject) : {},
|
||||
Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
|
||||
Symbol ? lodashBizarro.toString(symObject) : ''
|
||||
];
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
|
||||
assert.deepStrictEqual(actual, [{}, false, ''], label);
|
||||
|
||||
try {
|
||||
var map = new lodashBizarro.memoize.Cache;
|
||||
actual = map.set('a', 1).get('a');
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.memoize.Cache', 'Map');
|
||||
assert.deepStrictEqual(actual, 1, label);
|
||||
|
||||
try {
|
||||
map = new (Map || Object);
|
||||
if (Symbol && Symbol.iterator) {
|
||||
map[Symbol.iterator] = null;
|
||||
}
|
||||
actual = lodashBizarro.toArray(map);
|
||||
} catch (e) {
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.toArray', 'Map');
|
||||
assert.deepStrictEqual(actual, [], label);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user