-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (42 loc) · 1.2 KB
/
index.js
File metadata and controls
52 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
const genericNames = require("../index");
const test = require("tape");
const path = require("path");
const pattern = "[name]__[local]___[hash:base64:5]";
test("use `cwd` if no context was provided", t => {
const generate = genericNames(pattern);
t.equal(
generate("foo", path.join(__dirname, "test/case/source.css")),
"source__foo___VihAC"
);
t.end();
});
test("generate distinct hash for the provided context", t => {
const generate = genericNames(pattern, {
context: path.join(__dirname, "/test")
});
t.equal(
generate("foo", path.join(__dirname, "test/case/source.css")),
"source__foo___ZIJxV"
);
t.end();
});
test("generate distinct hash for the provided hashPrefix", t => {
const generate = genericNames(pattern, {
context: path.join(__dirname, "/test"),
hashPrefix: "--"
});
t.equal(
generate("foo", path.join(__dirname, "test/case/source.css")),
"source__foo___QTVQp"
);
t.end();
});
test("use group matches if regExp was provided", t => {
const generate = genericNames('[1]__[2]', { regExp: /([^/]*)\/([^/]*)$/ })
t.equal(
generate("foo", path.join(__dirname, "test/case/source.css")),
"case__source-css"
);
t.end()
})