1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const fs = require('fs'); 6const path = require('path'); 7 8if (!common.isMainThread) 9 common.skip('process.chdir is not available in Workers'); 10 11const tmpdir = require('../common/tmpdir'); 12 13process.chdir('..'); 14assert.notStrictEqual(process.cwd(), __dirname); 15process.chdir(__dirname); 16assert.strictEqual(process.cwd(), __dirname); 17 18let dirName; 19if (process.versions.icu) { 20 // ICU is available, use characters that could possibly be decomposed 21 dirName = 'weird \uc3a4\uc3ab\uc3af characters \u00e1\u00e2\u00e3'; 22} else { 23 // ICU is unavailable, use characters that can't be decomposed 24 dirName = 'weird \ud83d\udc04 characters \ud83d\udc05'; 25} 26const dir = path.resolve(tmpdir.path, dirName); 27 28// Make sure that the tmp directory is clean 29tmpdir.refresh(); 30 31fs.mkdirSync(dir); 32process.chdir(dir); 33assert.strictEqual(process.cwd().normalize(), dir.normalize()); 34 35process.chdir('..'); 36assert.strictEqual(process.cwd().normalize(), 37 path.resolve(tmpdir.path).normalize()); 38 39const err = { 40 code: 'ERR_INVALID_ARG_TYPE', 41 message: /The "directory" argument must be of type string/ 42}; 43assert.throws(function() { process.chdir({}); }, err); 44assert.throws(function() { process.chdir(); }, err); 45