Skip to content

Commit a455a15

Browse files
committed
Test collectLocalAssets options
1 parent 3efe65f commit a455a15

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

tests/unit.mjs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ function readDirectoryFiles(path) {
8484
return readdirSync(path, {withFileTypes: true}).filter(path => path.isFile()).map(path => path.name);
8585
}
8686

87-
test("collectLocalAssets works as expected", t => {
88-
const outputDir = "tests/input/";
89-
const assetDir = outputDir + "assets";
87+
const CLA_TEST_DATA = {
88+
outputDir: "tests/input/",
89+
assetDir: "tests/input/assets",
90+
assetFiles: readDirectoryFiles("tests/input/assets").map(filename => "tests/input/assets/"+filename).concat(
91+
readDirectoryFiles("tests/input/assets/subdir").map(name => "tests/input/assets/subdir/" + name)),
92+
};
9093

91-
const assetFiles = readDirectoryFiles(assetDir).map(filename => assetDir+"/"+filename).concat(
92-
readDirectoryFiles(assetDir + "/subdir").map(name => assetDir + "/subdir/" + name));
93-
const collected = collectLocalAssets(assetFiles, "tests/input/");
94+
test("collectLocalAssets works as expected", t => {
95+
const {outputDir, assetFiles} = CLA_TEST_DATA;
9496

97+
const collected = collectLocalAssets(assetFiles, outputDir);
9598
const expected = assetFiles.map(assetPath => {
9699
return {
97100
assetPath: assetPath.replace(outputDir, ""),
@@ -101,4 +104,20 @@ test("collectLocalAssets works as expected", t => {
101104
})
102105

103106
t.deepEqual(expected, collected);
104-
})
107+
})
108+
109+
test("collectLocalAssets options extensions & hashFunction are applied", t => {
110+
const {outputDir, assetFiles} = CLA_TEST_DATA;
111+
112+
const collected = collectLocalAssets(assetFiles, outputDir, ["css", "jpg"], content => {return "testvalue"});
113+
114+
115+
const expected = assetFiles.filter(filename => filename.toLowerCase().endsWith("jpg") || filename.toLowerCase().endsWith("css")).map(assetPath => {
116+
return {
117+
assetPath: assetPath.replace(outputDir, ""),
118+
assetHash: "testvalue"
119+
}
120+
})
121+
122+
t.deepEqual(expected, collected);
123+
});

0 commit comments

Comments
 (0)