|
| 1 | +import { getUntidyManifest } from '../../../test/fixtures'; |
| 2 | +import { shuffleObject } from '../../../test/helpers'; |
| 3 | +import { SORT_FIRST } from '../../constants'; |
| 4 | +import { IManifest } from '../../typings'; |
| 5 | +import { manifestData } from './index'; |
| 6 | + |
| 7 | +describe('format', () => { |
| 8 | + let results: IManifest[]; |
| 9 | + beforeAll(() => { |
| 10 | + results = manifestData.format([shuffleObject(getUntidyManifest()) as IManifest]); |
| 11 | + }); |
| 12 | + |
| 13 | + it('sorts specified keys to the top of package.json', () => { |
| 14 | + results.forEach((result) => { |
| 15 | + expect(Object.keys(result).slice(0, SORT_FIRST.length)).toEqual(SORT_FIRST); |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + it('sorts remaining keys alphabetically', () => { |
| 20 | + results.forEach((result) => { |
| 21 | + expect(Object.keys(result).slice(SORT_FIRST.length - 1)).toEqual([ |
| 22 | + 'author', |
| 23 | + 'bin', |
| 24 | + 'bugs', |
| 25 | + 'dependencies', |
| 26 | + 'devDependencies', |
| 27 | + 'files', |
| 28 | + 'homepage', |
| 29 | + 'keywords', |
| 30 | + 'license', |
| 31 | + 'main', |
| 32 | + 'peerDependencies', |
| 33 | + 'repository', |
| 34 | + 'scripts' |
| 35 | + ]); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('sorts "dependencies" alphabetically', () => { |
| 40 | + results.forEach((result) => { |
| 41 | + expect(result.dependencies).toEqual({ |
| 42 | + arnold: '5.0.0', |
| 43 | + dog: '2.13.0', |
| 44 | + guybrush: '7.1.1', |
| 45 | + mango: '2.3.0' |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + it('sorts "devDependencies" alphabetically', () => { |
| 51 | + results.forEach((result) => { |
| 52 | + expect(result.devDependencies).toEqual({ stroopwafel: '4.4.2', waldorf: '22.1.4' }); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('sorts "files" alphabetically', () => { |
| 57 | + results.forEach((result) => { |
| 58 | + expect(result.files).toEqual(['assets', 'dist']); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it('sorts "keywords" alphabetically', () => { |
| 63 | + results.forEach((result) => { |
| 64 | + expect(result.keywords).toEqual(['thing', 'those', 'whatsits']); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('sorts "peerDependencies" alphabetically', () => { |
| 69 | + results.forEach((result) => { |
| 70 | + expect(result.peerDependencies).toEqual({ giftwrap: '0.1.2', jambalaya: '6.1.4', zoolander: '1.4.25' }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + it('sorts "scripts" alphabetically', () => { |
| 75 | + results.forEach((result) => { |
| 76 | + expect(result.scripts).toEqual({ build: 'tsc', format: 'prettier', lint: 'tslint', test: 'jest' }); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + it('uses shorthand "bugs"', () => { |
| 81 | + results.forEach((result) => { |
| 82 | + expect(result.bugs).toEqual('https://github.com/JaneDoe/do-it/issues'); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + it('uses shorthand "repository"', () => { |
| 87 | + results.forEach((result) => { |
| 88 | + expect(result.repository).toEqual('JaneDoe/do-it'); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments