Skip to content

Commit

Permalink
feat: test case checker supports nested directories
Browse files Browse the repository at this point in the history
In order to test output into nested directories, such as I’m about to add for the publicpath-function test.
  • Loading branch information
karlvr committed Apr 5, 2019
1 parent a9985d8 commit 0f76012
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions test/TestCases.test.js
Expand Up @@ -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);
Expand Down

0 comments on commit 0f76012

Please sign in to comment.