Browse Source

test: use common.fixturesDir almost everywhere

Updating tests to use `common.fixturesDir` whenever possible/reasonable.
Left out things like tests for `path` and `require.resolve`.

PR-URL: https://github.com/nodejs/node/pull/6997
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6.x
Bryan English 9 years ago
committed by Evan Lucas
parent
commit
d6091c8194
  1. 4
      test/parallel/test-child-process-detached.js
  2. 5
      test/parallel/test-delayed-require.js
  3. 3
      test/parallel/test-global.js
  4. 2
      test/parallel/test-http-default-port.js
  5. 5
      test/parallel/test-internal-modules.js
  6. 4
      test/parallel/test-preload.js
  7. 2
      test/parallel/test-repl-persistent-history.js
  8. 2
      test/parallel/test-repl-syntax-error-stack.js
  9. 5
      test/parallel/test-require-json.js
  10. 4
      test/parallel/test-sync-fileread.js
  11. 3
      test/parallel/test-tls-connect-stream-writes.js
  12. 4
      test/parallel/test-util-decorate-error-stack.js
  13. 5
      test/parallel/test-util-internal.js
  14. 6
      test/sequential/test-deprecation-flags.js
  15. 4
      test/sequential/test-process-warnings.js

4
test/parallel/test-child-process-detached.js

@ -1,10 +1,10 @@
'use strict'; 'use strict';
require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var path = require('path'); var path = require('path');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var childPath = path.join(__dirname, '..', 'fixtures', var childPath = path.join(common.fixturesDir,
'parent-process-nonpersistent.js'); 'parent-process-nonpersistent.js');
var persistentPid = -1; var persistentPid = -1;

5
test/parallel/test-delayed-require.js

