decaffeinate: Convert CompileControllerTests.coffee and 17 other files to JS

This commit is contained in:
decaffeinate
2020-02-19 12:15:08 +01:00
committed by mserranom
parent 18e6b4715d
commit 79a0891fee
18 changed files with 3291 additions and 2401 deletions

View File

@@ -1,68 +1,92 @@
SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
require('chai').should()
modulePath = require('path').join __dirname, '../../../app/js/OutputFileFinder'
path = require "path"
expect = require("chai").expect
EventEmitter = require("events").EventEmitter
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const SandboxedModule = require('sandboxed-module');
const sinon = require('sinon');
require('chai').should();
const modulePath = require('path').join(__dirname, '../../../app/js/OutputFileFinder');
const path = require("path");
const { expect } = require("chai");
const { EventEmitter } = require("events");
describe "OutputFileFinder", ->
beforeEach ->
@OutputFileFinder = SandboxedModule.require modulePath, requires:
"fs": @fs = {}
"child_process": spawn: @spawn = sinon.stub()
describe("OutputFileFinder", function() {
beforeEach(function() {
this.OutputFileFinder = SandboxedModule.require(modulePath, { requires: {
"fs": (this.fs = {}),
"child_process": { spawn: (this.spawn = sinon.stub())
},
"logger-sharelatex": { log: sinon.stub(), warn: sinon.stub() }
@directory = "/test/dir"
@callback = sinon.stub()
}
});
this.directory = "/test/dir";
return this.callback = sinon.stub();
});
describe "findOutputFiles", ->
beforeEach ->
@resource_path = "resource/path.tex"
@output_paths = ["output.pdf", "extra/file.tex"]
@all_paths = @output_paths.concat [@resource_path]
@resources = [
path: @resource_path = "resource/path.tex"
]
@OutputFileFinder._getAllFiles = sinon.stub().callsArgWith(1, null, @all_paths)
@OutputFileFinder.findOutputFiles @resources, @directory, (error, @outputFiles) =>
describe("findOutputFiles", function() {
beforeEach(function() {
this.resource_path = "resource/path.tex";
this.output_paths = ["output.pdf", "extra/file.tex"];
this.all_paths = this.output_paths.concat([this.resource_path]);
this.resources = [
{path: (this.resource_path = "resource/path.tex")}
];
this.OutputFileFinder._getAllFiles = sinon.stub().callsArgWith(1, null, this.all_paths);
return this.OutputFileFinder.findOutputFiles(this.resources, this.directory, (error, outputFiles) => {
this.outputFiles = outputFiles;
});
});
it "should only return the output files, not directories or resource paths", ->
expect(@outputFiles).to.deep.equal [{
path: "output.pdf"
return it("should only return the output files, not directories or resource paths", function() {
return expect(this.outputFiles).to.deep.equal([{
path: "output.pdf",
type: "pdf"
}, {
path: "extra/file.tex",
type: "tex"
}]
}]);
});
});
describe "_getAllFiles", ->
beforeEach ->
@proc = new EventEmitter()
@proc.stdout = new EventEmitter()
@spawn.returns @proc
@directory = "/base/dir"
@OutputFileFinder._getAllFiles @directory, @callback
return describe("_getAllFiles", function() {
beforeEach(function() {
this.proc = new EventEmitter();
this.proc.stdout = new EventEmitter();
this.spawn.returns(this.proc);
this.directory = "/base/dir";
return this.OutputFileFinder._getAllFiles(this.directory, this.callback);
});
describe "successfully", ->
beforeEach ->
@proc.stdout.emit(
describe("successfully", function() {
beforeEach(function() {
this.proc.stdout.emit(
"data",
["/base/dir/main.tex", "/base/dir/chapters/chapter1.tex"].join("\n") + "\n"
)
@proc.emit "close", 0
);
return this.proc.emit("close", 0);
});
it "should call the callback with the relative file paths", ->
@callback.calledWith(
return it("should call the callback with the relative file paths", function() {
return this.callback.calledWith(
null,
["main.tex", "chapters/chapter1.tex"]
).should.equal true
).should.equal(true);
});
});
describe "when the directory doesn't exist", ->
beforeEach ->
@proc.emit "close", 1
return describe("when the directory doesn't exist", function() {
beforeEach(function() {
return this.proc.emit("close", 1);
});
it "should call the callback with a blank array", ->
@callback.calledWith(
return it("should call the callback with a blank array", function() {
return this.callback.calledWith(
null,
[]
).should.equal true
).should.equal(true);
});
});
});
});