|
| 1 | +import {npm} from '@commitlint/test'; |
| 2 | +import test from 'ava'; |
| 3 | +import config from '.'; |
| 4 | + |
| 5 | +test('exports rules key', t => { |
| 6 | + t.true(Object.prototype.hasOwnProperty.call(config, 'rules')); |
| 7 | +}); |
| 8 | + |
| 9 | +test('rules hold object', t => { |
| 10 | + t.is(typeof config.rules, 'object'); |
| 11 | +}); |
| 12 | + |
| 13 | +test('rules contain scope-enum', t => { |
| 14 | + t.true(Object.prototype.hasOwnProperty.call(config.rules, 'scope-enum')); |
| 15 | +}); |
| 16 | + |
| 17 | +test('scope-enum is function', t => { |
| 18 | + const {'scope-enum': fn} = config.rules; |
| 19 | + t.is(typeof fn, 'function'); |
| 20 | +}); |
| 21 | + |
| 22 | +test('scope-enum does not throw for missing context', t => { |
| 23 | + const {'scope-enum': fn} = config.rules; |
| 24 | + t.notThrows(() => fn()); |
| 25 | +}); |
| 26 | + |
| 27 | +test('scope-enum has expected severity', t => { |
| 28 | + const {'scope-enum': fn} = config.rules; |
| 29 | + const [severity] = fn(); |
| 30 | + t.is(severity, 2); |
| 31 | +}); |
| 32 | + |
| 33 | +test('scope-enum has expected modifier', t => { |
| 34 | + const {'scope-enum': fn} = config.rules; |
| 35 | + const [, modifier] = fn(); |
| 36 | + t.is(modifier, 'always'); |
| 37 | +}); |
| 38 | + |
| 39 | +test('returns empty value for empty lerna repository', async t => { |
| 40 | + const {'scope-enum': fn} = config.rules; |
| 41 | + const cwd = await npm.bootstrap('fixtures/empty'); |
| 42 | + const [, , value] = fn({cwd}); |
| 43 | + t.deepEqual(value, []); |
| 44 | +}); |
| 45 | + |
| 46 | +test('returns expected value for basic lerna repository', async t => { |
| 47 | + const {'scope-enum': fn} = config.rules; |
| 48 | + const cwd = await npm.bootstrap('fixtures/basic'); |
| 49 | + const [, , value] = fn({cwd}); |
| 50 | + t.deepEqual(value, ['a', 'b']); |
| 51 | +}); |
| 52 | + |
| 53 | +test.failing( |
| 54 | + 'throws for repository with .lerna vs .devDependencies.lerna mismatch', |
| 55 | + async t => { |
| 56 | + const {'scope-enum': fn} = config.rules; |
| 57 | + const cwd = await npm.bootstrap('fixtures/version-mismatch'); |
| 58 | + await t.throws(() => fn({cwd})); |
| 59 | + } |
| 60 | +); |
| 61 | + |
| 62 | +test('returns expected value for scoped lerna repository', async t => { |
| 63 | + const {'scope-enum': fn} = config.rules; |
| 64 | + const cwd = await npm.bootstrap('fixtures/scoped'); |
| 65 | + const [, , value] = fn({cwd}); |
| 66 | + t.deepEqual(value, ['a', 'b']); |
| 67 | +}); |
| 68 | + |
| 69 | +test('works with lerna 2.0', async t => { |
| 70 | + const {'scope-enum': fn} = config.rules; |
| 71 | + const cwd = await npm.bootstrap('fixtures/lerna-2.4'); |
| 72 | + const [, , value] = fn({cwd}); |
| 73 | + t.deepEqual(value, ['a', 'b']); |
| 74 | +}); |
| 75 | + |
| 76 | +test('works with lerna 2.4', async t => { |
| 77 | + const {'scope-enum': fn} = config.rules; |
| 78 | + const cwd = await npm.bootstrap('fixtures/lerna-2.4'); |
| 79 | + const [, , value] = fn({cwd}); |
| 80 | + t.deepEqual(value, ['a', 'b']); |
| 81 | +}); |
0 commit comments