UNPKG

998 BJavaScriptView Raw
1const spawn = require('./__helpers__/spawn');
2const path = require('path');
3
4const bin = (command) => path.relative(process.cwd(), path.join(__dirname, '..', 'bin', command));
5const fixture = (name) => path.relative(process.cwd(), path.join(__dirname, '__fixtures__', name));
6
7const 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
22testCommand(`prettier-package-json ${fixture('package-1.json')}`);
23testCommand(`prettier-package-json --use-tabs ${fixture('package-1.json')}`);
24testCommand(`prettier-package-json --tab-width 8 ${fixture('package-1.json')}`);
25testCommand(`prettier-package-json ${fixture('package-*.json')}`);
26testCommand(`prettier-package-json --list-different ${fixture('package-*.json')}`);