Created
July 23, 2014 18:39
-
-
Save jsantell/b5f3a3ff220e7fed801d to your computer and use it in GitHub Desktop.
e10sify-tests.js
This file contains 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
/** | |
* Creates wrappers for all xpcshell test files in a `./unit` directory | |
* for e10s tests, and copies over the xpcshell test with modified test names. | |
* | |
* Does NOT copy over head or support files, those need to be done manually. | |
*/ | |
var fs = require("fs"); | |
var path = require("path"); | |
var unitDir = path.join(__dirname, "unit"); | |
var unitIPCDir = path.join(__dirname, "unit_ipc"); | |
// Make `unit_ipc` directory if DNE | |
try { fs.mkdirSync(unitIPCDir); } catch (e) {} | |
// Create wrapper files for each `test_*.js` file in `unit_ipc` | |
var testFiles = fs.readdirSync(unitDir).filter(isTest); | |
testFiles.forEach(makeWrapper); | |
// Copy over the xpcshell.ini and modify it with wrapped files | |
fs.createReadStream(path.join(unitDir, "xpcshell.ini")) | |
.pipe(fs.createWriteStream(path.join(unitIPCDir, "xpcshell.ini"))) | |
.on("close", function () { | |
var ini = fs.readFileSync(path.join(unitIPCDir, "xpcshell.ini")) + ""; | |
var modified = ini.split("\n").map(function (line) { | |
if (/^\[test_.*\.js\]$/.test(line)) { | |
return makeWrapFilenameManifest(line); | |
} | |
return line; | |
}).join("\n"); | |
fs.writeFileSync(path.join(unitIPCDir, "xpcshell.ini"), modified); | |
}); | |
/** | |
* Utility functions | |
*/ | |
function makeWrapper (filename) { | |
fs.writeFileSync(path.join(unitIPCDir, makeWrapFilename(filename)), wrapBuffer(filename)); | |
} | |
function wrapBuffer (filename) { | |
return "function run_test() {\n" + | |
" run_test_in_child(\"../unit/" + filename + "\");\n" + | |
"}"; | |
} | |
function isTest (file) { | |
return /^test_.*\.js$/.test(file); | |
} | |
function makeWrapFilename (filename) { | |
return filename.replace(/\.js$/, "_wrap.js"); | |
} | |
function makeWrapFilenameManifest (filename) { | |
return filename.replace(/\.js\]$/, "_wrap.js]"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment