1 | const { format } = require('../src');
|
2 |
|
3 | test('It orders keys using the default key order', () => {
|
4 | const json = {
|
5 | description: 'Description',
|
6 | version: '0.0.0',
|
7 | name: 'Test'
|
8 | };
|
9 |
|
10 | expect(format(json)).toMatchSnapshot();
|
11 | });
|
12 |
|
13 | test('It orders keys using the specified key order', () => {
|
14 | const json = {
|
15 | description: 'Description',
|
16 | version: '0.0.0',
|
17 | name: 'Test'
|
18 | };
|
19 |
|
20 | expect(format(json, { keyOrder: ['name', 'version', 'description'] })).toMatchSnapshot();
|
21 | });
|
22 |
|
23 | test('It orders keys using a custom key order function', () => {
|
24 | const json = {
|
25 | description: 'Description',
|
26 | version: '0.0.0',
|
27 | name: 'Test'
|
28 | };
|
29 |
|
30 | const keyOrder = (keyA, keyB) => {
|
31 | if (keyA === keyB) {
|
32 | return 0;
|
33 | } else {
|
34 | return keyA < keyB ? -1 : 1;
|
35 | }
|
36 | };
|
37 |
|
38 | expect(format(json, { keyOrder })).toMatchSnapshot();
|
39 | });
|
40 |
|
41 | test('It orders scripts in alphabetical order, keeping pre and post scripts beside their counterparts', () => {
|
42 | const json = {
|
43 | scripts: {
|
44 | test: 'test',
|
45 | pretest: 'pretest',
|
46 | version: 'version',
|
47 | postversion: 'postversion',
|
48 | build: 'build'
|
49 | }
|
50 | };
|
51 |
|
52 | expect(format(json)).toMatchSnapshot();
|
53 | });
|