MojangIndexProcessorTest.ts 5.0 KB

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