Skip to content

Commit 0f76012

Browse files
committed
feat: test case checker supports nested directories
In order to test output into nested directories, such as I’m about to add for the publicpath-function test.
1 parent a9985d8 commit 0f76012

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

test/TestCases.test.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,33 @@ describe('TestCases', () => {
5959
);
6060
return;
6161
}
62-
const expectedDirectory = path.resolve(directoryForCase, 'expected');
63-
for (const file of fs.readdirSync(expectedDirectory)) {
64-
const content = fs.readFileSync(
65-
path.resolve(expectedDirectory, file),
66-
'utf-8'
67-
);
68-
const actualContent = fs.readFileSync(
69-
path.resolve(outputDirectoryForCase, file),
70-
'utf-8'
71-
);
72-
expect(actualContent).toEqual(content);
62+
63+
function compareDirectory(actual, expected) {
64+
for (const file of fs.readdirSync(expected, {
65+
withFileTypes: true,
66+
})) {
67+
if (file.isFile()) {
68+
const content = fs.readFileSync(
69+
path.resolve(expected, file.name),
70+
'utf-8'
71+
);
72+
const actualContent = fs.readFileSync(
73+
path.resolve(actual, file.name),
74+
'utf-8'
75+
);
76+
expect(actualContent).toEqual(content);
77+
} else if (file.isDirectory()) {
78+
compareDirectory(
79+
path.resolve(actual, file.name),
80+
path.resolve(expected, file.name)
81+
);
82+
}
83+
}
7384
}
85+
86+
const expectedDirectory = path.resolve(directoryForCase, 'expected');
87+
compareDirectory(outputDirectoryForCase, expectedDirectory);
88+
7489
done();
7590
});
7691
}, 10000);

0 commit comments

Comments
 (0)