/* global describe, it */

import 'should';
import fs from 'fs';
import path from 'path';
import cli from '../src/cli';

function makeArgv(testCase) {
  const options = testCase.options;
  const testPath = path.resolve('test/fake_modules/' + testCase.module);
  const argv = [testPath, '--json'];

  if (options.withoutDev) {
    argv.push('--dev=false');
  }

  if (options.ignoreMatches) {
    argv.push('--ignores=' + options.ignoreMatches.join(','));
  }

  return argv;
}

describe('depcheck command line', () => {
  const spec = fs.readFileSync(__dirname + '/spec.json', { encoding: 'utf8' });
  const testCases = JSON.parse(spec);

  testCases.forEach(testCase => {
    if (testCase.name === 'ignore ignoreDirs') {
      // TODO command line not supports ignoreDirs options yet, skip it
      return true;
    }

    it('should ' + testCase.name, () =>
      new Promise(resolve => {
        let log;

        cli(
          makeArgv(testCase),
          data => log = data,
          data => data.should.fail(), // should not go into error log
          exitCode => resolve({ log, exitCode })
        );
      }).then(({ log, exitCode }) => {
        const actual = JSON.parse(log);
        const expected = testCase.expected;

        actual.dependencies.should.eql(expected.dependencies);
        actual.devDependencies.should.eql(expected.devDependencies);

        exitCode.should.equal(0); // JSON output always return 0
      }));
  });
});

@@ -1443,13 +1443,612 @@
 );%0A  %7D);
+%0A%0A  it('should output help message', () =%3E%0A    new Promise(resolve =%3E %7B%0A      let help;%0A%0A      cli(%0A        %5B'--help'%5D,%0A        data =%3E help = data,%0A        data =%3E data.should.fail(), // should not go into error log%0A        exitCode =%3E resolve(%7B help, exitCode %7D)%0A      );%0A    %7D).then((%7B help, exitCode %7D) =%3E %7B%0A      const helpDocs = help.split('%5Cn').map(x =%3E x.trim()).filter(x =%3E x);%0A      const options = %5B'--help', '--json', '--dev', '--ignores'%5D;%0A%0A      options.forEach(option =%3E%0A        helpDocs.some(doc =%3E doc.startsWith(option)).should.be.true());%0A%0A      exitCode.should.equal(0);%0A    %7D));
 %0A%7D);%0A

Add cli help message test case.