diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-26 02:42:50 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-28 12:22:17 +0100 |
commit | 4c4ad120c57595b39bc4407f121ab689bb9ac846 (patch) | |
tree | 9e96868fb1e9f21459822f14b9c4bd858125b9e5 /test/parallel/test-path-parse-format.js | |
parent | df1c9eb9753a3f837b6ab98b720df6547ab93a08 (diff) | |
download | android-node-v8-4c4ad120c57595b39bc4407f121ab689bb9ac846.tar.gz android-node-v8-4c4ad120c57595b39bc4407f121ab689bb9ac846.tar.bz2 android-node-v8-4c4ad120c57595b39bc4407f121ab689bb9ac846.zip |
test: refactor path parse test
Use destructuring and arrow functions and make one test stricter.
Also inline the error object as there's only a sinlge error that can
currently be thrown in the path module.
PR-URL: https://github.com/nodejs/node/pull/26912
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test/parallel/test-path-parse-format.js')
-rw-r--r-- | test/parallel/test-path-parse-format.js | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index c50093301f..09f6bb0e9d 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -51,7 +51,7 @@ const winPaths = [ ]; const winSpecialCaseParseTests = [ - ['/foo/bar', { root: '/' }], + ['/foo/bar', { root: '/', dir: '/foo', base: 'bar', ext: '', name: 'bar' }], ]; const winSpecialCaseFormatTests = [ @@ -98,21 +98,16 @@ const unixSpecialCaseFormatTests = [ [{}, ''] ]; -const expectedMessage = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError -}, 18); - const errors = [ - { method: 'parse', input: [null], message: expectedMessage }, - { method: 'parse', input: [{}], message: expectedMessage }, - { method: 'parse', input: [true], message: expectedMessage }, - { method: 'parse', input: [1], message: expectedMessage }, - { method: 'parse', input: [], message: expectedMessage }, - { method: 'format', input: [null], message: expectedMessage }, - { method: 'format', input: [''], message: expectedMessage }, - { method: 'format', input: [true], message: expectedMessage }, - { method: 'format', input: [1], message: expectedMessage }, + { method: 'parse', input: [null] }, + { method: 'parse', input: [{}] }, + { method: 'parse', input: [true] }, + { method: 'parse', input: [1] }, + { method: 'parse', input: [] }, + { method: 'format', input: [null] }, + { method: 'format', input: [''] }, + { method: 'format', input: [true] }, + { method: 'format', input: [1] }, ]; checkParseFormat(path.win32, winPaths); @@ -153,10 +148,10 @@ const trailingTests = [ ] ]; const failures = []; -trailingTests.forEach(function(test) { +trailingTests.forEach((test) => { const parse = test[0]; const os = parse === path.win32.parse ? 'win32' : 'posix'; - test[1].forEach(function(test) { + test[1].forEach((test) => { const actual = parse(test[0]); const expected = test[1]; const message = `path.${os}.parse(${JSON.stringify(test[0])})\n expect=${ @@ -180,15 +175,18 @@ trailingTests.forEach(function(test) { assert.strictEqual(failures.length, 0, failures.join('')); function checkErrors(path) { - errors.forEach(function(errorCase) { + errors.forEach(({ method, input }) => { assert.throws(() => { - path[errorCase.method].apply(path, errorCase.input); - }, errorCase.message); + path[method].apply(path, input); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError' + }); }); } function checkParseFormat(path, paths) { - paths.forEach(function([element, root]) { + paths.forEach(([element, root]) => { const output = path.parse(element); assert.strictEqual(typeof output.root, 'string'); assert.strictEqual(typeof output.dir, 'string'); @@ -205,19 +203,14 @@ function checkParseFormat(path, paths) { } function checkSpecialCaseParseFormat(path, testCases) { - testCases.forEach(function(testCase) { - const element = testCase[0]; - const expect = testCase[1]; - const output = path.parse(element); - Object.keys(expect).forEach(function(key) { - assert.strictEqual(output[key], expect[key]); - }); + testCases.forEach(([element, expect]) => { + assert.deepStrictEqual(path.parse(element), expect); }); } function checkFormat(path, testCases) { - testCases.forEach(function(testCase) { - assert.strictEqual(path.format(testCase[0]), testCase[1]); + testCases.forEach(([element, expect]) => { + assert.strictEqual(path.format(element), expect); }); [null, undefined, 1, true, false, 'string'].forEach((pathObject) => { |