Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/parallel/test-process-chdir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');

assert.notStrictEqual(process.cwd(), __dirname);
process.chdir(__dirname);
assert.strictEqual(process.cwd(), __dirname);

const dir = path.resolve(common.tmpDir,
'weird \uc3a4\uc3ab\uc3af characters \u00e1\u00e2\u00e3');

// Make sure that the tmp directory is clean
common.refreshTmpDir();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is effectively unsafe after using common.tmpDir?

Isn't it possible that your tmpDir is different then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 refresh just removes the directory and creates it

exports.refreshTmpDir = function() {
  rimrafSync(exports.tmpDir);
  fs.mkdirSync(exports.tmpDir);
};

The name is actually decided when we load the module itself,

if (process.env.TEST_THREAD_ID) {
  // Distribute ports in parallel tests
  if (!process.env.NODE_COMMON_PORT)
    exports.PORT += +process.env.TEST_THREAD_ID * 100;

  exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
}
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);

Since we are just resolving the path before that, we are safe here.


fs.mkdirSync(dir);
process.chdir(dir);
assert.strictEqual(process.cwd(), dir);

process.chdir('..');
assert.strictEqual(process.cwd(), path.resolve(common.tmpDir));

assert.throws(function() { process.chdir({}); }, TypeError, 'Bad argument.');
assert.throws(function() { process.chdir(); }, TypeError, 'Bad argument.');
assert.throws(function() { process.chdir('x', 'y'); },
TypeError, 'Bad argument.');
38 changes: 0 additions & 38 deletions test/sequential/test-chdir.js

This file was deleted.