Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTho <thoqbk@gmail.com>2022-10-10 18:38:55 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2022-10-11 16:10:13 +0300
commitbc00f3bde14120714da3b0ce7d3efcf9abb1cba0 (patch)
treeedf219eec4ec1ba4e8b00e57f3cec4da2bdb2b9e /test
parent4bdef48732cdaa40ed049697b884fcc4515d8299 (diff)
fs: fix opts.filter issue in cp async
PR-URL: https://github.com/nodejs/node/pull/44922 Fixes: https://github.com/nodejs/node/issues/44720 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-cp.mjs37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/parallel/test-fs-cp.mjs b/test/parallel/test-fs-cp.mjs
index 7181bb63669..8a4a327c059 100644
--- a/test/parallel/test-fs-cp.mjs
+++ b/test/parallel/test-fs-cp.mjs
@@ -746,6 +746,43 @@ if (!isWindows) {
}));
}
+// Copy async should not throw exception if child folder is filtered out.
+{
+ const src = nextdir();
+ mkdirSync(join(src, 'test-cp-async'), mustNotMutateObjectDeep({ recursive: true }));
+
+ const dest = nextdir();
+ mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
+ writeFileSync(join(dest, 'test-cp-async'), 'test-content', mustNotMutateObjectDeep({ mode: 0o444 }));
+
+ cp(src, dest, {
+ filter: (path) => !path.includes('test-cp-async'),
+ recursive: true,
+ }, mustCall((err) => {
+ assert.strictEqual(err, null);
+ }));
+}
+
+// Copy async should not throw exception if dest is invalid but filtered out.
+{
+ // Create dest as a file.
+ // Expect: cp skips the copy logic entirely and won't throw any exception in path validation process.
+ const src = join(nextdir(), 'bar');
+ mkdirSync(src, mustNotMutateObjectDeep({ recursive: true }));
+
+ const destParent = nextdir();
+ const dest = join(destParent, 'bar');
+ mkdirSync(destParent, mustNotMutateObjectDeep({ recursive: true }));
+ writeFileSync(dest, 'test-content', mustNotMutateObjectDeep({ mode: 0o444 }));
+
+ cp(src, dest, {
+ filter: (path) => !path.includes('bar'),
+ recursive: true,
+ }, mustCall((err) => {
+ assert.strictEqual(err, null);
+ }));
+}
+
// It throws if options is not object.
{
assert.throws(