index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>lodash Test Suite</title>
  6. <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
  7. <style>
  8. #exports, #module {
  9. display: none;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <script>
  15. // Avoid reporting tests to Sauce Labs when script errors occur.
  16. if (location.port == '9001') {
  17. window.onerror = function(message) {
  18. if (window.QUnit) {
  19. QUnit.config.done.length = 0;
  20. }
  21. global_test_results = { 'message': message };
  22. };
  23. }
  24. </script>
  25. <script src="../node_modules/lodash/lodash.js"></script>
  26. <script>var lodashStable = _.noConflict();</script>
  27. <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
  28. <script src="../node_modules/qunit-extras/qunit-extras.js"></script>
  29. <script src="../node_modules/platform/platform.js"></script>
  30. <script src="./asset/test-ui.js"></script>
  31. <div id="qunit"></div>
  32. <div id="exports"></div>
  33. <div id="module"></div>
  34. <script>
  35. function setProperty(object, key, value) {
  36. try {
  37. Object.defineProperty(object, key, {
  38. 'configurable': true,
  39. 'enumerable': false,
  40. 'writable': true,
  41. 'value': value
  42. });
  43. } catch (e) {
  44. object[key] = value;
  45. }
  46. return object;
  47. }
  48. function addBizarroMethods() {
  49. var funcProto = Function.prototype,
  50. objectProto = Object.prototype;
  51. var hasOwnProperty = objectProto.hasOwnProperty,
  52. fnToString = funcProto.toString,
  53. nativeString = fnToString.call(objectProto.toString),
  54. noop = function() {},
  55. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  56. reToString = /toString/g;
  57. function constant(value) {
  58. return function() {
  59. return value;
  60. };
  61. }
  62. function createToString(funcName) {
  63. return constant(nativeString.replace(reToString, funcName));
  64. }
  65. // Allow bypassing native checks.
  66. setProperty(funcProto, 'toString', (function() {
  67. function wrapper() {
  68. setProperty(funcProto, 'toString', fnToString);
  69. var result = hasOwnProperty.call(this, 'toString') ? this.toString() : fnToString.call(this);
  70. setProperty(funcProto, 'toString', wrapper);
  71. return result;
  72. }
  73. return wrapper;
  74. }()));
  75. // Add prototype extensions.
  76. funcProto._method = noop;
  77. // Set bad shims.
  78. setProperty(Object, '_create', Object.create);
  79. setProperty(Object, 'create', (function() {
  80. function object() {}
  81. return function(prototype) {
  82. if (prototype === Object(prototype)) {
  83. object.prototype = prototype;
  84. var result = new object;
  85. object.prototype = undefined;
  86. }
  87. return result || {};
  88. };
  89. }()));
  90. setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
  91. setProperty(Object, 'getOwnPropertySymbols', undefined);
  92. setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
  93. setProperty(objectProto, 'propertyIsEnumerable', function(key) {
  94. return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
  95. });
  96. setProperty(window, '_Map', window.Map);
  97. if (_Map) {
  98. setProperty(window, 'Map', (function(Map) {
  99. var count = 0;
  100. return function() {
  101. if (count++) {
  102. return new Map;
  103. }
  104. var result = {};
  105. setProperty(window, 'Map', Map);
  106. return result;
  107. };
  108. }(_Map)));
  109. setProperty(Map, 'toString', createToString('Map'));
  110. }
  111. setProperty(window, '_Promise', window.Promise);
  112. setProperty(window, 'Promise', noop);
  113. setProperty(window, '_Set', window.Set);
  114. setProperty(window, 'Set', noop);
  115. setProperty(window, '_Symbol', window.Symbol);
  116. setProperty(window, 'Symbol', undefined);
  117. setProperty(window, '_WeakMap', window.WeakMap);
  118. setProperty(window, 'WeakMap', noop);
  119. // Fake `WinRTError`.
  120. setProperty(window, 'WinRTError', Error);
  121. // Fake free variable `global`.
  122. setProperty(window, 'exports', window);
  123. setProperty(window, 'global', window);
  124. setProperty(window, 'module', {});
  125. }
  126. function removeBizarroMethods() {
  127. var funcProto = Function.prototype,
  128. objectProto = Object.prototype;
  129. setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
  130. if (Object._create) {
  131. Object.create = Object._create;
  132. } else {
  133. delete Object.create;
  134. }
  135. if (Object._getOwnPropertySymbols) {
  136. Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
  137. } else {
  138. delete Object.getOwnPropertySymbols;
  139. }
  140. if (_Map) {
  141. Map = _Map;
  142. } else {
  143. setProperty(window, 'Map', undefined);
  144. }
  145. if (_Promise) {
  146. Promise = _Promise;
  147. } else {
  148. setProperty(window, 'Promise', undefined);
  149. }
  150. if (_Set) {
  151. Set = _Set;
  152. } else {
  153. setProperty(window, 'Set', undefined);
  154. }
  155. if (_Symbol) {
  156. Symbol = _Symbol;
  157. }
  158. if (_WeakMap) {
  159. WeakMap = _WeakMap;
  160. } else {
  161. setProperty(window, 'WeakMap', undefined);
  162. }
  163. setProperty(window, '_Map', undefined);
  164. setProperty(window, '_Promise', undefined);
  165. setProperty(window, '_Set', undefined);
  166. setProperty(window, '_Symbol', undefined);
  167. setProperty(window, '_WeakMap', undefined);
  168. setProperty(window, 'WinRTError', undefined);
  169. setProperty(window, 'exports', document.getElementById('exports'));
  170. setProperty(window, 'global', undefined);
  171. setProperty(window, 'module', document.getElementById('module'));
  172. delete funcProto._method;
  173. delete Object._create;
  174. delete Object._getOwnPropertySymbols;
  175. delete objectProto._propertyIsEnumerable;
  176. }
  177. // Load lodash to expose it to the bad extensions/shims.
  178. if (!ui.isModularize) {
  179. addBizarroMethods();
  180. document.write('<script src="' + ui.buildPath + '"><\/script>');
  181. }
  182. </script>
  183. <script>
  184. // Store lodash to test for bad extensions/shims.
  185. if (!ui.isModularize) {
  186. var lodashBizarro = window._;
  187. window._ = undefined;
  188. removeBizarroMethods();
  189. }
  190. // Load test scripts.
  191. document.write((ui.isForeign || ui.urlParams.loader == 'none')
  192. ? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
  193. : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
  194. );
  195. </script>
  196. <script>
  197. var lodashModule,
  198. shimmedModule,
  199. underscoreModule;
  200. (function() {
  201. if (window.curl) {
  202. curl.config({ 'apiName': 'require' });
  203. }
  204. if (ui.isForeign || !window.require) {
  205. return;
  206. }
  207. var reBasename = /[\w.-]+$/,
  208. basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
  209. modulePath = ui.buildPath.replace(/\.js$/, ''),
  210. moduleMain = modulePath.match(reBasename)[0],
  211. locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
  212. shimmedLocationPath = './abc/../' + locationPath,
  213. underscoreLocationPath = './xyz/../' + locationPath,
  214. uid = +new Date;
  215. function getConfig() {
  216. var result = {
  217. 'baseUrl': './',
  218. 'urlArgs': 't=' + uid++,
  219. 'waitSeconds': 0,
  220. 'paths': {},
  221. 'packages': [{
  222. 'name': 'test',
  223. 'location': basePath + 'test',
  224. 'main': 'test',
  225. 'config': {
  226. // Work around no global being exported.
  227. 'exports': 'QUnit',
  228. 'loader': 'curl/loader/legacy'
  229. }
  230. }],
  231. 'shim': {
  232. 'shimmed': {
  233. 'exports': '_'
  234. }
  235. }
  236. };
  237. if (ui.isModularize) {
  238. result.packages.push({
  239. 'name': 'lodash',
  240. 'location': locationPath,
  241. 'main': moduleMain
  242. }, {
  243. 'name': 'shimmed',
  244. 'location': shimmedLocationPath,
  245. 'main': moduleMain
  246. }, {
  247. 'name': 'underscore',
  248. 'location': underscoreLocationPath,
  249. 'main': moduleMain
  250. });
  251. } else {
  252. result.paths.lodash = modulePath;
  253. result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
  254. result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
  255. }
  256. return result;
  257. }
  258. function loadTests() {
  259. require(getConfig(), ['test'], function() {
  260. QUnit.start();
  261. });
  262. }
  263. function loadModulesAndTests() {
  264. require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
  265. lodashModule = lodash;
  266. lodashModule.moduleName = 'lodash';
  267. if (shimmed) {
  268. shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
  269. shimmedModule.moduleName = 'shimmed';
  270. }
  271. if (underscore) {
  272. underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
  273. underscoreModule.moduleName = 'underscore';
  274. }
  275. window._ = lodash;
  276. if (ui.isModularize) {
  277. require(getConfig(), [
  278. 'lodash/_baseEach',
  279. 'lodash/_isIndex',
  280. 'lodash/_isIterateeCall'
  281. ], function(baseEach, isIndex, isIterateeCall) {
  282. lodash._baseEach = baseEach;
  283. lodash._isIndex = isIndex;
  284. lodash._isIterateeCall = isIterateeCall;
  285. loadTests();
  286. });
  287. } else {
  288. loadTests();
  289. }
  290. });
  291. }
  292. QUnit.config.autostart = false;
  293. if (window.requirejs) {
  294. addBizarroMethods();
  295. require(getConfig(), ['lodash'], function(lodash) {
  296. lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
  297. delete requirejs.s.contexts._;
  298. removeBizarroMethods();
  299. loadModulesAndTests();
  300. });
  301. } else {
  302. loadModulesAndTests();
  303. }
  304. }());
  305. // Set a more readable browser name.
  306. window.onload = function() {
  307. var timeoutId = setInterval(function() {
  308. var ua = document.getElementById('qunit-userAgent');
  309. if (ua) {
  310. ua.innerHTML = platform;
  311. clearInterval(timeoutId);
  312. }
  313. }, 16);
  314. };
  315. </script>
  316. </body>
  317. </html>