add unit test
This commit is contained in:
@@ -144,14 +144,12 @@ module.exports = CompileManager =
|
|||||||
wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) ->
|
wordcount: (project_id, file_name, callback = (error, pdfPositions) ->) ->
|
||||||
base_dir = Settings.path.synctexBaseDir(project_id)
|
base_dir = Settings.path.synctexBaseDir(project_id)
|
||||||
file_path = base_dir + "/" + file_name
|
file_path = base_dir + "/" + file_name
|
||||||
logger.log project_id: project_id, file_name: file_name, "try wordcount"
|
|
||||||
CompileManager._runWordcount [file_path], (error, stdout) ->
|
CompileManager._runWordcount [file_path], (error, stdout) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
logger.log project_id: project_id, file_name: file_name, stdout: stdout, "wordcount output"
|
logger.log project_id: project_id, file_name: file_name, stdout: stdout, "wordcount output"
|
||||||
callback null, CompileManager._parseWordcountFromOutput(stdout)
|
callback null, CompileManager._parseWordcountFromOutput(stdout)
|
||||||
|
|
||||||
_runWordcount: (args, callback = (error, stdout) ->) ->
|
_runWordcount: (args, callback = (error, stdout) ->) ->
|
||||||
bin_path = Path.resolve("texcount")
|
|
||||||
seconds = 1000
|
seconds = 1000
|
||||||
child_process.execFile "texcount", args, timeout: 10 * seconds, (error, stdout, stderr) ->
|
child_process.execFile "texcount", args, timeout: 10 * seconds, (error, stdout, stderr) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
|||||||
@@ -189,3 +189,27 @@ describe "CompileController", ->
|
|||||||
)
|
)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "wordcount", ->
|
||||||
|
beforeEach ->
|
||||||
|
@file = "main.tex"
|
||||||
|
@project_id = "mock-project-id"
|
||||||
|
@req.params =
|
||||||
|
project_id: @project_id
|
||||||
|
@req.query =
|
||||||
|
file: @file
|
||||||
|
@res.send = sinon.stub()
|
||||||
|
|
||||||
|
@CompileManager.wordcount = sinon.stub().callsArgWith(2, null, @texcount = ["mock-texcount"])
|
||||||
|
@CompileController.wordcount @req, @res, @next
|
||||||
|
|
||||||
|
it "should return the word count of a file", ->
|
||||||
|
@CompileManager.wordcount
|
||||||
|
.calledWith(@project_id, @file)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should return the texcount info", ->
|
||||||
|
@res.send
|
||||||
|
.calledWith(JSON.stringify
|
||||||
|
texcount: @texcount
|
||||||
|
)
|
||||||
|
.should.equal true
|
||||||
|
|||||||
@@ -172,3 +172,32 @@ describe "CompileManager", ->
|
|||||||
column: @column
|
column: @column
|
||||||
}])
|
}])
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "wordcount", ->
|
||||||
|
beforeEach ->
|
||||||
|
@file_name = "main.tex"
|
||||||
|
@child_process.execFile = sinon.stub()
|
||||||
|
@child_process.execFile.callsArgWith(3, null, @stdout = "Encoding: ascii\nWords in text: 2", "")
|
||||||
|
@Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}"
|
||||||
|
@CompileManager.wordcount @project_id, @file_name, @callback
|
||||||
|
|
||||||
|
it "should execute the texcount binary", ->
|
||||||
|
file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}"
|
||||||
|
@child_process.execFile
|
||||||
|
.calledWith("texcount", [file_path], timeout: 10000)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback with the parsed output", ->
|
||||||
|
@callback
|
||||||
|
.calledWith(null, {
|
||||||
|
encode: "ascii"
|
||||||
|
textWords: 2
|
||||||
|
headWords: 0
|
||||||
|
outside: 0
|
||||||
|
headers: 0
|
||||||
|
elements: 0
|
||||||
|
mathInline: 0
|
||||||
|
mathDisplay: 0
|
||||||
|
})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user