Skip to content

Commit 907e90e

Browse files
committed
test: add integration test for custom pattern, hash length
1 parent f659975 commit 907e90e

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/tests/__fixtures__/original/script.oh-my-hash.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests/plugin.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ test.equal(
6565
"script.b0dcc67f.js"
6666
);
6767

68+
const CUSTOM_EXP_2 = new RegExp(/\oh-my-hash/);
69+
70+
test.equal(
71+
replaceHash("oh-my-hash.js", buffer, CUSTOM_EXP_2, DEFAULT_HASH_LENGTH),
72+
"b0dcc67ffc1fd562f212.js"
73+
);
74+
test.equal(
75+
replaceHash("script.oh-my-hash.js", buffer, CUSTOM_EXP_2, 8),
76+
"script.b0dcc67f.js"
77+
);
78+
6879
function copyFixture(fileName: string) {
6980
const file = path.join(__dirname, "__fixtures__/original", fileName);
7081
fs.copyFileSync(
@@ -95,6 +106,29 @@ async function fixture() {
95106
result.html.replace(/\n|\s+/g, ""),
96107
'<html><head><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,600i,700,700i"><linkrel="stylesheet"href="bundle.min.9a6cf95c41e87b9dc102.css"></head><body><scriptsrc="bundle.min.b0dcc67ffc1fd562f212.js"></script></body></html>'
97108
);
109+
110+
copyFixture("script.oh-my-hash.js");
111+
112+
const result2 = await posthtml()
113+
.use(
114+
hash({
115+
path: "src/tests/__fixtures__/processed",
116+
pattern: new RegExp(/\oh-my-hash/),
117+
hashLength: 8,
118+
})
119+
)
120+
.process(
121+
`<html>
122+
<body>
123+
<script src="script.oh-my-hash.js"></script>
124+
</body>
125+
</html>`
126+
);
127+
128+
test.equal(
129+
result2.html.replace(/\n|\s+/g, ""),
130+
'<html><body><scriptsrc="script.b0dcc67f.js"></script></body></html>'
131+
);
98132
}
99133

100134
fixture();

0 commit comments

Comments
 (0)