|
| 1 | +import {npm} from '@commitlint/test'; |
| 2 | +import config from '.'; |
| 3 | + |
| 4 | +test('exports rules key', () => { |
| 5 | + expect(config).toHaveProperty('rules'); |
| 6 | +}); |
| 7 | + |
| 8 | +test('rules hold object', () => { |
| 9 | + expect(config).toMatchObject({ |
| 10 | + rules: expect.any(Object), |
| 11 | + }); |
| 12 | +}); |
| 13 | + |
| 14 | +test('rules contain scope-enum', () => { |
| 15 | + expect(config).toMatchObject({ |
| 16 | + rules: { |
| 17 | + 'scope-enum': expect.anything(), |
| 18 | + }, |
| 19 | + }); |
| 20 | +}); |
| 21 | + |
| 22 | +test('scope-enum is function', () => { |
| 23 | + expect(config).toMatchObject({ |
| 24 | + rules: { |
| 25 | + 'scope-enum': expect.any(Function), |
| 26 | + }, |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +test('scope-enum does not throw for missing context', async () => { |
| 31 | + const {'scope-enum': fn} = config.rules; |
| 32 | + await expect(fn()).resolves.toBeTruthy(); |
| 33 | +}); |
| 34 | + |
| 35 | +test('scope-enum has expected severity', async () => { |
| 36 | + const {'scope-enum': fn} = config.rules; |
| 37 | + const [severity] = await fn(); |
| 38 | + expect(severity).toBe(2); |
| 39 | +}); |
| 40 | + |
| 41 | +test('scope-enum has expected modifier', async () => { |
| 42 | + const {'scope-enum': fn} = config.rules; |
| 43 | + const [, modifier] = await fn(); |
| 44 | + expect(modifier).toBe('always'); |
| 45 | +}); |
| 46 | + |
| 47 | +test('returns empty value for empty pnpm repository', async () => { |
| 48 | + const {'scope-enum': fn} = config.rules; |
| 49 | + const cwd = await npm.bootstrap('fixtures/empty', __dirname); |
| 50 | + const [, , value] = await fn({cwd}); |
| 51 | + expect(value).toEqual([]); |
| 52 | +}); |
| 53 | + |
| 54 | +test('returns expected value for basic pnpm repository', async () => { |
| 55 | + const {'scope-enum': fn} = config.rules; |
| 56 | + const cwd = await npm.bootstrap('fixtures/basic', __dirname); |
| 57 | + |
| 58 | + const [, , value] = await fn({cwd}); |
| 59 | + expect(value).toEqual(['a', 'b']); |
| 60 | +}); |
| 61 | + |
| 62 | +test('returns expected value for scoped pnpm repository', async () => { |
| 63 | + const {'scope-enum': fn} = config.rules; |
| 64 | + const cwd = await npm.bootstrap('fixtures/scoped', __dirname); |
| 65 | + |
| 66 | + const [, , value] = await fn({cwd}); |
| 67 | + |
| 68 | + expect(value).toEqual(['a', 'b']); |
| 69 | +}); |
0 commit comments