Skip to content

Commit 324c82b

Browse files
benglMylesBorins
authored andcommitted
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: #6997 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent ce91bb2 commit 324c82b

13 files changed

+28
-24
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
2-
require('../common');
2+
var common = require('../common');
33
var assert = require('assert');
44
var path = require('path');
55

66
var spawn = require('child_process').spawn;
7-
var childPath = path.join(__dirname, '..', 'fixtures',
7+
var childPath = path.join(common.fixturesDir,
88
'parent-process-nonpersistent.js');
99
var persistentPid = -1;
1010

test/parallel/test-delayed-require.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
2-
const common = require('../common');
2+
var common = require('../common');
3+
var path = require('path');
34
var assert = require('assert');
45

56
setTimeout(common.mustCall(function() {
6-
const a = require('../fixtures/a');
7+
const a = require(path.join(common.fixturesDir, 'a'));
78
assert.strictEqual(true, 'A' in a);
89
assert.strictEqual('A', a.A());
910
assert.strictEqual('D', a.D());

test/parallel/test-global.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable strict */
22
var common = require('../common');
3+
var path = require('path');
34
var assert = require('assert');
45

56
common.globalCheck = false;
@@ -13,7 +14,7 @@ assert.equal('bar',
1314
baseBar, // eslint-disable-line no-undef
1415
'global.x -> x in base level not working');
1516

16-
var module = require('../fixtures/global/plain');
17+
var module = require(path.join(common.fixturesDir, 'global', 'plain'));
1718
const fooBar = module.fooBar;
1819

1920
assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working');

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
55
const hostExpect = 'localhost';
66
const fs = require('fs');
77
const path = require('path');
8-
const fixtures = path.resolve(__dirname, '../fixtures/keys');
8+
const fixtures = path.join(common.fixturesDir, 'keys');
99
const options = {
1010
key: fs.readFileSync(fixtures + '/agent1-key.pem'),
1111
cert: fs.readFileSync(fixtures + '/agent1-cert.pem')
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
2-
require('../common');
2+
var common = require('../common');
3+
var path = require('path');
34
var assert = require('assert');
45

56
assert.throws(function() {
67
require('internal/freelist');
78
});
89

9-
assert(require('../fixtures/internal-modules') === 42);
10+
assert(require(path.join(common.fixturesDir, 'internal-modules')) === 42);

test/parallel/test-preload.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const path = require('path');
55
const child_process = require('child_process');
@@ -15,7 +15,7 @@ var preloadOption = function(preloads) {
1515
};
1616

1717
var fixture = function(name) {
18-
return path.join(__dirname, '../fixtures/' + name);
18+
return path.join(common.fixturesDir, name);
1919
};
2020

2121
var fixtureA = fixture('printA.js');
@@ -82,7 +82,7 @@ child_process.exec(nodeBinary + ' '
8282
});
8383

8484
// https://github.com/nodejs/node/issues/1691
85-
process.chdir(path.join(__dirname, '../fixtures/'));
85+
process.chdir(common.fixturesDir);
8686
child_process.exec(nodeBinary + ' '
8787
+ '--expose_debug_as=v8debug '
8888
+ '--require ' + fixture('cluster-preload.js') + ' '

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const sameHistoryFilePaths = '\nThe old repl history file has the same name ' +
6868
path.join(common.tmpDir, '.node_repl_history') +
6969
' and is empty.\nUsing it as is.\n';
7070
// File paths
71-
const fixtures = path.join(common.testDir, 'fixtures');
71+
const fixtures = common.fixturesDir;
7272
const historyFixturePath = path.join(fixtures, '.node_repl_history');
7373
const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history');
7474
const historyPathFail = path.join(common.tmpDir, '.node_repl\u0000_history');

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ common.ArrayStream.prototype.write = function(output) {
1717

1818
const putIn = new common.ArrayStream();
1919
repl.start('', putIn);
20-
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax');
20+
let file = path.join(common.fixturesDir, 'syntax', 'bad_syntax');
2121

2222
if (common.isWindows)
2323
file = file.replace(/\\/g, '\\\\');

test/parallel/test-require-json.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
2-
require('../common');
2+
var common = require('../common');
3+
var path = require('path');
34
var assert = require('assert');
45

56
try {
6-
require('../fixtures/invalid.json');
7+
require(path.join(common.fixturesDir, 'invalid.json'));
78
} catch (err) {
89
var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/;
910
var i = err.message.match(re);

test/parallel/test-sync-fileread.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
2-
require('../common');
2+
var common = require('../common');
33
var assert = require('assert');
44
var path = require('path');
55
var fs = require('fs');
66

7-
var fixture = path.join(__dirname, '../fixtures/x.txt');
7+
var fixture = path.join(common.fixturesDir, 'x.txt');
88

99
assert.equal('xyz\n', fs.readFileSync(fixture));

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const fs = require('fs');
5-
const path = require('path');
65
const tls = require('tls');
76
const stream = require('stream');
87
const net = require('net');
98

109
var server;
11-
var cert_dir = path.resolve(__dirname, '../fixtures');
10+
var cert_dir = common.fixturesDir;
1211
var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
1312
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
1413
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],

test/parallel/test-util-internal.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22
// Flags: --expose_internals
33

4-
require('../common');
4+
const common = require('../common');
5+
const path = require('path');
56
const assert = require('assert');
67
const internalUtil = require('internal/util');
78

@@ -24,7 +25,7 @@ assert.deepEqual(internalUtil.getHiddenValue({}, 'foo'), undefined);
2425
let arrowMessage;
2526

2627
try {
27-
require('../fixtures/syntax/bad_syntax');
28+
require(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
2829
} catch (err) {
2930
arrowMessage = internalUtil.getHiddenValue(err, 'arrowMessage');
3031
}

test/sequential/test-deprecation-flags.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
2-
require('../common');
2+
var common = require('../common');
33
var assert = require('assert');
44
var execFile = require('child_process').execFile;
55
var depmod = require.resolve('../fixtures/deprecated.js');
66
var node = process.execPath;
77

88
var depUserland =
9-
require.resolve('../fixtures/deprecated-userland-function.js');
9+
require.resolve(common.fixturesDir + '/deprecated-userland-function.js');
1010

1111
var normal = [depmod];
1212
var noDep = ['--no-deprecation', depmod];

0 commit comments

Comments
 (0)