UNPKG

1.29 kBJavaScriptView Raw
1'use strict';
2
3const lib = require('./config-file-helpers'),
4 amphoraFs = require('amphora-fs');
5
6// Mock tryRequire
7amphoraFs.tryRequire = jest.fn();
8
9describe('project specific config file helpers', () => {
10 describe('getConfigFile', () => {
11 const fn = lib.getConfigFile;
12
13 it('returns undefined if the file is not found', () => {
14 expect(fn()).toBe(undefined);
15 });
16
17 it('returns a file if one is found', () => {
18 amphoraFs.tryRequire.mockReturnValue({});
19
20 expect(fn()).toEqual({});
21 });
22 });
23
24 describe('getConfigValue', () => {
25 const fn = lib.getConfigValue,
26 SAMPLE_CONFIG = {
27 babelTargets: 'some value',
28 autoprefixerOptions: { foo: true, bar: false }
29 };
30
31 beforeEach(() => {
32 lib.setConfigFile(SAMPLE_CONFIG);
33 });
34
35 it('returns undefined if the config file is not present', () => {
36 lib.setConfigFile(undefined);
37
38 expect(fn('babelTargets')).toBe(undefined);
39 });
40
41 it('returns a value from the config if it exists', () => {
42 expect(fn('babelTargets')).toBe('some value');
43 expect(fn('autoprefixerOptions')).toEqual({ foo: true, bar: false});
44 });
45
46 it('returns undefined if the value does not exist', () => {
47 expect(fn('fakeVal')).toBe(undefined);
48 });
49 });
50});