Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed May 7, 2024
1 parent 9592d08 commit 3b7176e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 41 deletions.
16 changes: 6 additions & 10 deletions packages/manifest/test/Manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
{
Expand Down Expand Up @@ -761,17 +761,15 @@ describe('Manifest', () =>
assets: [
{
alias: [
'folder/json.json',
'folder/json'
'folder/json.json'
],
src: [
'folder/json.json'
]
},
{
alias: [
'folder/json.json5',
'folder/json'
'folder/json.json5'
],
src: [
'folder/json.json5'
Expand Down Expand Up @@ -811,17 +809,15 @@ describe('Manifest', () =>
},
{
alias: [
'spine/dragon.json',
'spine/dragon'
'spine/dragon.json'
],
src: [
'spine/dragon.json'
]
},
{
alias: [
'spine/dragon.atlas',
'spine/dragon'
'spine/dragon.atlas'
],
src: [
'spine/[email protected]',
Expand Down
82 changes: 54 additions & 28 deletions packages/spine/test/spineAtlasAll.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -128,37 +129,62 @@ describe('Spine Atlas All', () =>
});

await assetpack.run();
const globPath = `${outputDir}/*.{atlas,png,webp}`;
const files = await glob(globPath);

[
{
atlas: `[email protected]`,
png1: `[email protected]`,
png2: `[email protected]`
},
{
atlas: `dragon-spj8.webp.atlas`,
png1: `dragon-rSwKOg.webp`,
png2: `dragon2-ws3uhw.webp`
},
{
atlas: `[email protected]`,
png1: `[email protected]`,
png2: `[email protected]`
},
{
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);
}
});
});
});
32 changes: 29 additions & 3 deletions packages/spine/test/spineAtlasCacheBuster.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 3b7176e

Please sign in to comment.