Skip to content

Commit

Permalink
test if it supports file URL of a UNC path
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Dec 20, 2018
1 parent 9cd84bb commit 4eea1b5
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions 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;
Expand All @@ -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');
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 4eea1b5

Please sign in to comment.