From 4eea1b5670ac69d248262b764e448f774b2929ed Mon Sep 17 00:00:00 2001 From: Shinnosuke Watanabe Date: Thu, 20 Dec 2018 20:40:02 +0900 Subject: [PATCH] test if it supports file URL of a UNC path ref. https://nodejs.org/api/fs.html#fs_url_object_support --- test.js | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/test.js b/test.js index e3b56e4..0b2d311 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,7 @@ 'use strict'; const {dirname, join} = require('path'); +const {hostname} = require('os'); const {isMap} = require('util').types; const {pathToFileURL} = require('url'); const {symlink, unlink} = require('fs').promises; @@ -9,25 +10,30 @@ const lstatDir = require('.'); const test = require('tape'); const nonEssentialFilesRe = /(\.DS_Store|\.git|\.nyc_output|coverage)$/u; +const expected = [ + '.editorconfig', + '.gitattributes', + '.gitignore', + '.travis.yml', + 'index.js', + 'LICENSE', + 'node_modules', + 'package-lock.json', + 'package.json', + 'README.md', + 'test.js' +]; test('lstatDir()', async t => { const result = await lstatDir(__dirname); t.ok(isMap(result), 'should be fulfilled with a Map instance.'); - t.deepEqual([...result.keys()].filter(path => !nonEssentialFilesRe.test(path)), [ - '.editorconfig', - '.gitattributes', - '.gitignore', - '.travis.yml', - 'index.js', - 'LICENSE', - 'node_modules', - 'package-lock.json', - 'package.json', - 'README.md', - 'test.js' - ].map(path => join(__dirname, path)), 'should list all contents in a directory.'); + t.deepEqual( + [...result.keys()].filter(path => !nonEssentialFilesRe.test(path)), + expected.map(path => join(__dirname, path)), + 'should list all contents in a directory.' + ); const dir = dirname(require.resolve('readdir-sorted')); const tmp = join(__dirname, 'test-tmp-dir'); @@ -58,6 +64,18 @@ test('lstatDir()', async t => { t.end(); }); +(process.platform === 'win32' ? test : test.skip)('lstatDir() on Windows', async t => { + const url = new URL(`file://${hostname()}/${__dirname.replace(/\\/ug, '/').replace(/^([a-z]):/ui, '$1$')}`); + + t.deepEqual( + (await lstatDir(url)).filter(path => !nonEssentialFilesRe.test(path)), + expected.map(path => join(`\\${hostname()}`, __dirname, path)), + 'should support file URL of a UNC path.' + ); + + t.end(); +}); + test('Argument validation', async t => { try { await lstatDir([1, 2]);