Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add type check
  • Loading branch information
zero1five committed Jun 11, 2019
commit bf33d637c1b4b1300524e91dd149b002622127e6
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// 'Software'), to deal in the Software without restriction, including
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
Expand All @@ -11,7 +11,7 @@
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Expand Down
37 changes: 37 additions & 0 deletions test/parallel/test-fs-rmdir-type-check.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

[false, 1, [], {}, null, undefined].forEach((i) => {
common.expectsError(
Expand All @@ -19,3 +24,35 @@ const fs = require('fs');
}
);
});

const d = path.join(tmpdir.path, 'dir', 'test_rmdir_typecheck');
// Make sure the directory does not exist
assert(!fs.existsSync(d));
// Create the directory now
fs.mkdirSync(d, { recursive: true });

// Tests for clearDir option
['true', 1, [], {}].forEach((i) => {
common.expectsError(
() => fs.rmdirSync(d, { clearDir: i }),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
}
);
common.expectsError(
() => fs.rmdir(d, { clearDir: i }, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
}
);
assert.rejects(
fs.promises.rmdir(d, { clearDir: i }),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "clearDir" argument must be of type boolean. ' +
`Received type ${typeof i}`
}
);
});