Skip to content

Commit a0eca57

Browse files
committed
add allowNumericOnlyHash test
1 parent 8c3814b commit a0eca57

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

test/__snapshots__/Cli.basictest.js.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,19 @@ Object {
13741374
"multiple": false,
13751375
"simpleType": "string",
13761376
},
1377+
"module-generator-asset-resource-allow-numeric-only-hash": Object {
1378+
"configs": Array [
1379+
Object {
1380+
"description": "Hash may not contain any non-numeric characters when true. Hash may prefixed with character 'a' when false.",
1381+
"multiple": false,
1382+
"path": "module.generator.asset/resource.allowNumericOnlyHash",
1383+
"type": "boolean",
1384+
},
1385+
],
1386+
"description": "Hash may not contain any non-numeric characters when true. Hash may prefixed with character 'a' when false.",
1387+
"multiple": false,
1388+
"simpleType": "boolean",
1389+
},
13771390
"module-generator-asset-resource-emit": Object {
13781391
"configs": Array [
13791392
Object {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import url from "../_images/file.png";
2+
import url2 from "../_images/file_copy.png";
3+
4+
it("should import asset with module.generator.asset.allowNumericOnlyHash", () => {
5+
expect(url).toMatch(/images\/file\.[a-f0-9]{6}\.png$/);
6+
expect(url2).toMatch(/images\/file_copy\.[a-f0-9]{6}\.png$/);
7+
const assetInfo1 = __STATS__.assets.find(
8+
a => a.info.sourceFilename === "../_images/file.png"
9+
).info;
10+
const assetInfo2 = __STATS__.assets.find(
11+
a => a.info.sourceFilename === "../_images/file_copy.png"
12+
).info;
13+
14+
expect(assetInfo1.contenthash.length).toBe(2);
15+
expect(assetInfo1.contenthash[0].length).toBe(6);
16+
expect(assetInfo1.contenthash[1].length).toBe(6);
17+
expect(assetInfo2.contenthash.length).toBe(2);
18+
expect(assetInfo2.contenthash[0].length).toBe(6);
19+
expect(assetInfo2.contenthash[1].length).toBe(6);
20+
21+
expect(assetInfo1.fullhash).toBe(assetInfo2.fullhash);
22+
expect(assetInfo1.contenthash[0]).not.toEqual(assetInfo2.contenthash[0]);
23+
expect(assetInfo1.contenthash[0].slice(1)).toEqual(assetInfo2.contenthash[0].slice(1));
24+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
mode: "development",
4+
output: {
5+
hashDigestLength: 6
6+
},
7+
module: {
8+
rules: [
9+
{
10+
test: /file.png$/,
11+
type: "asset/resource",
12+
generator: {
13+
emit: false,
14+
filename: "[name].[contenthash:6][ext]",
15+
allowNumericOnlyHash: false
16+
}
17+
},
18+
{
19+
test: /file_copy.png$/,
20+
type: "asset/resource",
21+
generator: {
22+
emit: false,
23+
filename: "[name].[contenthash:6][ext]",
24+
allowNumericOnlyHash: true
25+
}
26+
}
27+
]
28+
}
29+
};

0 commit comments

Comments
 (0)