From aa3e4f15f71ab92010fca1357fc2aa36892e24a3 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..3fb890e8405d86 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 +{ + // Mimic there's a file in dest with the same name as the 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. {