From 5ebc66e740c073faca2a8e6c35db7a7b27fb9d58 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 27 May 2015 22:25:08 -0700 Subject: [PATCH] test: use both -r and --require in preload tests --- test/parallel/test-preload.js | 139 +++++++++++++++++----------------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index e6bbfda1dc5487..06fb3f38d142c7 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -6,13 +6,10 @@ var common = require('../common'), var nodeBinary = process.argv[0]; -var preloadOption = function(preloads) { - var option = ''; - preloads.forEach(function(preload, index) { - // TODO: randomly pick -r or --require - option += '-r ' + preload + ' '; - }); - return option; +var preloadOption = function(preloads, flag) { + return preloads.reduce(function(option, preload) { + return option + flag + ' ' + preload + ' '; + }, ''); }; var fixture = function(name) { @@ -24,72 +21,74 @@ var fixtureB = fixture('printB.js'); var fixtureC = fixture('printC.js'); var fixtureThrows = fixture('throws_error4.js'); -// test preloading a single module works -child_process.exec(nodeBinary + ' ' - + preloadOption([fixtureA]) + ' ' - + fixtureB, - function(err, stdout, stderr) { - if (err) throw err; - assert.equal(stdout, 'A\nB\n'); - }); +['-r', '--require'].forEach(function (flag) { + // test preloading a single module works + child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureA], flag) + ' ' + + fixtureB, + function(err, stdout, stderr) { + if (err) throw err; + assert.equal(stdout, 'A\nB\n'); + }); -// test preloading multiple modules works -child_process.exec(nodeBinary + ' ' - + preloadOption([fixtureA, fixtureB]) + ' ' - + fixtureC, - function(err, stdout, stderr) { - if (err) throw err; - assert.equal(stdout, 'A\nB\nC\n'); - }); + // test preloading multiple modules works + child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureA, fixtureB], flag) + ' ' + + fixtureC, + function(err, stdout, stderr) { + if (err) throw err; + assert.equal(stdout, 'A\nB\nC\n'); + }); -// test that preloading a throwing module aborts -child_process.exec(nodeBinary + ' ' - + preloadOption([fixtureA, fixtureThrows]) + ' ' - + fixtureB, - function(err, stdout, stderr) { - if (err) { - assert.equal(stdout, 'A\n'); - } else { - throw new Error('Preload should have failed'); - } - }); + // test that preloading a throwing module aborts + child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureA, fixtureThrows], flag) + ' ' + + fixtureB, + function(err, stdout, stderr) { + if (err) { + assert.equal(stdout, 'A\n'); + } else { + throw new Error('Preload should have failed'); + } + }); -// test that preload can be used with --eval -child_process.exec(nodeBinary + ' ' - + preloadOption([fixtureA]) - + '-e "console.log(\'hello\');"', - function(err, stdout, stderr) { - if (err) throw err; - assert.equal(stdout, 'A\nhello\n'); - }); + // test that preload can be used with --eval + child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureA], flag) + + '-e "console.log(\'hello\');"', + function(err, stdout, stderr) { + if (err) throw err; + assert.equal(stdout, 'A\nhello\n'); + }); -// test that preload placement at other points in the cmdline -// also test that duplicated preload only gets loaded once -child_process.exec(nodeBinary + ' ' - + preloadOption([fixtureA]) - + '-e "console.log(\'hello\');" ' - + preloadOption([fixtureA, fixtureB]), - function(err, stdout, stderr) { - if (err) throw err; - assert.equal(stdout, 'A\nB\nhello\n'); - }); + // test that preload placement at other points in the cmdline + // also test that duplicated preload only gets loaded once + child_process.exec(nodeBinary + ' ' + + preloadOption([fixtureA], flag) + + '-e "console.log(\'hello\');" ' + + preloadOption([fixtureA, fixtureB], flag), + function(err, stdout, stderr) { + if (err) throw err; + assert.equal(stdout, 'A\nB\nhello\n'); + }); -child_process.exec(nodeBinary + ' ' - + '--require ' + fixture('cluster-preload.js') + ' ' - + fixture('cluster-preload-test.js'), - function(err, stdout, stderr) { - if (err) throw err; - assert.ok(/worker terminated with code 43/.test(stdout)); - }); + child_process.exec(nodeBinary + ' ' + + flag + ' ' + fixture('cluster-preload.js') + ' ' + + fixture('cluster-preload-test.js'), + function(err, stdout, stderr) { + if (err) throw err; + assert.ok(/worker terminated with code 43/.test(stdout)); + }); -// https://github.com/nodejs/io.js/issues/1691 -var originalCwd = process.cwd(); -process.chdir(path.join(__dirname, '../fixtures/')); -child_process.exec(nodeBinary + ' ' - + '--expose_debug_as=v8debug ' - + '--require ' + fixture('cluster-preload.js') + ' ' - + 'cluster-preload-test.js', - function(err, stdout, stderr) { - if (err) throw err; - assert.ok(/worker terminated with code 43/.test(stdout)); - }); + // https://github.com/nodejs/io.js/issues/1691 + var originalCwd = process.cwd(); + process.chdir(path.join(__dirname, '../fixtures/')); + child_process.exec(nodeBinary + ' ' + + '--expose_debug_as=v8debug ' + + flag + ' ' + fixture('cluster-preload.js') + ' ' + + 'cluster-preload-test.js', + function(err, stdout, stderr) { + if (err) throw err; + assert.ok(/worker terminated with code 43/.test(stdout)); + }); +});