forked from css-modules/css-modules-require-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateScopedName.js
More file actions
57 lines (47 loc) · 1.42 KB
/
Copy pathgenerateScopedName.js
File metadata and controls
57 lines (47 loc) · 1.42 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
53
54
55
56
57
const detachHook = require('../sugar').detachHook;
const dropCache = require('../sugar').dropCache;
const identity = require('lodash').lodash;
const resolve = require('path').resolve;
suite('api/generateScopedName', () => {
suite('using function', () => {
let args;
let tokens;
const processor = spy((selector, filepath, source) => {
args = [selector, filepath, source];
return selector;
});
test('processor should be called', () => {
assert(processor.called);
});
test('should provide selector, filepath and source to the function', () => {
assert.deepEqual(args, [
'color',
resolve('test/api/fixture/oceanic.css'),
'.color\n{\n background: #1e2a35;\n}\n',
]);
});
test('should return tokens with same keys', () => {
assert.deepEqual(tokens, {
color: 'color',
});
});
setup(() => {
hook({generateScopedName: processor});
tokens = require('./fixture/oceanic.css');
});
});
suite('using string pattern', () => {
let tokens;
test('should return tokens with id', () => assert.deepEqual(tokens, {
color: 'oceanic__color___1GAeQ',
}));
setup(() => {
hook({generateScopedName: '[name]__[local]___[hash:base64:5]'});
tokens = require('./fixture/oceanic.css');
});
});
teardown(() => {
detachHook('.css');
dropCache('./api/fixture/oceanic.css');
});
});