{"size": 2709, "ext": "js", "max_stars_repo_path": "test.js", "max_stars_repo_name": "ember-cli/ember-cli-jshint", "max_stars_repo_stars_event_min_datetime": "2016-04-11T13:47:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T07:40:46.000Z", "max_issues_repo_path": "test.js", "max_issues_repo_name": "ember-cli/ember-cli-jshint", "max_issues_repo_issues_event_min_datetime": "2016-04-28T16:57:43.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-26T12:29:25.000Z", "max_forks_repo_path": "test.js", "max_forks_repo_name": "ember-cli/ember-cli-jshint", "max_forks_repo_forks_event_min_datetime": "2016-05-10T22:09:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T11:19:33.000Z"}
{"max_stars_count": 6, "max_issues_count": 17, "max_forks_count": 8, "avg_line_length": 43.6935483871, "max_line_length": 105, "alphanum_fraction": 0.6415651532}
var fs = require('fs-extra');
var exec = require('child_process').exec;
var Promise = require('es6-promise').Promise;

var expect = require('chai').expect;

var FAILING_FILE = __dirname + '/tests/dummy/app/unused.js';

describe('ember-cli-jshint', function() {
  this.timeout(60000);

  afterEach(function() {
    fs.removeSync(FAILING_FILE);
  });

  it('passes if JSHint tests pass', function() {
    return emberTest().then(function(result) {
      expect(result.error).to.not.exist;
      expect(result.stdout.match(/[^\r\n]+/g))
        .to.contain('ok 1 PhantomJS 2.1 - JSHint | app.js: should pass jshint')
        .to.contain('ok 2 PhantomJS 2.1 - JSHint | helpers/destroy-app.js: should pass jshint')
        .to.contain('ok 3 PhantomJS 2.1 - JSHint | helpers/module-for-acceptance.js: should pass jshint')
        .to.contain('ok 4 PhantomJS 2.1 - JSHint | helpers/resolver.js: should pass jshint')
        .to.contain('ok 5 PhantomJS 2.1 - JSHint | helpers/start-app.js: should pass jshint')
        .to.contain('ok 6 PhantomJS 2.1 - JSHint | resolver.js: should pass jshint')
        .to.contain('ok 7 PhantomJS 2.1 - JSHint | router.js: should pass jshint')
        .to.contain('ok 8 PhantomJS 2.1 - JSHint | test-helper.js: should pass jshint')
        .to.not.contain('not ok 9 PhantomJS 2.1 - JSHint | unused.js: should pass jshint');
    })
  });

  it('fails if a JSHint tests fails', function() {
    fs.outputFileSync(FAILING_FILE, 'let unused = 6;\n');

    return emberTest().then(function(result) {
      expect(result.error).to.exist;
      expect(result.stdout.match(/[^\r\n]+/g))
        .to.contain('ok 1 PhantomJS 2.1 - JSHint | app.js: should pass jshint')
        .to.contain('ok 2 PhantomJS 2.1 - JSHint | helpers/destroy-app.js: should pass jshint')
        .to.contain('ok 3 PhantomJS 2.1 - JSHint | helpers/module-for-acceptance.js: should pass jshint')
        .to.contain('ok 4 PhantomJS 2.1 - JSHint | helpers/resolver.js: should pass jshint')
        .to.contain('ok 5 PhantomJS 2.1 - JSHint | helpers/start-app.js: should pass jshint')
        .to.contain('ok 6 PhantomJS 2.1 - JSHint | resolver.js: should pass jshint')
        .to.contain('ok 7 PhantomJS 2.1 - JSHint | router.js: should pass jshint')
        .to.contain('ok 8 PhantomJS 2.1 - JSHint | test-helper.js: should pass jshint')
        .to.contain('not ok 9 PhantomJS 2.1 - JSHint | unused.js: should pass jshint');
    })
  });
});

function emberTest() {
  return new Promise(function(resolve) {
    exec('node_modules/.bin/ember test', { cwd: __dirname }, function (error, stdout, stderr) {
      resolve({
        error: error,
        stdout: stdout,
        stderr: stderr,
      });
    });
  });
}
