Use find -type f to get a list of output files
This commit is contained in:
@@ -4,29 +4,25 @@ require('chai').should()
|
||||
modulePath = require('path').join __dirname, '../../../app/js/OutputFileFinder'
|
||||
path = require "path"
|
||||
expect = require("chai").expect
|
||||
EventEmitter = require("events").EventEmitter
|
||||
|
||||
describe "OutputFileFinder", ->
|
||||
beforeEach ->
|
||||
@OutputFileFinder = SandboxedModule.require modulePath, requires:
|
||||
"fs": @fs = {}
|
||||
"wrench": @wrench = {}
|
||||
"child_process": spawn: @spawn = sinon.stub()
|
||||
@directory = "/test/dir"
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "findOutputFiles", ->
|
||||
beforeEach ->
|
||||
@resource_path = "resource/path.tex"
|
||||
@output_paths = ["output.pdf", "extra", "extra/file.tex"]
|
||||
@output_paths = ["output.pdf", "extra/file.tex"]
|
||||
@all_paths = @output_paths.concat [@resource_path]
|
||||
@resources = [
|
||||
path: @resource_path = "resource/path.tex"
|
||||
]
|
||||
@OutputFileFinder._isDirectory = (dirPath, callback = (error, directory) ->) =>
|
||||
callback null, dirPath == path.join(@directory, "extra")
|
||||
|
||||
@wrench.readdirRecursive = (dir, callback) =>
|
||||
callback(null, [@resource_path].concat(@output_paths))
|
||||
callback(null, null)
|
||||
sinon.spy @wrench, "readdirRecursive"
|
||||
@OutputFileFinder._getAllFiles = sinon.stub().callsArgWith(1, null, @all_paths)
|
||||
@OutputFileFinder.findOutputFiles @resources, @directory, (error, @outputFiles) =>
|
||||
|
||||
it "should only return the output files, not directories or resource paths", ->
|
||||
@@ -37,5 +33,24 @@ describe "OutputFileFinder", ->
|
||||
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
|
||||
|
||||
@proc.stdout.emit(
|
||||
"data",
|
||||
["/base/dir/main.tex", "/base/dir/chapters/chapter1.tex"].join("\n") + "\n"
|
||||
)
|
||||
@proc.emit "close", 0
|
||||
|
||||
it "should call the callback with the relative file paths", ->
|
||||
@callback.calledWith(
|
||||
null,
|
||||
["main.tex", "chapters/chapter1.tex"]
|
||||
).should.equal true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user