|
| 1 | +const detachHook = require('../sugar').detachHook; |
| 2 | +const dropCache = require('../sugar').dropCache; |
| 3 | +const resolve = require('path').resolve; |
| 4 | +const writeFileSync = require('fs').writeFileSync; |
| 5 | + |
| 6 | +const destination = resolve(__dirname, './fixture/oceanic.css'); |
| 7 | +const source1 = `.color\n{\n background: #1e2a35;\n}\n`; |
| 8 | +const source2 = `.awesome-color\n{\n background: #1e2a35;\n}\n`; |
| 9 | + |
| 10 | +suite('env.NODE_ENV', () => { |
| 11 | + suite('in the development mode', () => { |
| 12 | + test('should get tokens from fs, not from cache', () => { |
| 13 | + const tokens = require('./fixture/oceanic.css'); |
| 14 | + |
| 15 | + assert.deepEqual(tokens, { |
| 16 | + 'awesome-color': '_test_env_fixture_oceanic__awesome-color', |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + setup(() => { |
| 21 | + process.env.NODE_ENV = 'development'; |
| 22 | + hook({}); |
| 23 | + writeFile(source1); |
| 24 | + require('./fixture/oceanic.css'); |
| 25 | + writeFile(source2); |
| 26 | + }); |
| 27 | + |
| 28 | + teardown(() => { |
| 29 | + process.env.NODE_ENV = ''; |
| 30 | + writeFile(source1); |
| 31 | + detachHook('.css'); |
| 32 | + dropCache('./env/fixture/oceanic.css'); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + suite('not in the development mode', () => { |
| 37 | + test('should get tokens from cache', () => { |
| 38 | + const tokens = require('./fixture/oceanic.css'); |
| 39 | + |
| 40 | + assert.deepEqual(tokens, { |
| 41 | + 'color': '_test_env_fixture_oceanic__color', |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + setup(() => { |
| 46 | + hook({}); |
| 47 | + require('./fixture/oceanic.css'); |
| 48 | + }); |
| 49 | + |
| 50 | + teardown(() => { |
| 51 | + detachHook('.css'); |
| 52 | + dropCache('./env/fixture/oceanic.css'); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +/** |
| 58 | + * @param {string} data |
| 59 | + */ |
| 60 | +function writeFile(data) { |
| 61 | + writeFileSync(destination, data, 'utf8'); |
| 62 | +} |
0 commit comments