| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c661d8c commit 2b2471b
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,9 +34,6 @@ const path = require('path'); | |||
| 34 | 34 | const fixtures = require('../common/fixtures'); | |
| 35 | 35 | const nodejs = `"${process.execPath}"`; | |
| 36 | 36 | ||
| 37 | - if (!common.isMainThread) | ||
| 38 | - common.skip('process.chdir is not available in Workers'); | ||
| 39 | - | ||
| 40 | 37 | if (process.argv.length > 2) { | |
| 41 | 38 | console.log(process.argv.slice(2).join(' ')); | |
| 42 | 39 | process.exit(0); | |
@@ -98,16 +95,14 @@ child.exec(`${nodejs} --print "os.platform()"`, | |||
| 98 | 95 | })); | |
| 99 | 96 | ||
| 100 | 97 | // Module path resolve bug regression test. | |
| 101 | - const cwd = process.cwd(); | ||
| 102 | - process.chdir(path.resolve(__dirname, '../../')); | ||
| 103 | 98 | child.exec(`${nodejs} --eval "require('./test/parallel/test-cli-eval.js')"`, | |
| 99 | + { cwd: path.resolve(__dirname, '../../') }, | ||
| 104 | 100 | common.mustCall((err, stdout, stderr) => { | |
| 105 | 101 | assert.strictEqual(err.code, 42); | |
| 106 | 102 | assert.strictEqual( | |
| 107 | 103 | stdout, 'Loaded as a module, exiting with status code 42.\n'); | |
| 108 | 104 | assert.strictEqual(stderr, ''); | |
| 109 | 105 | })); | |
| 110 | - process.chdir(cwd); | ||
| 111 | 106 | ||
| 112 | 107 | // Missing argument should not crash. | |
| 113 | 108 | child.exec(`${nodejs} -e`, common.mustCall((err, stdout, stderr) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,6 @@ | |||
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | if (process.config.variables.node_without_node_options) | |
| 4 | 4 | common.skip('missing NODE_OPTIONS support'); | |
| 5 | - if (!common.isMainThread) | ||
| 6 | - common.skip('process.chdir is not available in Workers'); | ||
| 7 | 5 | ||
| 8 | 6 | // Test options specified by env variable. | |
| 9 | 7 | ||
@@ -12,7 +10,6 @@ const exec = require('child_process').execFile; | |||
| 12 | 10 | ||
| 13 | 11 | const tmpdir = require('../common/tmpdir'); | |
| 14 | 12 | tmpdir.refresh(); | |
| 15 | - process.chdir(tmpdir.path); | ||
| 16 | 13 | ||
| 17 | 14 | disallow('--version'); | |
| 18 | 15 | disallow('-v'); | |
@@ -32,7 +29,7 @@ disallow('--'); | |||
| 32 | 29 | ||
| 33 | 30 | function disallow(opt) { | |
| 34 | 31 | const env = Object.assign({}, process.env, { NODE_OPTIONS: opt }); | |
| 35 | - exec(process.execPath, { env }, common.mustCall(function(err) { | ||
| 32 | + exec(process.execPath, { cwd: tmpdir.path, env }, common.mustCall((err) => { | ||
| 36 | 33 | const message = err.message.split(/\r?\n/)[1]; | |
| 37 | 34 | const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`; | |
| 38 | 35 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,6 @@ | |||
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | if (process.config.variables.node_without_node_options) | |
| 4 | 4 | common.skip('missing NODE_OPTIONS support'); | |
| 5 | - if (!common.isMainThread) | ||
| 6 | - common.skip('process.chdir is not available in Workers'); | ||
| 7 | 5 | ||
| 8 | 6 | // Test options specified by env variable. | |
| 9 | 7 | ||
@@ -12,7 +10,6 @@ const exec = require('child_process').execFile; | |||
| 12 | 10 | ||
| 13 | 11 | const tmpdir = require('../common/tmpdir'); | |
| 14 | 12 | tmpdir.refresh(); | |
| 15 | - process.chdir(tmpdir.path); | ||
| 16 | 13 | ||
| 17 | 14 | const printA = require.resolve('../fixtures/printA.js'); | |
| 18 | 15 | expect(`-r ${printA}`, 'A\nB\n'); | |
@@ -64,6 +61,7 @@ expect('--stack-trace-limit=100', | |||
| 64 | 61 | function expect(opt, want, command = 'console.log("B")', wantsError = false) { | |
| 65 | 62 | const argv = ['-e', command]; | |
| 66 | 63 | const opts = { | |
| 64 | + cwd: tmpdir.path, | ||
| 67 | 65 | env: Object.assign({}, process.env, { NODE_OPTIONS: opt }), | |
| 68 | 66 | maxBuffer: 1e6, | |
| 69 | 67 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,31 +3,28 @@ | |||
| 3 | 3 | // This tests that process.argv is the same in the preloaded module | |
| 4 | 4 | // and the user module. | |
| 5 | 5 | ||
| 6 | - const common = require('../common'); | ||
| 6 | + require('../common'); | ||
| 7 | 7 | ||
| 8 | 8 | const tmpdir = require('../common/tmpdir'); | |
| 9 | 9 | const assert = require('assert'); | |
| 10 | + const { join } = require('path'); | ||
| 10 | 11 | const { spawnSync } = require('child_process'); | |
| 11 | 12 | const fs = require('fs'); | |
| 12 | 13 | ||
| 13 | - if (!common.isMainThread) { | ||
| 14 | - common.skip('Cannot chdir to the tmp directory in workers'); | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | 14 | tmpdir.refresh(); | |
| 18 | 15 | ||
| 19 | - process.chdir(tmpdir.path); | ||
| 20 | 16 | fs.writeFileSync( | |
| 21 | - 'preload.js', | ||
| 17 | + join(tmpdir.path, 'preload.js'), | ||
| 22 | 18 | 'console.log(JSON.stringify(process.argv));', | |
| 23 | 19 | 'utf-8'); | |
| 24 | 20 | ||
| 25 | 21 | fs.writeFileSync( | |
| 26 | - 'main.js', | ||
| 22 | + join(tmpdir.path, 'main.js'), | ||
| 27 | 23 | 'console.log(JSON.stringify(process.argv));', | |
| 28 | 24 | 'utf-8'); | |
| 29 | 25 | ||
| 30 | - const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js']); | ||
| 26 | + const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js'], | ||
| 27 | + { cwd: tmpdir.path }); | ||
| 31 | 28 | ||
| 32 | 29 | if (child.status !== 0) { | |
| 33 | 30 | console.log(child.stderr.toString()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,6 @@ const fixtures = require('../common/fixtures'); | |||
| 5 | 5 | // Refs: https://github.com/nodejs/node/pull/2253 | |
| 6 | 6 | if (common.isSunOS) | |
| 7 | 7 | common.skip('unreliable on SunOS'); | |
| 8 | - if (!common.isMainThread) | ||
| 9 | - common.skip('process.chdir is not available in Workers'); | ||
| 10 | 8 | ||
| 11 | 9 | const assert = require('assert'); | |
| 12 | 10 | const childProcess = require('child_process'); | |
@@ -133,9 +131,9 @@ childProcess.exec( | |||
| 133 | 131 | ); | |
| 134 | 132 | ||
| 135 | 133 | // Test that preloading with a relative path works | |
| 136 | - process.chdir(fixtures.fixturesDir); | ||
| 137 | 134 | childProcess.exec( | |
| 138 | 135 | `"${nodeBinary}" ${preloadOption(['./printA.js'])} "${fixtureB}"`, | |
| 136 | + { cwd: fixtures.fixturesDir }, | ||
| 139 | 137 | common.mustCall(function(err, stdout, stderr) { | |
| 140 | 138 | assert.ifError(err); | |
| 141 | 139 | assert.strictEqual(stdout, 'A\nB\n'); | |
@@ -145,6 +143,7 @@ if (common.isWindows) { | |||
| 145 | 143 | // https://github.com/nodejs/node/issues/21918 | |
| 146 | 144 | childProcess.exec( | |
| 147 | 145 | `"${nodeBinary}" ${preloadOption(['.\\printA.js'])} "${fixtureB}"`, | |
| 146 | + { cwd: fixtures.fixturesDir }, | ||
| 148 | 147 | common.mustCall(function(err, stdout, stderr) { | |
| 149 | 148 | assert.ifError(err); | |
| 150 | 149 | assert.strictEqual(stdout, 'A\nB\n'); | |
@@ -153,10 +152,10 @@ if (common.isWindows) { | |||
| 153 | 152 | } | |
| 154 | 153 | ||
| 155 | 154 | // https://github.com/nodejs/node/issues/1691 | |
| 156 | - process.chdir(fixtures.fixturesDir); | ||
| 157 | 155 | childProcess.exec( | |
| 158 | 156 | `"${nodeBinary}" --require ` + | |
| 159 | 157 | `"${fixtures.path('cluster-preload.js')}" cluster-preload-test.js`, | |
| 158 | + { cwd: fixtures.fixturesDir }, | ||
| 160 | 159 | function(err, stdout, stderr) { | |
| 161 | 160 | assert.ifError(err); | |
| 162 | 161 | assert.ok(/worker terminated with code 43/.test(stdout)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,20 +5,18 @@ const fs = require('fs'); | |||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | const { spawnSync } = require('child_process'); | |
| 7 | 7 | ||
| 8 | - if (!common.isMainThread) | ||
| 9 | - common.skip('chdir not available in workers'); | ||
| 10 | 8 | if (!common.enoughTestMem) | |
| 11 | 9 | common.skip('skipped due to memory requirements'); | |
| 12 | 10 | if (common.isAIX) | |
| 13 | 11 | common.skip('does not work on AIX'); | |
| 14 | 12 | ||
| 15 | 13 | tmpdir.refresh(); | |
| 16 | - process.chdir(tmpdir.path); | ||
| 17 | 14 | ||
| 18 | 15 | // Generate log file. | |
| 19 | - spawnSync(process.execPath, [ '--prof', '-p', '42' ]); | ||
| 16 | + spawnSync(process.execPath, [ '--prof', '-p', '42' ], { cwd: tmpdir.path }); | ||
| 20 | 17 | ||
| 21 | - const logfile = fs.readdirSync('.').filter((name) => name.endsWith('.log'))[0]; | ||
| 18 | + const files = fs.readdirSync(tmpdir.path); | ||
| 19 | + const logfile = files.filter((name) => /\.log$/.test(name))[0]; | ||
| 22 | 20 | assert(logfile); | |
| 23 | 21 | ||
| 24 | 22 | // Make sure that the --preprocess argument is passed through correctly, | |
@@ -28,7 +26,7 @@ assert(logfile); | |||
| 28 | 26 | const { stdout } = spawnSync( | |
| 29 | 27 | process.execPath, | |
| 30 | 28 | [ '--prof-process', '--preprocess', logfile ], | |
| 31 | - { encoding: 'utf8' }); | ||
| 29 | + { cwd: tmpdir.path, encoding: 'utf8' }); | ||
| 32 | 30 | ||
| 33 | 31 | // Make sure that the result is valid JSON. | |
| 34 | 32 | JSON.parse(stdout); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,6 @@ const tmpdir = require('../common/tmpdir'); | |||
| 10 | 10 | ||
| 11 | 11 | // This tests the emission of node.environment trace events | |
| 12 | 12 | ||
| 13 | - if (!common.isMainThread) | ||
| 14 | - common.skip('process.chdir is not available in Workers'); | ||
| 15 | - | ||
| 16 | 13 | const names = new Set([ | |
| 17 | 14 | 'Environment', | |
| 18 | 15 | 'RunAndClearNativeImmediates', | |
@@ -32,10 +29,10 @@ if (process.argv[2] === 'child') { | |||
| 32 | 29 | setTimeout(() => { 1 + 1; }, 1); | |
| 33 | 30 | } else { | |
| 34 | 31 | tmpdir.refresh(); | |
| 35 | - process.chdir(tmpdir.path); | ||
| 36 | 32 | ||
| 37 | 33 | const proc = cp.fork(__filename, | |
| 38 | 34 | [ 'child' ], { | |
| 35 | + cwd: tmpdir.path, | ||
| 39 | 36 | execArgv: [ | |
| 40 | 37 | '--trace-event-categories', | |
| 41 | 38 | 'node.environment' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,12 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - const common = require('../common'); | ||
| 2 | + require('../common'); | ||
| 3 | 3 | const tmpdir = require('../common/tmpdir'); | |
| 4 | 4 | const fs = require('fs'); | |
| 5 | 5 | const assert = require('assert'); | |
| 6 | + const { join } = require('path'); | ||
| 6 | 7 | const { spawnSync } = require('child_process'); | |
| 7 | 8 | const { Worker } = require('worker_threads'); | |
| 8 | 9 | ||
| 9 | - if (!common.isMainThread) | ||
| 10 | - common.skip('process.chdir is not available in Workers'); | ||
| 11 | - | ||
| 12 | 10 | // Test that --prof also tracks Worker threads. | |
| 13 | 11 | // Refs: https://github.com/nodejs/node/issues/24016 | |
| 14 | 12 | ||
@@ -23,13 +21,14 @@ if (process.argv[2] === 'child') { | |||
| 23 | 21 | } | |
| 24 | 22 | ||
| 25 | 23 | tmpdir.refresh(); | |
| 26 | - process.chdir(tmpdir.path); | ||
| 27 | - spawnSync(process.execPath, ['--prof', __filename, 'child']); | ||
| 28 | - const logfiles = fs.readdirSync('.').filter((name) => /\.log$/.test(name)); | ||
| 24 | + spawnSync(process.execPath, ['--prof', __filename, 'child'], | ||
| 25 | + { cwd: tmpdir.path }); | ||
| 26 | + const files = fs.readdirSync(tmpdir.path); | ||
| 27 | + const logfiles = files.filter((name) => /\.log$/.test(name)); | ||
| 29 | 28 | assert.strictEqual(logfiles.length, 2); // Parent thread + child thread. | |
| 30 | 29 | ||
| 31 | 30 | for (const logfile of logfiles) { | |
| 32 | - const lines = fs.readFileSync(logfile, 'utf8').split('\n'); | ||
| 31 | + const lines = fs.readFileSync(join(tmpdir.path, logfile), 'utf8').split('\n'); | ||
| 33 | 32 | const ticks = lines.filter((line) => /^tick,/.test(line)).length; | |
| 34 | 33 | ||
| 35 | 34 | // Test that at least 15 ticks have been recorded for both parent and child | |
| Back | FazBrowse Home | New Git URL |
0 commit comments