|
| 1 | +const test = require('ava'); |
| 2 | +const prettier = require('prettier'); |
| 3 | + |
| 4 | +test('default', (t) => { |
| 5 | + const options = { |
| 6 | + filepath: 'package.json', |
| 7 | + parser: 'json-stringify', |
| 8 | + plugins: ['.'] |
| 9 | + }; |
| 10 | + const fixture = { |
| 11 | + engines: { |
| 12 | + npm: 'joker', |
| 13 | + node: 'batman' |
| 14 | + } |
| 15 | + }; |
| 16 | + |
| 17 | + const input = JSON.stringify(fixture, null, 2); |
| 18 | + const output = prettier.format(input, options); |
| 19 | + |
| 20 | + t.snapshot(output); |
| 21 | +}); |
| 22 | + |
| 23 | +test('enginesNode', (t) => { |
| 24 | + const options = { |
| 25 | + enginesNode: '>= batcave', |
| 26 | + filepath: 'package.json', |
| 27 | + parser: 'json-stringify', |
| 28 | + plugins: ['.'] |
| 29 | + }; |
| 30 | + const fixture = { |
| 31 | + engines: { |
| 32 | + npm: 'joker', |
| 33 | + node: 'batman' |
| 34 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + const input = JSON.stringify(fixture, null, 2); |
| 38 | + const output = prettier.format(input, options); |
| 39 | + |
| 40 | + t.snapshot(output); |
| 41 | +}); |
| 42 | + |
| 43 | +test('enginesNpm', (t) => { |
| 44 | + const options = { |
| 45 | + enginesNpm: '>= harley', |
| 46 | + filepath: 'package.json', |
| 47 | + parser: 'json-stringify', |
| 48 | + plugins: ['.'] |
| 49 | + }; |
| 50 | + const fixture = { |
| 51 | + engines: { |
| 52 | + npm: 'joker', |
| 53 | + node: 'batman' |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + const input = JSON.stringify(fixture, null, 2); |
| 58 | + const output = prettier.format(input, options); |
| 59 | + |
| 60 | + t.snapshot(output); |
| 61 | +}); |
| 62 | + |
| 63 | +test('missing', (t) => { |
| 64 | + const options = { |
| 65 | + enginesNode: '>= batcave', |
| 66 | + enginesNpm: '>= harley', |
| 67 | + filepath: 'package.json', |
| 68 | + parser: 'json-stringify', |
| 69 | + plugins: ['.'] |
| 70 | + }; |
| 71 | + const fixture = { |
| 72 | + engines: {} |
| 73 | + }; |
| 74 | + |
| 75 | + const input = JSON.stringify(fixture, null, 2); |
| 76 | + const output = prettier.format(input, options); |
| 77 | + |
| 78 | + t.snapshot(output); |
| 79 | +}); |
0 commit comments