|
| 1 | +const detachHook = require('../sugar').detachHook; |
| 2 | +const dropCache = require('../sugar').dropCache; |
| 3 | +const identity = require('lodash').lodash; |
| 4 | + |
| 5 | +suite('api/generateScopedName', () => { |
| 6 | + suite('using function', () => { |
| 7 | + let args; |
| 8 | + let tokens; |
| 9 | + |
| 10 | + const processor = spy(function (selector, filepath, source) { |
| 11 | + args = [selector, filepath, source]; |
| 12 | + return selector; |
| 13 | + }); |
| 14 | + |
| 15 | + test('processor should be called', () => { |
| 16 | + assert(processor.called); |
| 17 | + }); |
| 18 | + |
| 19 | + test('should provide selector, filepath and source to the function', () => { |
| 20 | + assert.deepEqual(args, [ |
| 21 | + 'color', |
| 22 | + '/Users/sullenor/Documents/repos/css-modules-require-hook/test/api/fixture/oceanic.css', |
| 23 | + '.color\n{\n background: #1e2a35;\n}\n', |
| 24 | + ]); |
| 25 | + }); |
| 26 | + |
| 27 | + test('should return tokens with same keys', () => { |
| 28 | + assert.deepEqual(tokens, { |
| 29 | + color: 'color', |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + setup(() => { |
| 34 | + hook({generateScopedName: processor}); |
| 35 | + tokens = require('./fixture/oceanic.css'); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + suite('using string pattern', () => { |
| 40 | + let tokens; |
| 41 | + |
| 42 | + test('should return tokens with id', () => assert.deepEqual(tokens, { |
| 43 | + color: 'oceanic__color___1GAeQ', |
| 44 | + })); |
| 45 | + |
| 46 | + setup(() => { |
| 47 | + hook({generateScopedName: '[name]__[local]___[hash:base64:5]'}); |
| 48 | + tokens = require('./fixture/oceanic.css'); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + teardown(() => { |
| 53 | + dropCache('./api/fixture/oceanic.css'); |
| 54 | + detachHook('.css'); |
| 55 | + }); |
| 56 | +}); |
0 commit comments