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
49      function addBizarroMethods() {
50        var funcProto = Function.prototype,
51            objectProto = Object.prototype;
52
53        var hasOwnProperty = objectProto.hasOwnProperty,
54            fnToString = funcProto.toString,
55            nativeString = fnToString.call(objectProto.toString),
56            noop = function() {},
57            propertyIsEnumerable = objectProto.propertyIsEnumerable,
58            reToString = /toString/g;
59
60        function constant(value) {
61          return function() {
62            return value;
63          };
64        }
65
66        function createToString(funcName) {
67          return constant(nativeString.replace(reToString, funcName));
68        }
69
70        // Allow bypassing native checks.
71        setProperty(funcProto, 'toString', (function() {
72          function wrapper() {
73            setProperty(funcProto, 'toString', fnToString);
74            var result = hasOwnProperty.call(this, 'toString') ? this.toString() : fnToString.call(this);
75            setProperty(funcProto, 'toString', wrapper);
76            return result;
77          }
78          return wrapper;
79        }()));
80
81        // Add prototype extensions.
82        funcProto._method = noop;
83
84        // Set bad shims.
85        setProperty(Object, '_create', Object.create);
86        setProperty(Object, 'create', undefined);
87
88        setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
89        setProperty(Object, 'getOwnPropertySymbols', undefined);
90
91        setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
92        setProperty(objectProto, 'propertyIsEnumerable', function(key) {
93          return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
94        });
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
110          setProperty(Map, 'toString', createToString('Map'));
111        }
112        setProperty(window, '_Promise', window.Promise);
113        setProperty(window, 'Promise', noop);
114
115        setProperty(window, '_Set', window.Set);
116        setProperty(window, 'Set', noop);
117
118        setProperty(window, '_Symbol', window.Symbol);
119        setProperty(window, 'Symbol', undefined);
120
121        setProperty(window, '_WeakMap', window.WeakMap);
122        setProperty(window, 'WeakMap', noop);
123
124        // Fake `WinRTError`.
125        setProperty(window, 'WinRTError', Error);
126
127        // Fake free variable `global`.
128        setProperty(window, 'exports', window);
129        setProperty(window, 'global', window);
130        setProperty(window, 'module', {});
131      }
132
133      function removeBizarroMethods() {
134        var funcProto = Function.prototype,
135            objectProto = Object.prototype;
136
137        setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
138
139        if (Object._create) {
140          Object.create = Object._create;
141        } else {
142          delete Object.create;
143        }
144        if (Object._getOwnPropertySymbols) {
145          Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
146        } else {
147          delete Object.getOwnPropertySymbols;
148        }
149        if (_Map) {
150          Map = _Map;
151        } else {
152          setProperty(window, 'Map', undefined);
153        }
154        if (_Promise) {
155          Promise = _Promise;
156        } else {
157          setProperty(window, 'Promise', undefined);
158        }
159        if (_Set) {
160          Set = _Set;
161        } else {
162          setProperty(window, 'Set', undefined);
163        }
164        if (_Symbol) {
165          Symbol = _Symbol;
166        }
167        if (_WeakMap) {
168          WeakMap = _WeakMap;
169        } else {
170          setProperty(window, 'WeakMap', undefined);
171        }
172        setProperty(window, '_Map', undefined);
173        setProperty(window, '_Promise', undefined);
174        setProperty(window, '_Set', undefined);
175        setProperty(window, '_Symbol', undefined);
176        setProperty(window, '_WeakMap', undefined);
177
178        setProperty(window, 'WinRTError', undefined);
179
180        setProperty(window, 'exports', document.getElementById('exports'));
181        setProperty(window, 'global', undefined);
182        setProperty(window, 'module', document.getElementById('module'));
183
184        delete funcProto._method;
185        delete Object._create;
186        delete Object._getOwnPropertySymbols;
187        delete objectProto._propertyIsEnumerable;
188      }
189
190      // Load lodash to expose it to the bad extensions/shims.
191      if (!ui.isModularize) {
192        addBizarroMethods();
193        document.write('<script src="' + ui.buildPath + '"><\/script>');
194      }
195    </script>
196    <script>
197      // Store lodash to test for bad extensions/shims.
198      if (!ui.isModularize) {
199        var lodashBizarro = window._;
200        window._ = undefined;
201        removeBizarroMethods();
202      }
203      // Load test scripts.
204      document.write((ui.isForeign || ui.urlParams.loader == 'none')
205        ? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
206        : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
207      );
208    </script>
209    <script>
210      var lodashModule,
211          shimmedModule,
212          underscoreModule;
213
214      (function() {
215        if (window.curl) {
216          curl.config({ 'apiName': 'require' });
217        }
218        if (ui.isForeign || !window.require) {
219          return;
220        }
221        var reBasename = /[\w.-]+$/,
222            basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
223            modulePath = ui.buildPath.replace(/\.js$/, ''),
224            moduleMain = modulePath.match(reBasename)[0],
225            locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
226            shimmedLocationPath = './abc/../' + locationPath,
227            underscoreLocationPath = './xyz/../' + locationPath,
228            uid = +new Date;
229
230        function getConfig() {
231          var result = {
232            'baseUrl': './',
233            'urlArgs': 't=' + uid++,
234            'waitSeconds': 0,
235            'paths': {},
236            'packages': [{
237              'name': 'test',
238              'location': basePath + 'test',
239              'main': 'test',
240              'config': {
241                // Work around no global being exported.
242                'exports': 'QUnit',
243                'loader': 'curl/loader/legacy'
244              }
245            }],
246            'shim': {
247              'shimmed': {
248                'exports': '_'
249              }
250            }
251          };
252
253          if (ui.isModularize) {
254            result.packages.push({
255              'name': 'lodash',
256              'location': locationPath,
257              'main': moduleMain
258            }, {
259              'name': 'shimmed',
260              'location': shimmedLocationPath,
261              'main': moduleMain
262            }, {
263              'name': 'underscore',
264              'location': underscoreLocationPath,
265              'main': moduleMain
266            });
267          } else {
268            result.paths.lodash = modulePath;
269            result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
270            result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
271          }
272          return result;
273        }
274
275        function loadTests() {
276          require(getConfig(), ['test'], function() {
277            QUnit.start();
278          });
279        }
280
281        function loadModulesAndTests() {
282          require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
283            lodashModule = lodash;
284            lodashModule.moduleName = 'lodash';
285
286            if (shimmed) {
287              shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
288              shimmedModule.moduleName = 'shimmed';
289            }
290            if (underscore) {
291              underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
292              underscoreModule.moduleName = 'underscore';
293            }
294            window._ = lodash;
295
296            if (ui.isModularize) {
297              require(getConfig(), [
298                'lodash/_baseEach',
299                'lodash/_isIndex',
300                'lodash/_isIterateeCall'
301              ], function(baseEach, isIndex, isIterateeCall) {
302                lodash._baseEach = baseEach;
303                lodash._isIndex = isIndex;
304                lodash._isIterateeCall = isIterateeCall;
305                loadTests();
306              });
307            } else {
308              loadTests();
309            }
310          });
311        }
312
313        QUnit.config.autostart = false;
314
315        if (window.requirejs) {
316          addBizarroMethods();
317          require(getConfig(), ['lodash'], function(lodash) {
318            lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
319            delete requirejs.s.contexts._;
320
321            removeBizarroMethods();
322            loadModulesAndTests();
323          });
324        } else {
325          loadModulesAndTests();
326        }
327      }());
328
329      // Set a more readable browser name.
330      window.onload = function() {
331        var timeoutId = setInterval(function() {
332          var ua = document.getElementById('qunit-userAgent');
333          if (ua) {
334            ua.innerHTML = platform;
335            clearInterval(timeoutId);
336          }
337        }, 16);
338      };
339    </script>
340  </body>
341</html>
342