Created
December 14, 2012 15:30
-
-
Save jvandyke/4286269 to your computer and use it in GitHub Desktop.
Include all test files in Testacular for RequireJS
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
node_modules | |
testdeps.js |
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
require.config({ | |
// !! Testacular serves files from '/base' | |
baseUrl: '/base/resources/js', | |
paths: { | |
'jquery': 'thirdpartyjs/jquery/jquery-1.7.2.min', | |
}, | |
shim: { | |
'jquery/button-tabs': ['jquery'], | |
'jquery/form': ['jquery'], | |
'jquery/tools': ['jquery'] | |
} | |
}); | |
require(['../../spec/javascript/testdeps'], function() { | |
window.__testacular__.start(); | |
}); |
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
/** | |
* This file is used across all runners to maintain consistency. | |
*/ | |
var glob = require("glob"); | |
var _ = require('underscore'); | |
var util = require('util'); | |
var fs = require("fs"); | |
var files = { | |
// Should all be relative to the root directory. | |
baseDir: "../..", | |
jasmine: [ | |
"spec/javascript/lib/jasmine-helpers.js" | |
], | |
src: [ | |
// Make all JS accessible by the test runner's server, but don't include | |
// them by default in the runner page as <script> tags. | |
{pattern: "resources/js/**/*.js", included: false}, | |
// A file to load the tests dynamically during the tests. | |
{pattern: "spec/javascript/testdeps.js", included: false}, | |
// Main RequireJS module. | |
'spec/javascript/main-test.js' | |
], | |
// Any files from globs that should not be included. | |
exclude: [], | |
tests: [ | |
{pattern: 'spec/javascript/specs/*.spec.js', included: false}, | |
{pattern: 'spec/javascript/specs/**/*.spec.js', included: false} | |
] | |
}; | |
var config; | |
try { | |
config = require(__dirname + "/_config.js").config; | |
} catch (e) { | |
config = []; | |
} | |
var globOpts = { | |
cwd: process.cwd() + '/' + files.baseDir, | |
root: files.baseDir, | |
sync: true | |
}; | |
var testFiles = []; | |
files.tests.forEach(function(def) { | |
var pattern = _.isObject(def) ? def.pattern : def; | |
testFiles = testFiles.concat(glob.sync(pattern, globOpts)); | |
}); | |
testFiles = _.uniq(testFiles); | |
testFiles = _.map(testFiles, function(file) { | |
return "'/base/" + file + "'"; | |
}); | |
var testFilesRequirements = testFiles.join(","); | |
fs.writeFileSync(process.cwd() + "/testdeps.js", "define([" + testFilesRequirements + "], function() { /** This is a test runner file. Safe to delete. **/ });"); | |
if (exports) { | |
exports.testFiles = testFiles; | |
exports.files = files; | |
exports.config = config; | |
exports.mergeFiles = function mergeFiles() { | |
var files = []; | |
[].splice.call(arguments, 0).forEach(function(file) { | |
if (file.match(/testacular/)) { | |
files.push(file); | |
} else { | |
files[file].forEach(function(f) { | |
// replace @ref | |
var deps = files[file]; | |
if (util.isArray(deps)) { | |
files = files.concat(deps); | |
} | |
}); | |
} | |
}); | |
return files; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using grunt, this plugin provides another way to include all your test files with less custom code https://www.npmjs.org/package/grunt-amd-require-tests