LatexMetrics.test.js 3.9 KB

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