var chai = require("chai")
var spies = require("chai-spies");
var path = require("path");
var compiler = require(path.join(__dirname, ".."));

chai.use(spies);

var expect = chai.expect;

var fixturesDir = path.join(__dirname, "fixtures");

function prependFixturesDir(filename) {
  return path.join(fixturesDir, filename);
}

describe("#compileSync", function() {
  // Use a timeout of 5 minutes because Travis on Linux can be SUPER slow.
  this.timeout(300000);

  it("works with --yes", function () {
    var opts = {yes: true, output: "/dev/null", verbose: true, cwd: fixturesDir};
    var compileProcess = compiler.compileSync(prependFixturesDir("Parent.elm"), opts);

    expect(compileProcess.status, "Expected elm-make to have exit code 0").to.equal(0);
  });

  it("reports errors on bad source", function () {
    var opts = {
      yes: true,
      verbose: true,
      cwd: fixturesDir
    };
    var compileProcess = compiler.compileSync(prependFixturesDir("Bad.elm"), opts);

    var exitCode = compileProcess.status;
    var desc = "Expected elm-make to have exit code 1";
    expect(exitCode, desc).to.equal(1);
  });

  it("invokes custom `emitWarning`", function () {
    var opts = {
      foo: "bar",
      emitWarning: chai.spy(),
      yes: true,
      output: "/dev/null",
      verbose: true,
      cwd: fixturesDir
    };
    var compileProcess = compiler.compileSync(prependFixturesDir("Parent.elm"), opts);

    var desc = "Expected emitWarning to have been called";
    expect(opts.emitWarning, desc).to.have.been.called();
  });
});

@@ -24,43 +24,8 @@
 i%22)%0A
-var spies = require(%22chai-spies%22);%0A
 var 
@@ -105,26 +105,8 @@
 );%0A%0A
-chai.use(spies);%0A%0A
 var 

remove useless chai-spies