Skip to content

Instantly share code, notes, and snippets.

@necolas
Created September 8, 2014 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necolas/3a84843cb323ade1071a to your computer and use it in GitHub Desktop.
Save necolas/3a84843cb323ade1071a to your computer and use it in GitHub Desktop.
Auto-generating the intern test config
/**
* Functional and Unit test configuration
*
* This configuration file has to work in both Node.js and browser environments.
* Therefore, this config is a template that is used to build the Intern config
* used to run the tests. The packages and suites are automatically defined.
*
* Learn more about configuring Intern at:
* https://github.com/theintern/intern/wiki/Configuring-Intern
*/
module.exports = {
buildDir: 'build/test',
capabilities: {
'selenium-version': '2.42.2',
'idle-timeout': 30
},
environments: [
{ browserName: 'chrome' },
{ browserName: 'firefox' }
],
excludeInstrumentation: '__EXCLUDES__',
maxConcurrency: 3,
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
loader: {
baseUrl: '__BASE_URL__',
packages: '__PACKAGES__',
map: {
intern: {
dojo: 'intern/node_modules/dojo',
chai: 'intern/node_modules/chai/chai'
},
'*': {
'intern/dojo': 'intern/node_modules/dojo'
}
}
},
suites: '__SUITES__',
functionalSuites: '__FUNC_SUITES__',
};
/**
* Build the config for the unit and functional tests from the intern.config.js
* template.
*/
var fs = require('fs');
var glob = require('glob');
var path = require('path');
// config template
var INTERN_CONFIG = require('./intern.config');
// dirs
var BUILD_TEST_DIR = INTERN_CONFIG.buildDir;
var ROOT = './app';
// replacement config values
var BASE_URL = '(typeof window !== "undefined" ? ' + '"../.." : "./") + "' + BUILD_TEST_DIR + '"';
var EXCLUDES = '/(intern.js)|(?:node_modules|test)\\//';
// extract the packages and suites (in the format expected by Intern) from the
// web_modules
var modules = {
entries: [],
units: [],
webdrivers: []
};
glob.sync(ROOT + '/**/*.js').forEach(function (filepath) {
var moduleName = path.dirname(path.relative(ROOT, filepath));
var modulePath = path.relative(ROOT, filepath);
if (filepath.indexOf('unit.spec') > -1) {
modules.units.push(modulePath);
} else if (filepath.indexOf('webdriver.spec') > -1) {
modules.webdrivers.push(modulePath);
} else {
modules.entries.push({
name: moduleName,
location: moduleName,
main: 'index.js'
});
}
});
// build config
var raw = JSON.stringify(INTERN_CONFIG);
raw = raw.replace('"__BASE_URL__"', BASE_URL);
raw = raw.replace('"__EXCLUDES__"', EXCLUDES);
raw = raw.replace('"__PACKAGES__"', JSON.stringify(modules.entries));
raw = raw.replace('"__SUITES__"', JSON.stringify(modules.units));
raw = raw.replace('"__FUNC_SUITES__"', JSON.stringify(modules.webdrivers));
raw = 'define(' + raw + ')';
fs.writeFileSync(path.join(BUILD_TEST_DIR, 'intern.js'), raw);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment