require.async('module_function_fd2', function (fd) { ok(fd() === true, "can require async in-package modules"); // stats ok(!!require.stats('module_function_fd2'), "should count stats: async modules"); start(); });
asyncTest("require.async().then() should return promise not require()", function () { expect(1); var promise = require.async('./modules/async/module_as_json_async.json' + rnd); ok(typeof promise === "object" && typeof promise.then === "function", "must return promise"); start(); });
require.preload(requiredModules, function (bad, good, string, json) { ok(bad === requiredModules[0] && good === requiredModules[1] && string === requiredModules[2] && json === requiredModules[3], 'Should return module names if taking from cache'); start(); });
var check_result = function (scriptTag) { if (typeof result === "undefined") { result = scriptTag; } else { ok(result === scriptTag, "Must perform one call. Results must be the same"); start(); } };
asyncTest("require.image().then() image loader without callback", function () { expect(1); var promise = require.image('./modules/loader/image_callbackless.gif' + rnd); ok(typeof promise === "object" && typeof promise.then === "function", "must return promise"); start(); });
asyncTest("require.css().then() CSS loader without callback", function () { expect(1); var promise = require.css('./modules/loader/some_css_callbackless.css' + rnd); ok(typeof promise === "object" && typeof promise.then === "function", "must return promise"); start(); });
function complete() { counter--; if (counter === 0) { ok(typeof require('bundle-test-simultaneous-1_js') === 'object', 'Should mix modules'); ok(typeof require('bundle-test-simultaneous-2_js') === 'object', 'Should mix modules'); start(); } }
var check_result = function (module_as_json_async) { if (typeof result === "undefined") { result = module_as_json_async; } else { ok(result === module_as_json_async, "Must perform one call. Results must be the same"); start(); } };
require.async('sk_async_js', function (js) { ok(js() === 'ok', 'should require shortcuts: js'); // stats ok(require.stats('sk_async_js') === require.stats('/modules/shortcuts/async.js'), "shortcut should point to the same object as module"); ok(!!require.stats('/modules/shortcuts/async.js'), "should count stats of real file"); ok(require.stats('/modules/shortcuts/async.js').shortcuts[0] === 'sk_async_js', "should pass shourtcuts names"); start(); });
asyncTest("require.image() image loader without callback", function () { expect(1); var requireReturned = require .image('./modules/loader/image_callbackless.gif' + rnd) .image('./modules/loader/image_callbackless.gif' + rnd + 1); ok(typeof requireReturned === "function", "require.image() must return require"); start(); });
asyncTest("require.css() CSS loader without callback", function () { expect(1); var requireReturned = require .css('./modules/loader/some_css_callbackless.css' + rnd) .css('./modules/loader/some_css_callbackless.css' + rnd + 1); ok(typeof requireReturned === "function", "require.css() must return require"); start(); });
.then(function (modules) { var module1 = modules[0], module2 = modules[1], module3 = modules[2]; ok(true, "Modules executes as they are loaded - in load order"); ok(module1.file === "1.js" && module2.file === "2.js" && module3.file === "3.js", "Modules should be callbacked in list order"); start(); });
require.async(['coverage_fully_covered_async', 'coverage_not_functions_async'], function () { var stats = require.stats(), report; report = stats.modules["coverage_fully_covered_async"].coverage.report; for (var i in report) { if (report.hasOwnProperty(i)) { ok(false, "should be fully covered!"); } } report = stats.modules["coverage_not_functions_async"].coverage.report; ok(report[3].functions[0] === "test", "coverage_not_functions: not 2 line"); ok(report[4].lines === false, "coverage_not_functions: not 3 line"); start(); });
test('basic', t => { //t.plan(4); const start = Start(reporter()); start( files(path.resolve(__dirname, '../compiled')), clean(), files(path.resolve(__dirname, '../base/main.styl')), read(), task({sourcemap: false}), write(path.resolve(__dirname, '../compiled')) ) .then(() => { const te = () => assert(path.resolve(__dirname, '../compiled'), path.resolve(__dirname, '../expected')) t.doesNotThrow(te) t.equal( typeof task, 'function', '1st function' ); t.equal( typeof task(), 'function', '2nd function' ); t.equal( typeof task()(), 'function', '3rd function' ); t.end(); }); });
require.async('./modules/async/module_as_json_async.json' + rnd, function (module_as_json_async) { ok(typeof module_as_json_async === "object", "should require async module-object"); ok(require('./modules/async/module_as_json_async.json' + rnd) === module_as_json_async, "can sync require, loaded async module-object"); start(); });
require.async('./modules/async/module_as_string_async.html' + rnd, function (module_as_string_async) { ok(typeof module_as_string_async === "string", "should require async module-strings"); ok(module_as_string_async === '<div class="b-template">${pewpew}</div>', "content ok?"); ok(require('./modules/async/module_as_string_async.html' + rnd) === module_as_string_async, "can sync require, loaded async module-strings"); start(); });
var id = require('setTimeout')(function () { ok(false, 'JSONP call fails'); start(); }, 3000);
require.async('./modules/async/module_plain_function_async.js' + rnd, function (module_plain_function_async) { ok(module_plain_function_async.some_function() === true, "should require async module-functions"); ok(require('./modules/async/module_plain_function_async.js' + rnd) === module_plain_function_async, "can async require plain modules, loaded async module-functions"); start(); });
require('window').someJsonHandler = function (result) { ok(result.ok, 'JSON called'); require('window').someJsonHandler = null; require('clearTimeout')(id); start(); };
function (module1, module2, module3) { ok(true, "Modules executes as they are loaded - in load order"); ok(module1.file === "1.js" && module2.file === "2.js" && module3.file === "3.js", "Modules should be callbacked in list order"); start(); });
require.bundle('test-bundle-test-mix', function (script2) { ok(script1 === script2, 'Returns script tag'); start(); });
require.js('sk_js_js', function (script_tag2) { ok(script_tag2 === script_tag, 'should load once'); ok(require('sk_js_js') === require('/modules/shortcuts/js.js'), "should be defined using path-to-module"); ok(typeof require('shortcuts_js') === "function", 'Should create a global function shortcuts_js as in module function'); start(); })
require.async('module_function_fd2', function (fd) { ok(fd() === true, "can require async in-package modules"); start(); });
require.async('sk_async_js', function (js) { ok(js() === 'ok', 'should require shortcuts: js'); start(); });
require.bundle('test-bundle-test-mix', function () { ok(typeof require('bundle-test-mix_js') === 'object', 'Should mix modules'); ok(typeof require('bundle-test-mix_html') === 'string', 'Should mix modules'); ok(typeof require('bundle-test-mix_json') === 'object', 'Should mix modules'); start(); });
require.bundle('test-bundle-test-exists-2', function () { ok(expected === require('bundle-test-exists_js'), 'Should be the same instance'); start(); });
.async('./modules/async/module_as_json_async.json' + rnd, function () { ok(true, 'Callback is optional'); ok(true, 'WeCan use chain calls'); start(); });
require.async('./modules/async/undefined_module.js' + rnd, function (undefined_module_2) { ok(typeof undefined_module_2 === "undefined", "should not cache errorous modules"); start(); });
require.bundle('test-bundle-test-not-exists', function (result) { ok(typeof result === 'undefined', 'Should return undefined'); start(); });
require.bundle('test-bundle-test-with-main', function () { ok(window._global_variable_from_bundle_main === true, 'Main should expose global variable'); start(); });