overleaf/services/clsi/test/unit/js/OutputFileFinderTests.js
Jakob Ackermann 5aeb1f1459 Merge pull request #16438 from overleaf/jpa-em-replace-find-subprocess
[clsi] replace find subprocess for listing compile dir contents

GitOrigin-RevId: 36c8230ea6d787b1d948407d6473c14af8d6b5f6
2024-01-11 09:04:52 +00:00

72 lines
1.9 KiB
JavaScript

const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const modulePath = require('path').join(
__dirname,
'../../../app/js/OutputFileFinder'
)
const { expect } = require('chai')
const mockFs = require('mock-fs')
describe('OutputFileFinder', function () {
beforeEach(function () {
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',
}),
},
})
})
afterEach(function () {
mockFs.restore()
})
describe('findOutputFiles', function () {
beforeEach(async 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') }]
const { outputFiles, allEntries } =
await this.OutputFileFinder.promises.findOutputFiles(
this.resources,
this.directory
)
this.outputFiles = outputFiles
this.allEntries = allEntries
})
it('should only return the output files, not directories or resource paths', function () {
expect(this.outputFiles).to.have.deep.members([
{
path: 'output.pdf',
type: 'pdf',
},
{
path: 'extra/file.tex',
type: 'tex',
},
])
expect(this.allEntries).to.deep.equal([
'extra/file.tex',
'extra/',
'output.pdf',
'resource/path.tex',
'resource/',
'sneaky-file',
])
})
})
})