diff --git a/packages/manifest/test/Manifest.test.ts b/packages/manifest/test/Manifest.test.ts index c19b962..512438e 100644 --- a/packages/manifest/test/Manifest.test.ts +++ b/packages/manifest/test/Manifest.test.ts @@ -631,11 +631,11 @@ describe('Manifest', () => ], }, { - alias: ['folder2/1.mp3', '1.mp3'], + alias: ['folder2/1.mp3'], src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: ['folder2/folder3/1.mp3', '1.mp3'], + alias: ['folder2/folder3/1.mp3'], src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { @@ -761,8 +761,7 @@ describe('Manifest', () => assets: [ { alias: [ - 'folder/json.json', - 'folder/json' + 'folder/json.json' ], src: [ 'folder/json.json' @@ -770,8 +769,7 @@ describe('Manifest', () => }, { alias: [ - 'folder/json.json5', - 'folder/json' + 'folder/json.json5' ], src: [ 'folder/json.json5' @@ -811,8 +809,7 @@ describe('Manifest', () => }, { alias: [ - 'spine/dragon.json', - 'spine/dragon' + 'spine/dragon.json' ], src: [ 'spine/dragon.json' @@ -820,8 +817,7 @@ describe('Manifest', () => }, { alias: [ - 'spine/dragon.atlas', - 'spine/dragon' + 'spine/dragon.atlas' ], src: [ 'spine/dragon@0.5x.atlas', diff --git a/packages/spine/test/spineAtlasAll.test.ts b/packages/spine/test/spineAtlasAll.test.ts index 6f4c95a..1227ab9 100644 --- a/packages/spine/test/spineAtlasAll.test.ts +++ b/packages/spine/test/spineAtlasAll.test.ts @@ -1,4 +1,5 @@ -import { existsSync, readFileSync } from 'fs-extra'; +import { readFileSync } from 'fs-extra'; +import glob from 'glob-promise'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCacheBuster } from '../src/spineAtlasCacheBuster'; import { spineAtlasCompress } from '../src/spineAtlasCompress'; @@ -128,37 +129,62 @@ describe('Spine Atlas All', () => }); await assetpack.run(); + const globPath = `${outputDir}/*.{atlas,png,webp}`; + const files = await glob(globPath); - [ - { - atlas: `dragon-ZmGiUA@0.5x.webp.atlas`, - png1: `dragon-7mmX8g@0.5x.webp`, - png2: `dragon2-k_22pw@0.5x.webp` - }, - { - atlas: `dragon-spj8.webp.atlas`, - png1: `dragon-rSwKOg.webp`, - png2: `dragon2-ws3uhw.webp` - }, - { - atlas: `dragon-wstH@0.5x.png.atlas`, - png1: `dragon-3--s@0.5x.png`, - png2: `dragon2-vflfww@0.5x.png` - }, - { - atlas: `dragon-O471eg.png.atlas`, - png1: `dragon-vezElA.png`, - png2: `dragon2-3UnJNw.png` - } - ].forEach(({ atlas, png1, png2 }) => + // need two sets of files + expect(files.length).toBe(12); + expect(files.filter((file) => file.endsWith('.atlas')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.webp')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.jpg')).length).toBe(0); + + const atlasFiles = files.filter((file) => file.endsWith('.atlas')); + const pngFiles = files.filter((file) => file.endsWith('.png')); + const webpFiles = files.filter((file) => file.endsWith('.webp')); + + // check that the files are correct + atlasFiles.forEach((atlasFile) => { - const rawAtlas = readFileSync(`${outputDir}/${atlas}`); + const rawAtlas = readFileSync(atlasFile); + const isHalfSize = atlasFile.includes('@0.5x'); + const isWebp = atlasFile.includes('.webp'); + const isPng = atlasFile.includes('.png'); + + const checkFiles = (fileList: string[], isHalfSize: boolean, isFileType: boolean) => + { + fileList.forEach((file) => + { + // remove the outputDir + file = file.replace(`${outputDir}/`, ''); + const isFileHalfSize = file.includes('@0.5x'); + const isFileFileType = file.includes(isWebp ? '.webp' : '.png'); + const shouldExist = isHalfSize === isFileHalfSize && isFileType === isFileFileType; - expect(rawAtlas.includes(png1)).toBeTruthy(); - expect(rawAtlas.includes(png2)).toBeTruthy(); + expect(rawAtlas.includes(file)).toBe(shouldExist); + }); + }; - expect(existsSync(`${outputDir}/${png1}`)).toBeTruthy(); - expect(existsSync(`${outputDir}/${png2}`)).toBeTruthy(); + if (isHalfSize) + { + if (isWebp) + { + checkFiles(webpFiles, true, true); + } + else if (isPng) + { + checkFiles(pngFiles, true, true); + } + } + else + if (isWebp) + { + checkFiles(webpFiles, false, true); + } + else if (isPng) + { + checkFiles(pngFiles, false, true); + } }); }); }); diff --git a/packages/spine/test/spineAtlasCacheBuster.test.ts b/packages/spine/test/spineAtlasCacheBuster.test.ts index f8f9aa7..6164abb 100644 --- a/packages/spine/test/spineAtlasCacheBuster.test.ts +++ b/packages/spine/test/spineAtlasCacheBuster.test.ts @@ -1,4 +1,5 @@ import { readFileSync } from 'fs-extra'; +import glob from 'glob-promise'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCacheBuster } from '../src/spineAtlasCacheBuster'; import { AssetPack } from '@play-co/assetpack-core'; @@ -47,9 +48,34 @@ describe('Spine Atlas Cache Buster', () => await assetpack.run(); - const rawAtlas = readFileSync(`${outputDir}/dragon-qmTByg.atlas`); + const globPath = `${outputDir}/*.{atlas,png}`; + const files = await glob(globPath); - expect(rawAtlas.includes('dragon-iSqGPQ')).toBeTruthy(); - expect(rawAtlas.includes('dragon2-6ebkeA')).toBeTruthy(); + // need two sets of files + expect(files.length).toBe(3); + expect(files.filter((file) => file.endsWith('.atlas')).length).toBe(1); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(2); + + const atlasFiles = files.filter((file) => file.endsWith('.atlas')); + const pngFiles = files.filter((file) => file.endsWith('.png')); + + // check that the files are correct + atlasFiles.forEach((atlasFile) => + { + const rawAtlas = readFileSync(atlasFile); + + const checkFiles = (fileList: string[]) => + { + fileList.forEach((file) => + { + // remove the outputDir + file = file.replace(`${outputDir}/`, ''); + + expect(rawAtlas.includes(file)).toBe(true); + }); + }; + + checkFiles(pngFiles); + }); }); });