OutputFileFinderTests.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const SandboxedModule = require('sandboxed-module')
  2. const sinon = require('sinon')
  3. const modulePath = require('path').join(
  4. __dirname,
  5. '../../../app/js/OutputFileFinder'
  6. )
  7. const { expect } = require('chai')
  8. const mockFs = require('mock-fs')
  9. describe('OutputFileFinder', function () {
  10. beforeEach(function () {
  11. this.OutputFileFinder = SandboxedModule.require(modulePath, {})
  12. this.directory = '/test/dir'
  13. this.callback = sinon.stub()
  14. mockFs({
  15. [this.directory]: {
  16. resource: {
  17. 'path.tex': 'a source file',
  18. },
  19. 'output.pdf': 'a generated pdf file',
  20. extra: {
  21. 'file.tex': 'a generated tex file',
  22. },
  23. 'sneaky-file': mockFs.symlink({
  24. path: '../foo',
  25. }),
  26. },
  27. })
  28. })
  29. afterEach(function () {
  30. mockFs.restore()
  31. })
  32. describe('findOutputFiles', function () {
  33. beforeEach(async function () {
  34. this.resource_path = 'resource/path.tex'
  35. this.output_paths = ['output.pdf', 'extra/file.tex']
  36. this.all_paths = this.output_paths.concat([this.resource_path])
  37. this.resources = [{ path: (this.resource_path = 'resource/path.tex') }]
  38. const { outputFiles, allEntries } =
  39. await this.OutputFileFinder.promises.findOutputFiles(
  40. this.resources,
  41. this.directory
  42. )
  43. this.outputFiles = outputFiles
  44. this.allEntries = allEntries
  45. })
  46. it('should only return the output files, not directories or resource paths', function () {
  47. expect(this.outputFiles).to.have.deep.members([
  48. {
  49. path: 'output.pdf',
  50. type: 'pdf',
  51. },
  52. {
  53. path: 'extra/file.tex',
  54. type: 'tex',
  55. },
  56. ])
  57. expect(this.allEntries).to.deep.equal([
  58. 'extra/file.tex',
  59. 'extra/',
  60. 'output.pdf',
  61. 'resource/path.tex',
  62. 'resource/',
  63. 'sneaky-file',
  64. ])
  65. })
  66. })
  67. })