2020-02-19 06:15:25 -05:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 06:15:08 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-19 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/OutputFileFinder'
|
|
|
|
)
|
|
|
|
const path = require('path')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
const { EventEmitter } = require('events')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('OutputFileFinder', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.OutputFileFinder = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
fs: (this.fs = {}),
|
2021-07-13 07:04:48 -04:00
|
|
|
child_process: { spawn: (this.spawn = sinon.stub()) },
|
2020-12-18 10:16:46 -05:00
|
|
|
},
|
|
|
|
globals: {
|
2021-07-13 07:04:48 -04:00
|
|
|
Math, // used by lodash
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.directory = '/test/dir'
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('findOutputFiles', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should only return the output files, not directories or resource paths', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return expect(this.outputFiles).to.deep.equal([
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
2021-07-13 07:04:48 -04:00
|
|
|
type: 'pdf',
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'extra/file.tex',
|
2021-07-13 07:04:48 -04:00
|
|
|
type: 'tex',
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
2014-12-09 06:25:23 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('_getAllFiles', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.proc = new EventEmitter()
|
|
|
|
this.proc.stdout = new EventEmitter()
|
2020-05-07 05:30:14 -04:00
|
|
|
this.proc.stdout.setEncoding = sinon.stub().returns(this.proc.stdout)
|
2020-02-19 06:15:37 -05:00
|
|
|
this.spawn.returns(this.proc)
|
|
|
|
this.directory = '/base/dir'
|
|
|
|
return this.OutputFileFinder._getAllFiles(this.directory, this.callback)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('successfully', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.proc.stdout.emit(
|
|
|
|
'data',
|
|
|
|
['/base/dir/main.tex', '/base/dir/chapters/chapter1.tex'].join('\n') +
|
|
|
|
'\n'
|
|
|
|
)
|
|
|
|
return this.proc.emit('close', 0)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback with the relative file paths', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback
|
|
|
|
.calledWith(null, ['main.tex', 'chapters/chapter1.tex'])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe("when the directory doesn't exist", function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.proc.emit('close', 1)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should call the callback with a blank array', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.callback.calledWith(null, []).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|