Last active
February 11, 2024 23:19
-
-
Save jrburke/5303319 to your computer and use it in GitHub Desktop.
config calls to run tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//in test1.js | |
define({ | |
paths: {}, | |
deps: ['test/_', 'test/$', 'dep1', 'dep2'], | |
callback: function (_, $, dep1, dep2) { | |
//test dep1 and dep2 in here | |
} | |
}); | |
//in test2.js | |
define({ | |
paths: {}, | |
deps: ['test/_', 'test/$', 'dep3', 'dep4'], | |
callback: function (_, $, dep3, dep4) { | |
//test dep3 and dep4 in here | |
} | |
}); | |
//testLoader. Depends on any modules you want to use | |
//separate to the ones used in the tests. | |
define(['jquery', 'underscore'], function ($, _) { | |
var contextCount = 0, | |
globalRequire = require; | |
return { | |
load: function(id, require, load, config) { | |
require([id], function (config) { | |
config.context = 'test' + (countextCounter += 1); | |
var oldCallback = config.callback; | |
config.callback = function () { | |
oldConfig.apply(config, [].slice.call(arguments, 0)); | |
//Signal loading is complete | |
load(); | |
} | |
//Set up versions of libs you only want to use in | |
//the tests, and not in the app modules. Put them | |
//under a 'test' namespace (or something else to your liking) | |
//By doing this right before the globalRequire call, it means | |
//they will be claimed by the globalRequire | |
define('test/$', function () { return $; }); | |
define('test/_', function () { return _; }); | |
globalRequire(config); | |
}); | |
} | |
}; | |
}); | |
//Using it: | |
require.config({ | |
context: 'testLoaderRequire', | |
//configure the test versions of 'jquery' and 'underscore' | |
//that will be used by the testLoader plugin here. | |
paths: {}, | |
shim: {}, | |
//load the tests | |
deps: ['testLoader!test1', 'testLoader!test2'], | |
callback: function () { | |
mocha.run(); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment