From ec30bf05e4678ae2e3d2e9768e6ed340e857d7ae Mon Sep 17 00:00:00 2001 From: Tho Date: Sat, 1 Oct 2022 18:57:38 +0800 Subject: [PATCH] fs: add test for cpSync --- test/parallel/test-fs-cp.mjs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/parallel/test-fs-cp.mjs b/test/parallel/test-fs-cp.mjs index 7181bb636699b0..3cb32787549728 100644 --- a/test/parallel/test-fs-cp.mjs +++ b/test/parallel/test-fs-cp.mjs @@ -336,6 +336,24 @@ if (!isWindows) { }, { code: 'ERR_INVALID_RETURN_VALUE' }); } +// It should not throw exception if child folder +// does not pass filter function +{ + // Create a file in dest with the same name as a child folder in src + // expect: this shouldn't throw error since filtered out by filter function + const src = nextdir(); + mkdirSync(join(src, 'foo'), mustNotMutateObjectDeep({ recursive: true })); + + const dest = nextdir(); + mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true })); + writeFileSync(join(dest, 'foo'), 'foo-content', mustNotMutateObjectDeep({ mode: 0o444 })); + + cpSync(src, dest, { + filter: (path) => !path.includes('foo'), + recursive: true, + }); +} + // It throws error if errorOnExist is true, force is false, and file or folder // copied over. {