1 | const spawn = require('./__helpers__/spawn');
|
2 | const path = require('path');
|
3 |
|
4 | const bin = (command) => path.relative(process.cwd(), path.join(__dirname, '..', 'bin', command));
|
5 | const fixture = (name) => path.relative(process.cwd(), path.join(__dirname, '__fixtures__', name));
|
6 |
|
7 | const testCommand = (cmdline, cb) => {
|
8 | const [command, ...args] = cmdline.split(' ');
|
9 |
|
10 | test(`${command} ${args.join(' ')}`, () => {
|
11 | !cb && expect.assertions(1);
|
12 | return spawn(bin(command), args).then((result) => {
|
13 | if (cb) {
|
14 | cb(result);
|
15 | } else {
|
16 | expect(result).toMatchSnapshot();
|
17 | }
|
18 | });
|
19 | });
|
20 | };
|
21 |
|
22 | testCommand(`prettier-package-json ${fixture('package-1.json')}`);
|
23 | testCommand(`prettier-package-json --use-tabs ${fixture('package-1.json')}`);
|
24 | testCommand(`prettier-package-json --tab-width 8 ${fixture('package-1.json')}`);
|
25 | testCommand(`prettier-package-json ${fixture('package-*.json')}`);
|
26 | testCommand(`prettier-package-json --list-different ${fixture('package-*.json')}`);
|