forked from pixijs/assetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(manifest): filter out duplicate names (#24)
* fix(manifest): filter out duplicate names * fix tests
- Loading branch information
Showing
8 changed files
with
294 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,9 +357,7 @@ describe('Manifest', () => | |
{ | ||
alias: [ | ||
'folder/json.json', | ||
'folder/json', | ||
'json.json', | ||
'json' | ||
], | ||
src: [ | ||
'folder/json.json' | ||
|
@@ -368,9 +366,7 @@ describe('Manifest', () => | |
{ | ||
alias: [ | ||
'folder/json.json5', | ||
'folder/json', | ||
'json.json5', | ||
'json' | ||
], | ||
src: [ | ||
'folder/json.json5' | ||
|
@@ -394,8 +390,6 @@ describe('Manifest', () => | |
alias: [ | ||
'folder2/1.mp3', | ||
'folder2/1', | ||
'1.mp3', | ||
'1' | ||
], | ||
src: [ | ||
'folder2/1.ogg', | ||
|
@@ -406,8 +400,6 @@ describe('Manifest', () => | |
alias: [ | ||
'folder2/folder3/1.mp3', | ||
'folder2/folder3/1', | ||
'1.mp3', | ||
'1' | ||
], | ||
src: [ | ||
'folder2/folder3/1.ogg', | ||
|
@@ -417,9 +409,7 @@ describe('Manifest', () => | |
{ | ||
alias: [ | ||
'spine/dragon.json', | ||
'spine/dragon', | ||
'dragon.json', | ||
'dragon' | ||
], | ||
src: [ | ||
'spine/dragon.json' | ||
|
@@ -428,9 +418,7 @@ describe('Manifest', () => | |
{ | ||
alias: [ | ||
'spine/dragon.atlas', | ||
'spine/dragon', | ||
'dragon.atlas', | ||
'dragon' | ||
], | ||
src: [ | ||
'spine/[email protected]', | ||
|
@@ -643,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'], | ||
}, | ||
{ | ||
|
@@ -773,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' | ||
|
@@ -823,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]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -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); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.