YM
2025-08-07 e5c64590b336221f132ed28ae4ae6dca3e03055c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
 
// These testcases are specific to one uncommon behavior in path module. Few
// of the functions in path module, treat '' strings as current working
// directory. This test makes sure that the behavior is intact between commits.
// See: https://github.com/nodejs/node/pull/2106
 
var tape = require('tape');
var path = require('../');
var pwd = process.cwd();
 
tape('path.join zero-length', function (t) {
  // join will internally ignore all the zero-length strings and it will return
  // '.' if the joined string is a zero-length string.
  t.strictEqual(path.posix.join(''), '.');
  t.strictEqual(path.posix.join('', ''), '.');
  if (path.win32) t.strictEqual(path.win32.join(''), '.');
  if (path.win32) t.strictEqual(path.win32.join('', ''), '.');
  t.strictEqual(path.join(pwd), pwd);
  t.strictEqual(path.join(pwd, ''), pwd);
  t.end();
});
 
tape('path.normalize zero-length', function (t) {
  // normalize will return '.' if the input is a zero-length string
  t.strictEqual(path.posix.normalize(''), '.');
  if (path.win32) t.strictEqual(path.win32.normalize(''), '.');
  t.strictEqual(path.normalize(pwd), pwd);
  t.end();
});
 
tape('path.isAbsolute zero-length', function (t) {
  // Since '' is not a valid path in any of the common environments, return false
  t.strictEqual(path.posix.isAbsolute(''), false);
  if (path.win32) t.strictEqual(path.win32.isAbsolute(''), false);
  t.end();
});
 
tape('path.resolve zero-length', function (t) {
  // resolve, internally ignores all the zero-length strings and returns the
  // current working directory
  t.strictEqual(path.resolve(''), pwd);
  t.strictEqual(path.resolve('', ''), pwd);
  t.end();
});
 
tape('path.relative zero-length', function (t) {
  // relative, internally calls resolve. So, '' is actually the current directory
  t.strictEqual(path.relative('', pwd), '');
  t.strictEqual(path.relative(pwd, ''), '');
  t.strictEqual(path.relative(pwd, pwd), '');
  t.end();
});