Skip to content

Commit

Permalink
Fix tests on Windows and Node.js 12 (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
RyanZim and sindresorhus committed Feb 12, 2020
1 parent 9de6474 commit 3354122
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 9 additions & 3 deletions test/async.js
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import test from 'ava';
import tempy from 'tempy';
import gracefulFs from 'graceful-fs';
import semver from 'semver';
import {getFixture, assertDirectory, customFsOptions} from './helpers/util';
import makeDir from '..';

Expand Down Expand Up @@ -119,10 +120,15 @@ test.serial('handles invalid path characters', async t => {

if (process.platform === 'win32') {
test('handles non-existent root', async t => {
// We assume the `o:\` drive doesn't exist on Windows
await t.throwsAsync(makeDir('o:\\foo'), {
const expectedError = semver.satisfies(process.version, '>=12') ? {
code: 'ENOENT',
message: /no such file or directory, mkdir/
} : {
code: 'EPERM',
message: /operation not permitted, mkdir/
});
};

// We assume the `o:\` drive doesn't exist on Windows.
await t.throwsAsync(makeDir('o:\\foo'), expectedError);
});
}
16 changes: 11 additions & 5 deletions test/sync.js
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import test from 'ava';
import tempy from 'tempy';
import gracefulFs from 'graceful-fs';
import semver from 'semver';
import {getFixture, assertDirectory, customFsOptions} from './helpers/util';
import makeDir from '..';

Expand Down Expand Up @@ -105,12 +106,17 @@ test('handles null bytes in path', t => {

if (process.platform === 'win32') {
test('handles non-existent root', t => {
// We assume the `o:\` drive doesn't exist on Windows
t.throws(() => {
makeDir.sync('o:\\foo');
}, {
const expectedError = semver.satisfies(process.version, '>=12') ? {
code: 'ENOENT',
message: /no such file or directory, mkdir/
} : {
code: 'EPERM',
message: /operation not permitted, mkdir/
});
};

// We assume the `o:\` drive doesn't exist on Windows.
t.throws(() => {
makeDir.sync('o:\\foo');
}, expectedError);
});
}

0 comments on commit 3354122

Please sign in to comment.