node/test/parallel/test-path.js
Michaël Zasso 06ee10e523
test: split path tests into multiple files
Create one file for testing each function of the path module.
Keep general error tests and tests for constant properties in
test-path.js.

PR-URL: https://github.com/nodejs/node/pull/15093
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-10-25 04:09:43 -04:00

52 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
// Test thrown TypeErrors
const typeErrorTests = [true, false, 7, null, {}, undefined, [], NaN];
function fail(fn) {
const args = Array.from(arguments).slice(1);
assert.throws(() => {
fn.apply(null, args);
}, TypeError);
}
typeErrorTests.forEach((test) => {
[path.posix, path.win32].forEach((namespace) => {
fail(namespace.join, test);
fail(namespace.resolve, test);
fail(namespace.normalize, test);
fail(namespace.isAbsolute, test);
fail(namespace.relative, test, 'foo');
fail(namespace.relative, 'foo', test);
fail(namespace.parse, test);
fail(namespace.dirname, test);
fail(namespace.basename, test);
fail(namespace.extname, test);
// undefined is a valid value as the second argument to basename
if (test !== undefined) {
fail(namespace.basename, 'foo', test);
}
});
});
// path.sep tests
// windows
assert.strictEqual(path.win32.sep, '\\');
// posix
assert.strictEqual(path.posix.sep, '/');
// path.delimiter tests
// windows
assert.strictEqual(path.win32.delimiter, ';');
// posix
assert.strictEqual(path.posix.delimiter, ':');
if (common.isWindows)
assert.deepStrictEqual(path, path.win32, 'should be win32 path module');
else
assert.deepStrictEqual(path, path.posix, 'should be posix path module');