MojangIndexProcessorTest.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* eslint-disable @typescript-eslint/ban-ts-comment */
  2. import nock from 'nock'
  3. import { URL } from 'url'
  4. import { MojangIndexProcessor } from 'common/asset/processor/MojangIndexProcessor'
  5. import { dirname, join } from 'path'
  6. import { expect } from 'chai'
  7. import { remove, pathExists } from 'fs-extra'
  8. import { getVersionJsonPath } from 'common/util/FileUtils'
  9. // @ts-ignore (JSON Modules enabled in tsconfig.test.json)
  10. import versionManifest from './files/version_manifest.json'
  11. // @ts-ignore (JSON Modules enabled in tsconfig.test.json)
  12. import versionJson115 from './files/1.15.2.json'
  13. // @ts-ignore (JSON Modules enabled in tsconfig.test.json)
  14. import versionJson1710 from './files/1.7.10.json'
  15. // @ts-ignore (JSON Modules enabled in tsconfig.test.json)
  16. import index115 from './files/index_1.15.json'
  17. const commonDir = join(__dirname, 'files')
  18. const assetDir = join(commonDir, 'assets')
  19. const jsonPath115 = getVersionJsonPath(commonDir, '1.15.2')
  20. const indexPath115 = join(assetDir, 'indexes', '1.15.json')
  21. const jsonPath1710 = getVersionJsonPath(commonDir, '1.7.10')
  22. describe('Mojang Index Processor', () => {
  23. after(async () => {
  24. nock.cleanAll()
  25. await remove(dirname(jsonPath115))
  26. await remove(indexPath115)
  27. await remove(dirname(jsonPath1710))
  28. })
  29. it('[ MIP ] Validate Full Remote (1.15.2)', async () => {
  30. const manifestUrl = new URL(MojangIndexProcessor.VERSION_MANIFEST_ENDPOINT)
  31. const versionJsonUrl = new URL('https://launchermeta.mojang.com/v1/packages/1a36ca2e147f4fdc4a8b9c371450e1581732c354/1.15.2.json')
  32. const assetIndexUrl = new URL('https://launchermeta.mojang.com/v1/packages/5406d9a75dfb58f549070d8bae279562c38a68f6/1.15.json')
  33. nock(manifestUrl.origin)
  34. .get(manifestUrl.pathname)
  35. .reply(200, versionManifest)
  36. nock(versionJsonUrl.origin)
  37. .get(versionJsonUrl.pathname)
  38. .reply(200, versionJson115)
  39. nock(assetIndexUrl.origin)
  40. .get(assetIndexUrl.pathname)
  41. .reply(200, index115)
  42. const mojangIndexProcessor = new MojangIndexProcessor(commonDir, '1.15.2')
  43. await mojangIndexProcessor.init()
  44. const notValid = await mojangIndexProcessor.validate()
  45. const savedJson = await pathExists(jsonPath115)
  46. const savedIndex = await pathExists(indexPath115)
  47. expect(notValid).to.haveOwnProperty('assets')
  48. expect(notValid.assets).to.have.lengthOf(2109-2)
  49. expect(notValid).to.haveOwnProperty('libraries')
  50. // Natives are different per OS
  51. expect(notValid.libraries).to.have.length.gte(24)
  52. expect(notValid).to.haveOwnProperty('client')
  53. expect(notValid.client).to.have.lengthOf(1)
  54. expect(notValid).to.haveOwnProperty('misc')
  55. expect(notValid.misc).to.have.lengthOf(1)
  56. expect(savedJson).to.equal(true)
  57. expect(savedIndex).to.equal(true)
  58. })
  59. it('[ MIP ] Validate Full Local (1.12.2)', async () => {
  60. const manifestUrl = new URL(MojangIndexProcessor.VERSION_MANIFEST_ENDPOINT)
  61. nock(manifestUrl.origin)
  62. .get(manifestUrl.pathname)
  63. .reply(200, versionManifest)
  64. const mojangIndexProcessor = new MojangIndexProcessor(commonDir, '1.12.2')
  65. await mojangIndexProcessor.init()
  66. const notValid = await mojangIndexProcessor.validate()
  67. expect(notValid).to.haveOwnProperty('assets')
  68. expect(notValid.assets).to.have.lengthOf(1305-2)
  69. expect(notValid).to.haveOwnProperty('libraries')
  70. // Natives are different per OS
  71. expect(notValid.libraries).to.have.length.gte(27)
  72. expect(notValid).to.haveOwnProperty('client')
  73. expect(notValid.client).to.have.lengthOf(1)
  74. expect(notValid).to.haveOwnProperty('misc')
  75. expect(notValid.misc).to.have.lengthOf(1)
  76. })
  77. it('[ MIP ] Validate Half Remote (1.7.10)', async () => {
  78. const manifestUrl = new URL(MojangIndexProcessor.VERSION_MANIFEST_ENDPOINT)
  79. const versionJsonUrl = new URL('https://launchermeta.mojang.com/v1/packages/2e818dc89e364c7efcfa54bec7e873c5f00b3840/1.7.10.json')
  80. nock(manifestUrl.origin)
  81. .get(manifestUrl.pathname)
  82. .reply(200, versionManifest)
  83. nock(versionJsonUrl.origin)
  84. .get(versionJsonUrl.pathname)
  85. .reply(200, versionJson1710)
  86. const mojangIndexProcessor = new MojangIndexProcessor(commonDir, '1.7.10')
  87. await mojangIndexProcessor.init()
  88. const notValid = await mojangIndexProcessor.validate()
  89. const savedJson = await pathExists(jsonPath1710)
  90. expect(notValid).to.haveOwnProperty('assets')
  91. expect(notValid.assets).to.have.lengthOf(686-2)
  92. expect(notValid).to.haveOwnProperty('libraries')
  93. // Natives are different per OS
  94. expect(notValid.libraries).to.have.length.gte(27)
  95. expect(notValid).to.haveOwnProperty('client')
  96. expect(notValid.client).to.have.lengthOf(1)
  97. expect(notValid).to.haveOwnProperty('misc')
  98. expect(notValid.misc).to.have.lengthOf(1)
  99. expect(savedJson).to.equal(true)
  100. })
  101. })