|
| 1 | +import path from 'path'; |
| 2 | +import test from 'ava'; |
| 3 | +import expect from 'unexpected'; |
| 4 | + |
| 5 | +import getConfiguration from '../../source/library/get-configuration'; |
| 6 | + |
| 7 | +const cwd = process.cwd(); |
| 8 | + |
| 9 | +test('overridden-type-enums should return the exact type-enum', async t => { |
| 10 | + const back = chdir('fixtures/overridden-type-enums'); |
| 11 | + const actual = await getConfiguration(); |
| 12 | + expect(actual.rules['type-enum'][2], 'to equal', [ "a", "b", "c", "d" ]); |
| 13 | + back(); |
| 14 | +}); |
| 15 | + |
| 16 | +test('overridden-extended-type-enums should return the exact type-enum', async t => { |
| 17 | + const back = chdir('fixtures/overridden-extended-type-enums'); |
| 18 | + const actual = await getConfiguration(); |
| 19 | + expect(actual.rules['type-enum'][2], 'to equal', [ "a", "b", "c", "d" ]); |
| 20 | + back(); |
| 21 | +}); |
| 22 | + |
| 23 | +test('extends-empty should have no rules', async t => { |
| 24 | + const back = chdir('fixtures/extends-empty'); |
| 25 | + const actual = await getConfiguration(); |
| 26 | + expect(actual.rules, 'to equal', {}); |
| 27 | + back(); |
| 28 | +}); |
| 29 | + |
| 30 | +test('invalid extend should throw', async t => { |
| 31 | + const back = chdir('fixtures/extends-invalid'); |
| 32 | + t.throws(getConfiguration(), Error); |
| 33 | + back(); |
| 34 | +}); |
| 35 | + |
| 36 | +test('empty file should have no rules', async t => { |
| 37 | + const back = chdir('fixtures/empty-object-file'); |
| 38 | + const actual = await getConfiguration(); |
| 39 | + expect(actual.rules, 'to equal', {}); |
| 40 | + back(); |
| 41 | +}); |
| 42 | + |
| 43 | +test('empty file should extend angular', async t => { |
| 44 | + const back = chdir('fixtures/empty-file'); |
| 45 | + const actual = await getConfiguration(); |
| 46 | + expect(actual.extends, 'to equal', ['angular']); |
| 47 | + back(); |
| 48 | +}); |
| 49 | + |
| 50 | +function chdir(target) { |
| 51 | + const to = path.resolve(cwd, target.split('/').join(path.sep)); |
| 52 | + process.chdir(to); |
| 53 | + return () => process.chdir(cwd); |
| 54 | +} |
0 commit comments