|
| 1 | +import { equal } from 'assert'; |
| 2 | +import { writeFileSync } from 'fs'; |
| 3 | +import { join } from 'path'; |
| 4 | +import { dropCache } from '../utils/sugar'; |
| 5 | +import hook from '../src'; |
| 6 | + |
| 7 | +const fixture = join(__dirname, 'fixture/dynamic.css'); |
| 8 | + |
| 9 | +function updateFile(content) { |
| 10 | + writeFileSync(fixture, content, 'utf8'); |
| 11 | +} |
| 12 | + |
| 13 | +describe('development mode', () => { |
| 14 | + describe('should cache calls not in development mode', () => { |
| 15 | + before(() => { |
| 16 | + hook(); |
| 17 | + updateFile('.block\n{\n display: block;\n}'); |
| 18 | + process.env.NODE_ENV = ''; |
| 19 | + require(fixture); |
| 20 | + updateFile('.inline-block\n{\n display: inline-block;\n}'); |
| 21 | + }); |
| 22 | + |
| 23 | + after(() => { |
| 24 | + process.env.NODE_ENV = ''; |
| 25 | + dropCache(fixture); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should retrive data from cache', () => { |
| 29 | + const tokens = require(fixture); |
| 30 | + const keys = Object.keys(tokens); |
| 31 | + equal(keys.length, 1); |
| 32 | + equal(keys.join(''), 'block'); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + describe('should clear cache in development mode', () => { |
| 37 | + before(() => { |
| 38 | + hook(); |
| 39 | + updateFile('.block\n{\n display: block;\n}'); |
| 40 | + process.env.NODE_ENV = 'development'; |
| 41 | + require(fixture); |
| 42 | + updateFile('.inline-block\n{\n display: inline-block;\n}'); |
| 43 | + }); |
| 44 | + |
| 45 | + after(() => { |
| 46 | + process.env.NODE_ENV = ''; |
| 47 | + dropCache(fixture); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should retrive data from fs', () => { |
| 51 | + const tokens = require(fixture); |
| 52 | + const keys = Object.keys(tokens); |
| 53 | + equal(keys.length, 1); |
| 54 | + equal(keys.join(''), 'inline-block'); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments