2020-02-19 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
2024-11-08 05:21:56 -05:00
|
|
|
const modulePath = require('node:path').join(
|
2020-02-19 06:15:37 -05:00
|
|
|
__dirname,
|
|
|
|
'../../../app/js/OutputFileFinder'
|
|
|
|
)
|
|
|
|
const { expect } = require('chai')
|
2024-01-10 07:02:06 -05:00
|
|
|
const mockFs = require('mock-fs')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('OutputFileFinder', function () {
|
|
|
|
beforeEach(function () {
|
2024-01-10 07:02:06 -05:00
|
|
|
this.OutputFileFinder = SandboxedModule.require(modulePath, {})
|
|
|
|
this.directory = '/test/dir'
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
|
|
|
|
mockFs({
|
|
|
|
[this.directory]: {
|
|
|
|
resource: {
|
|
|
|
'path.tex': 'a source file',
|
|
|
|
},
|
|
|
|
'output.pdf': 'a generated pdf file',
|
|
|
|
extra: {
|
|
|
|
'file.tex': 'a generated tex file',
|
|
|
|
},
|
|
|
|
'sneaky-file': mockFs.symlink({
|
|
|
|
path: '../foo',
|
|
|
|
}),
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2024-01-10 07:02:06 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
mockFs.restore()
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('findOutputFiles', function () {
|
2024-01-10 07:02:06 -05:00
|
|
|
beforeEach(async 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') }]
|
2024-01-10 07:02:06 -05:00
|
|
|
const { outputFiles, allEntries } =
|
|
|
|
await this.OutputFileFinder.promises.findOutputFiles(
|
|
|
|
this.resources,
|
|
|
|
this.directory
|
|
|
|
)
|
|
|
|
this.outputFiles = outputFiles
|
|
|
|
this.allEntries = allEntries
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2024-01-10 07:02:06 -05:00
|
|
|
it('should only return the output files, not directories or resource paths', function () {
|
|
|
|
expect(this.outputFiles).to.have.deep.members([
|
2020-02-19 06:15:37 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
])
|
2024-01-10 07:02:06 -05:00
|
|
|
expect(this.allEntries).to.deep.equal([
|
|
|
|
'extra/file.tex',
|
|
|
|
'extra/',
|
|
|
|
'output.pdf',
|
|
|
|
'resource/path.tex',
|
|
|
|
'resource/',
|
|
|
|
'sneaky-file',
|
|
|
|
])
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|