<commit_before>var helper = require('./helper');
var Compiler = require('../lib/compiler');
var tsc = require('../lib/tsc');
var sinon = require('sinon');
var File = require('gulp-util').File;
var fs = require('fs');

describe('Compiler', function () {

  beforeEach(function () {
    this.sinon = sinon.sandbox.create();
  });

  afterEach(function () {
    this.sinon.restore();
  });

  describe('#getVersion', function () {
    it('returns the version of tsc', function (done) {
      this.sinon.stub(tsc, 'version').callsArgWith(1, null, '1.2.3');

      var compiler = new Compiler();
      compiler.getVersion(function (err, version) {
        if (err) return done(err);
        version.should.equal('1.2.3');
        done();
      });
    });
  });

  describe('#addSourceFile', function () {
    it('adds a source file and an output file for it', function () {
      var sourceFile = new File({ cwd: '/', path: '/test.ts' });

      var compiler = new Compiler();
      compiler.addSourceFile(sourceFile);

      compiler.sourceFiles.should.have.length(1);
      compiler.sourceFiles[0].path.should.equal('/test.ts');

      compiler.outputFiles.should.have.length(1);
      compiler.outputFiles[0].path.should.equal('/test.js');
    });

    it('adds also .map and .d.ts files when required', function () {
      var sourceFile = new File({ cwd: '/', path: '/test.ts' });

      var compiler = new Compiler({ sourcemap: true, declaration: true });
      compiler.addSourceFile(sourceFile);

      compiler.outputFiles.should.have.length(3);
      compiler.outputFiles[0].path.should.equal('/test.js');
      compiler.outputFiles[1].path.should.equal('/test.d.ts');
      compiler.outputFiles[2].path.should.equal('/test.js.map');
    });
  });

  describe('#compile', function () {
    it('executes tsc command', function (done) {
      var proc = helper.createDummyProcess();
      this.sinon.stub(tsc, 'exec').returns(proc);

      var compiler = new Compiler();
      compiler.compile(function (err) {
        if (err) return done(err);

        tsc.exec.calledOnce.should.be.true;
        var args = tsc.exec.args[0];
        args[0].should.eql(['--module', 'commonjs', '--target', 'ES3']);

        done();
      });

      proc.terminate(0);
    });
<commit_msg>Add spec for adding .d.ts file as a source file<commit_after>var helper = require('./helper');
var Compiler = require('../lib/compiler');
var tsc = require('../lib/tsc');
var sinon = require('sinon');
var File = require('gulp-util').File;
var fs = require('fs');

describe('Compiler', function () {

  beforeEach(function () {
    this.sinon = sinon.sandbox.create();
  });

  afterEach(function () {
    this.sinon.restore();
  });

  describe('#getVersion', function () {
    it('returns the version of tsc', function (done) {
      this.sinon.stub(tsc, 'version').callsArgWith(1, null, '1.2.3');

      var compiler = new Compiler();
      compiler.getVersion(function (err, version) {
        if (err) return done(err);
        version.should.equal('1.2.3');
        done();
      });
    });
  });

  describe('#addSourceFile', function () {
    it('adds a source file and an output file for it', function () {
      var sourceFile = new File({ cwd: '/', path: '/test.ts' });

      var compiler = new Compiler();
      compiler.addSourceFile(sourceFile);

      compiler.sourceFiles.should.have.length(1);
      compiler.sourceFiles[0].path.should.equal('/test.ts');

      compiler.outputFiles.should.have.length(1);
      compiler.outputFiles[0].path.should.equal('/test.js');
    });

    it('adds also .map and .d.ts files when required', function () {
      var sourceFile = new File({ cwd: '/', path: '/test.ts' });

      var compiler = new Compiler({ sourcemap: true, declaration: true });
      compiler.addSourceFile(sourceFile);

      compiler.outputFiles.should.have.length(3);
      compiler.outputFiles[0].path.should.equal('/test.js');
      compiler.outputFiles[1].path.should.equal('/test.d.ts');
      compiler.outputFiles[2].path.should.equal('/test.js.map');
    });

    it('never adds an output file for .d.ts file', function () {
      var sourceFile = new File({ cwd: '/', path: '/test.d.ts' });

      var compiler = new Compiler();
      compiler.addSourceFile(sourceFile);

      compiler.outputFiles.should.be.empty;
    });
  });

  describe('#compile', function () {
    it('executes tsc command', function (done) {
      var proc = helper.createDummyProcess();
      this.sinon.stub(tsc, 'exec').returns(proc);

      var compiler = new Compiler();
      compiler.compile(function (err) {
        if (err) return done(err);

        tsc.exec.calledOnce.should.be.true;
        var args = tsc.exec.args[0];
        args[0].should.eql(['--module', 'commonjs', '--target', 'ES3']);

        done();
      });

      proc.terminate(0);
    });

{'fraction_non_alphanumeric': 0.18245469522240526, 'fraction_numerical': 0.007825370675453048, 'mean_word_length': 2.9264349232012936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7281880', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1501, 'n_words': 313}