LatexMetricsTests.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const fs = require('node:fs')
  2. const path = require('node:path')
  3. const { expect } = require('chai')
  4. const { addLatexFdbMetrics } = require('../../../app/js/LatexMetrics')
  5. describe('LatexMetrics', function () {
  6. describe('addLatexFdbMetrics', function () {
  7. beforeEach(function () {
  8. this.stats = {}
  9. Object.defineProperty(this.stats, 'latexmk', {
  10. value: {},
  11. enumerable: false,
  12. })
  13. })
  14. it('should do nothing if fdbContent is null or empty', function () {
  15. addLatexFdbMetrics(null, this.stats)
  16. expect(this.stats.latexmk).to.deep.equal({})
  17. addLatexFdbMetrics('', this.stats)
  18. expect(this.stats.latexmk).to.deep.equal({})
  19. })
  20. it('should parse v3 fdb content and add to stats', function () {
  21. const fdbContent = fs.readFileSync(
  22. path.join(__dirname, 'fixtures', 'v3.fdb_latexmk'),
  23. 'utf8'
  24. )
  25. addLatexFdbMetrics(fdbContent, this.stats)
  26. expect(this.stats.latexmk['fdb-file-types']).to.deep.equal({
  27. system: [
  28. { ext: 'fmt', count: 1, size: 3847283 },
  29. { ext: 'map', count: 2, size: 1644257 },
  30. { ext: 'pfb', count: 12, size: 404691 },
  31. { ext: 'sty', count: 19, size: 209868 },
  32. { ext: 'mkii', count: 1, size: 71627 },
  33. { ext: 'def', count: 1, size: 55368 },
  34. { ext: 'cnf', count: 2, size: 32268 },
  35. { ext: 'bst', count: 1, size: 24635 },
  36. { ext: 'tfm', count: 16, size: 20608 },
  37. { ext: 'cls', count: 1, size: 20496 },
  38. { ext: 'clo', count: 1, size: 8967 },
  39. { ext: 'cfg', count: 2, size: 4241 },
  40. { ext: 'fd', count: 2, size: 4089 },
  41. ],
  42. user: [
  43. { ext: 'png', count: 2, size: 3886031 },
  44. { ext: 'tex', count: 1, size: 6147 },
  45. { ext: 'aux', count: 1, size: 1080 },
  46. { ext: 'bib', count: 1, size: 230 },
  47. { ext: 'bbl', count: 1, size: 203 },
  48. ],
  49. total: {
  50. fontFileCount: 0,
  51. fontFileSize: 0,
  52. imageFileCount: 2,
  53. imageFileSize: 3886031,
  54. otherFileCount: 2,
  55. otherFileSize: 1283,
  56. systemFileCount: 61,
  57. systemFileSize: 6348398,
  58. textFileCount: 2,
  59. textFileSize: 6377,
  60. },
  61. })
  62. })
  63. it('should parse v4 fdb content and add to stats', function () {
  64. const fdbContent = fs.readFileSync(
  65. path.join(__dirname, 'fixtures', 'v4.fdb_latexmk'),
  66. 'utf8'
  67. )
  68. addLatexFdbMetrics(fdbContent, this.stats)
  69. expect(this.stats.latexmk['fdb-file-types']).to.deep.equal({
  70. system: [
  71. { ext: 'fmt', count: 1, size: 8172536 },
  72. { ext: 'map', count: 2, size: 4652176 },
  73. { ext: 'pfb', count: 13, size: 542949 },
  74. { ext: 'sty', count: 9, size: 100959 },
  75. { ext: 'mkii', count: 1, size: 71627 },
  76. { ext: 'def', count: 2, size: 49388 },
  77. { ext: 'cnf', count: 2, size: 41037 },
  78. { ext: 'bst', count: 1, size: 24635 },
  79. { ext: 'tfm', count: 17, size: 22144 },
  80. { ext: 'cls', count: 1, size: 20144 },
  81. { ext: 'clo', count: 1, size: 8448 },
  82. { ext: 'enc', count: 1, size: 2900 },
  83. { ext: 'fd', count: 1, size: 2470 },
  84. { ext: 'cfg', count: 2, size: 1902 },
  85. ],
  86. user: [
  87. { ext: 'png', count: 2, size: 3886031 },
  88. { ext: 'tex', count: 1, size: 6147 },
  89. { ext: 'aux', count: 1, size: 1382 },
  90. { ext: 'bib', count: 1, size: 230 },
  91. { ext: 'bbl', count: 1, size: 203 },
  92. ],
  93. total: {
  94. fontFileCount: 0,
  95. fontFileSize: 0,
  96. imageFileCount: 2,
  97. imageFileSize: 3886031,
  98. otherFileCount: 2,
  99. otherFileSize: 1585,
  100. systemFileCount: 54,
  101. systemFileSize: 13713315,
  102. textFileCount: 2,
  103. textFileSize: 6377,
  104. },
  105. })
  106. })
  107. })
  108. })