From 0f7601276303829fc33dc4d73907e4025f8e7193 Mon Sep 17 00:00:00 2001 From: Karl von Randow Date: Sat, 6 Apr 2019 07:10:13 +1300 Subject: [PATCH] feat: test case checker supports nested directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to test output into nested directories, such as I’m about to add for the publicpath-function test. --- test/TestCases.test.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/test/TestCases.test.js b/test/TestCases.test.js index ee4cd52c..10a49bf0 100644 --- a/test/TestCases.test.js +++ b/test/TestCases.test.js @@ -59,18 +59,33 @@ describe('TestCases', () => { ); return; } - const expectedDirectory = path.resolve(directoryForCase, 'expected'); - for (const file of fs.readdirSync(expectedDirectory)) { - const content = fs.readFileSync( - path.resolve(expectedDirectory, file), - 'utf-8' - ); - const actualContent = fs.readFileSync( - path.resolve(outputDirectoryForCase, file), - 'utf-8' - ); - expect(actualContent).toEqual(content); + + function compareDirectory(actual, expected) { + for (const file of fs.readdirSync(expected, { + withFileTypes: true, + })) { + if (file.isFile()) { + const content = fs.readFileSync( + path.resolve(expected, file.name), + 'utf-8' + ); + const actualContent = fs.readFileSync( + path.resolve(actual, file.name), + 'utf-8' + ); + expect(actualContent).toEqual(content); + } else if (file.isDirectory()) { + compareDirectory( + path.resolve(actual, file.name), + path.resolve(expected, file.name) + ); + } + } } + + const expectedDirectory = path.resolve(directoryForCase, 'expected'); + compareDirectory(outputDirectoryForCase, expectedDirectory); + done(); }); }, 10000);