@ -1,10 +1,11 @@
'use strict'; 'use strict';
require('../common'); var common = require('../common');
var path = require('path');
var assert = require('assert'); var assert = require('assert');
var a; var a;
setTimeout(function() { setTimeout(function() {
a = require('../fixtures/a'); a = require(path.join(common.fixturesDir, 'a'));
}, 50); }, 50);
process.on('exit', function() { process.on('exit', function() {

3
test/parallel/test-global.js

@ -1,5 +1,6 @@
/* eslint-disable strict */ /* eslint-disable strict */
var common = require('../common'); var common = require('../common');
var path = require('path');
var assert = require('assert'); var assert = require('assert');
common.globalCheck = false; common.globalCheck = false;
@ -13,7 +14,7 @@ assert.equal('bar',
baseBar, // eslint-disable-line no-undef baseBar, // eslint-disable-line no-undef
'global.x -> x in base level not working'); 'global.x -> x in base level not working');
var module = require('../fixtures/global/plain'); var module = require(path.join(common.fixturesDir, 'global', 'plain'));
const fooBar = module.fooBar; const fooBar = module.fooBar;
assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working'); assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working');

2
test/parallel/test-http-default-port.js

@ -7,7 +7,7 @@ const assert = require('assert');
const hostExpect = 'localhost'; const hostExpect = 'localhost';
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const fixtures = path.resolve(__dirname, '../fixtures/keys'); const fixtures = path.join(common.fixturesDir, 'keys');
const options = { const options = {
key: fs.readFileSync(fixtures + '/agent1-key.pem'), key: fs.readFileSync(fixtures + '/agent1-key.pem'),
cert: fs.readFileSync(fixtures + '/agent1-cert.pem') cert: fs.readFileSync(fixtures + '/agent1-cert.pem')

5
test/parallel/test-internal-modules.js

@ -1,9 +1,10 @@
'use strict'; 'use strict';
require('../common'); var common = require('../common');
var path = require('path');
var assert = require('assert'); var assert = require('assert');
assert.throws(function() { assert.throws(function() {
require('internal/freelist'); require('internal/freelist');
}); });
assert(require('../fixtures/internal-modules') === 42); assert(require(path.join(common.fixturesDir, 'internal-modules')) === 42);

4
test/parallel/test-preload.js

@ -22,7 +22,7 @@ const preloadOption = function(preloads) {
}; };
const fixture = function(name) { const fixture = function(name) {
return path.join(__dirname, '../fixtures/' + name); return path.join(common.fixturesDir, name);
}; };
const fixtureA = fixture('printA.js'); const fixtureA = fixture('printA.js');
@ -138,7 +138,7 @@ childProcess.exec(nodeBinary + ' '
}); });
// https://github.com/nodejs/node/issues/1691 // https://github.com/nodejs/node/issues/1691
process.chdir(path.join(__dirname, '../fixtures/')); process.chdir(common.fixturesDir);
childProcess.exec(nodeBinary + ' ' childProcess.exec(nodeBinary + ' '
+ '--expose_debug_as=v8debug ' + '--expose_debug_as=v8debug '
+ '--require ' + fixture('cluster-preload.js') + ' ' + '--require ' + fixture('cluster-preload.js') + ' '

2
test/parallel/test-repl-persistent-history.js

@ -70,7 +70,7 @@ const sameHistoryFilePaths = '\nThe old repl history file has the same name ' +
path.join(common.tmpDir, '.node_repl_history') + path.join(common.tmpDir, '.node_repl_history') +
' and is empty.\nUsing it as is.\n'; ' and is empty.\nUsing it as is.\n';
// File paths // File paths
const fixtures = path.join(common.testDir, 'fixtures'); const fixtures = common.fixturesDir;
const historyFixturePath = path.join(fixtures, '.node_repl_history'); const historyFixturePath = path.join(fixtures, '.node_repl_history');
const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history'); const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history');
const historyPathFail = path.join(common.tmpDir, '.node_repl\u0000_history'); const historyPathFail = path.join(common.tmpDir, '.node_repl\u0000_history');

2
test/parallel/test-repl-syntax-error-stack.js

@ -17,7 +17,7 @@ common.ArrayStream.prototype.write = function(output) {
const putIn = new common.ArrayStream(); const putIn = new common.ArrayStream();
repl.start('', putIn); repl.start('', putIn);
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax'); let file = path.join(common.fixturesDir, 'syntax', 'bad_syntax');
if (common.isWindows) if (common.isWindows)
file = file.replace(/\\/g, '\\\\'); file = file.replace(/\\/g, '\\\\');

5
test/parallel/test-require-json.js

@ -1,9 +1,10 @@
'use strict'; 'use strict';
require('../common'); var common = require('../common');
var path = require('path');
var assert = require('assert'); var assert = require('assert');
try { try {
require('../fixtures/invalid.json'); require(path.join(common.fixturesDir, 'invalid.json'));
} catch (err) { } catch (err) {
var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/; var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/;
var i = err.message.match(re); var i = err.message.match(re);

4
test/parallel/test-sync-fileread.js

@ -1,9 +1,9 @@
'use strict'; 'use strict';
require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var fixture = path.join(__dirname, '../fixtures/x.txt'); var fixture = path.join(common.fixturesDir, 'x.txt');
assert.equal('xyz\n', fs.readFileSync(fixture)); assert.equal('xyz\n', fs.readFileSync(fixture));

3
test/parallel/test-tls-connect-stream-writes.js

@ -2,13 +2,12 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const tls = require('tls'); const tls = require('tls');
const stream = require('stream'); const stream = require('stream');
const net = require('net'); const net = require('net');
var server; var server;
var cert_dir = path.resolve(__dirname, '../fixtures'); var cert_dir = common.fixturesDir;
var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'), var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'), cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ], ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],

4
test/parallel/test-util-decorate-error-stack.js

@ -1,6 +1,6 @@
// Flags: --expose_internals // Flags: --expose_internals
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const internalUtil = require('internal/util'); const internalUtil = require('internal/util');
const spawnSync = require('child_process').spawnSync; const spawnSync = require('child_process').spawnSync;
@ -26,7 +26,7 @@ function checkStack(stack) {
} }
let err; let err;
const badSyntaxPath = const badSyntaxPath =
path.resolve(__dirname, '..', 'fixtures', 'syntax', 'bad_syntax') path.join(common.fixturesDir, 'syntax', 'bad_syntax')
.replace(/\\/g, '\\\\'); .replace(/\\/g, '\\\\');
try { try {

5
test/parallel/test-util-internal.js

@ -1,7 +1,8 @@
'use strict'; 'use strict';
// Flags: --expose_internals // Flags: --expose_internals
require('../common'); const common = require('../common');
const path = require('path');
const assert = require('assert'); const assert = require('assert');
const internalUtil = require('internal/util'); const internalUtil = require('internal/util');
const spawnSync = require('child_process').spawnSync; const spawnSync = require('child_process').spawnSync;
@ -43,7 +44,7 @@ assert.strictEqual(internalUtil.getHiddenValue(obj, 'foo'), 'bar');
let arrowMessage; let arrowMessage;
try { try {
require('../fixtures/syntax/bad_syntax'); require(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
} catch (err) { } catch (err) {
arrowMessage = internalUtil.getHiddenValue(err, 'node:arrowMessage'); arrowMessage = internalUtil.getHiddenValue(err, 'node:arrowMessage');
} }

6
test/sequential/test-deprecation-flags.js

@ -1,12 +1,12 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const execFile = require('child_process').execFile; const execFile = require('child_process').execFile;
const depmod = require.resolve('../fixtures/deprecated.js'); const depmod = require.resolve(common.fixturesDir + '/deprecated.js');
const node = process.execPath; const node = process.execPath;
const depUserland = const depUserland =
require.resolve('../fixtures/deprecated-userland-function.js'); require.resolve(common.fixturesDir + '/deprecated-userland-function.js');
const normal = [depmod]; const normal = [depmod];
const noDep = ['--no-deprecation', depmod]; const noDep = ['--no-deprecation', depmod];

4
test/sequential/test-process-warnings.js

@ -1,9 +1,9 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const execFile = require('child_process').execFile; const execFile = require('child_process').execFile;
const warnmod = require.resolve('../fixtures/warnings.js'); const warnmod = require.resolve(common.fixturesDir + '/warnings.js');
const node = process.execPath; const node = process.execPath;
const normal = [warnmod]; const normal = [warnmod];

Loading…
Cancel
Save