diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..cdf3654 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "printWidth": 120 +} diff --git a/test/cache-buster/cacheBuster.test.ts b/test/cache-buster/cacheBuster.test.ts index ccd3426..02bd75b 100644 --- a/test/cache-buster/cacheBuster.test.ts +++ b/test/cache-buster/cacheBuster.test.ts @@ -1,9 +1,9 @@ import { existsSync } from 'node:fs'; import { join } from 'upath'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { Asset, AssetPack, path } from '../../src/core/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'cache-buster'; diff --git a/test/core/AssetWatcher.test.ts b/test/core/AssetWatcher.test.ts index be86c86..d165e4b 100644 --- a/test/core/AssetWatcher.test.ts +++ b/test/core/AssetWatcher.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getInputDir } from '../../shared/test/index.js'; import { Asset } from '../../src/core/Asset.js'; import { AssetCache } from '../../src/core/AssetCache.js'; import { AssetWatcher } from '../../src/core/AssetWatcher.js'; import { logAssetGraph } from '../../src/core/utils/logAssetGraph.js'; +import { assetPath, createFolder, getInputDir } from '../utils/index.js'; const pkg = 'core'; diff --git a/test/core/Assetpack.test.ts b/test/core/Assetpack.test.ts index 3fa84e3..e54e18c 100644 --- a/test/core/Assetpack.test.ts +++ b/test/core/Assetpack.test.ts @@ -2,6 +2,11 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import { join } from 'path'; import { describe, expect, it } from 'vitest'; +import { cacheBuster } from '../../src/cache-buster/cacheBuster.js'; +import { AssetPack } from '../../src/core/AssetPack.js'; +import { getHash } from '../../src/core/index.js'; +import { logAssetGraph } from '../../src/core/utils/logAssetGraph.js'; +import { pixiManifest } from '../../src/manifest/pixiManifest.js'; import { assetPath, createAssetPipe, @@ -9,12 +14,10 @@ import { getCacheDir, getInputDir, getOutputDir -} from '../../shared/test/index.js'; -import { AssetPack } from '../../src/core/AssetPack.js'; -import { logAssetGraph } from '../../src/core/utils/logAssetGraph.js'; +} from '../utils/index.js'; -import type { MockAssetPipe } from '../../shared/test/index.js'; import type { AssetPipe } from '../../src/core/pipes/AssetPipe.js'; +import type { MockAssetPipe } from '../utils/index.js'; const pkg = 'core'; @@ -125,6 +128,73 @@ describe('Core', () => expect(fs.readJSONSync(join(outputDir, 'json.json'))).toStrictEqual({ nice: 'test' }); }); + it('should delete previously hashed versions of an asset', { timeout: 10000 }, async () => + { + const testName = 'watch-delete-hash'; + const inputDir = `${getInputDir(pkg, testName)}/`; + const outputDir = getOutputDir(pkg, testName); + + createFolder( + pkg, + { + name: testName, + files: [{ + name: 'json.json', + content: assetPath('json/json.json'), + }], + folders: [], + }); + + const testFile = join(inputDir, 'json.json'); + + const assetpack = new AssetPack({ + entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: true, + pipes: [ + cacheBuster(), + pixiManifest(), + ] + }); + + await assetpack.watch(); + + const origHash = getHash(join(inputDir, 'json.json')); + + expect(existsSync(join(outputDir, `json-${origHash}.json`))).toBe(true); + + fs.writeJSONSync(testFile, { nice: 'test' }); + + await new Promise((resolve) => + { + setTimeout(resolve, 1500); + }); + + expect(existsSync(join(outputDir, `json-${origHash}.json`))).toBe(false); + const newHash = getHash(join(inputDir, 'json.json')); + + expect(existsSync(join(outputDir, `json-${newHash}.json`))).toBe(true); + + fs.removeSync(testFile); + + await new Promise((resolve) => + { + setTimeout(resolve, 1500); + }); + + await assetpack.stop(); + + expect(existsSync(join(outputDir, `json-${origHash}.json`))).toBe(false); + expect(existsSync(join(outputDir, `json-${newHash}.json`))).toBe(false); + expect(fs.readJSONSync(join(outputDir, 'manifest.json'))).toStrictEqual({ + bundles: [ + { + name: 'default', + assets: [] + }] + }); + }); + it('should ignore specified files when watching', async () => { const testName = 'watch-ignore'; diff --git a/test/core/Utils.test.ts b/test/core/Utils.test.ts index 43a7293..c17baaf 100644 --- a/test/core/Utils.test.ts +++ b/test/core/Utils.test.ts @@ -1,8 +1,8 @@ import { describe, expect, it } from 'vitest'; -import { createAssetPipe, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/AssetPack.js'; import { extractTagsFromFileName } from '../../src/core/utils/extractTagsFromFileName.js'; import { generateCacheName } from '../../src/core/utils/generateCacheName.js'; +import { createAssetPipe, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; import type { Asset } from '../../src/core/Asset.js'; import type { AssetPipe } from '../../src/core/index.js'; diff --git a/test/core/config.test.ts b/test/core/config.test.ts index ff8036f..8f56559 100644 --- a/test/core/config.test.ts +++ b/test/core/config.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { createAssetPipe } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; +import { createAssetPipe } from '../utils/index.js'; import type { AssetPackConfig } from '../../src/core/config.js'; diff --git a/test/ffmpeg/Audio.test.ts b/test/ffmpeg/Audio.test.ts index a851bee..98f8d43 100644 --- a/test/ffmpeg/Audio.test.ts +++ b/test/ffmpeg/Audio.test.ts @@ -1,8 +1,8 @@ import { existsSync } from 'node:fs'; import { describe, expect, it, vi } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { audio } from '../../src/ffmpeg/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'ffmpeg'; diff --git a/test/image/Compress.test.ts b/test/image/Compress.test.ts index 6db955f..d9c830b 100644 --- a/test/image/Compress.test.ts +++ b/test/image/Compress.test.ts @@ -1,8 +1,8 @@ import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { compress } from '../../src/image/compress.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'image'; diff --git a/test/image/Mipmap.test.ts b/test/image/Mipmap.test.ts index 348a1dc..39f9797 100644 --- a/test/image/Mipmap.test.ts +++ b/test/image/Mipmap.test.ts @@ -1,8 +1,8 @@ import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { mipmap } from '../../src/image/mipmap.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'image'; diff --git a/test/json/Json.test.ts b/test/json/Json.test.ts index 81051f6..a367b82 100644 --- a/test/json/Json.test.ts +++ b/test/json/Json.test.ts @@ -1,8 +1,8 @@ import { existsSync, readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { json } from '../../src/json/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'json'; diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 6d44b5c..0c6b8aa 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -1,21 +1,21 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { - assetPath, - createFolder, - getCacheDir, - getInputDir, - getOutputDir -} from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { audio } from '../../src/ffmpeg/index.js'; import { compress, mipmap } from '../../src/image/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { spineAtlasManifestMod, spineAtlasMipmap } from '../../src/spine/index.js'; import { texturePacker, texturePackerManifestMod } from '../../src/texture-packer/index.js'; +import { + assetPath, + createFolder, + getCacheDir, + getInputDir, + getOutputDir +} from '../utils/index.js'; -import type { File } from '../../shared/test/index.js'; +import type { File } from '../utils/index.js'; const pkg = 'manifest'; diff --git a/test/spine/spineAtlasAll.test.ts b/test/spine/spineAtlasAll.test.ts index e18b434..89de492 100644 --- a/test/spine/spineAtlasAll.test.ts +++ b/test/spine/spineAtlasAll.test.ts @@ -1,13 +1,13 @@ import { glob } from 'glob'; import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { AssetPack } from '../../src/core/index.js'; import { compress, mipmap } from '../../src/image/index.js'; import { spineAtlasCacheBuster } from '../../src/spine/spineAtlasCacheBuster.js'; import { spineAtlasCompress } from '../../src/spine/spineAtlasCompress.js'; import { spineAtlasMipmap } from '../../src/spine/spineAtlasMipmap.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'spine'; diff --git a/test/spine/spineAtlasCacheBuster.test.ts b/test/spine/spineAtlasCacheBuster.test.ts index 90d335a..c24a994 100644 --- a/test/spine/spineAtlasCacheBuster.test.ts +++ b/test/spine/spineAtlasCacheBuster.test.ts @@ -1,10 +1,10 @@ import { glob } from 'glob'; import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { AssetPack } from '../../src/core/index.js'; import { spineAtlasCacheBuster } from '../../src/spine/spineAtlasCacheBuster.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'spine'; diff --git a/test/spine/spineAtlasCompress.test.ts b/test/spine/spineAtlasCompress.test.ts index a41dd8b..cecfa68 100644 --- a/test/spine/spineAtlasCompress.test.ts +++ b/test/spine/spineAtlasCompress.test.ts @@ -1,9 +1,9 @@ import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { compress } from '../../src/image/index.js'; import { spineAtlasCompress } from '../../src/spine/spineAtlasCompress.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'spine'; diff --git a/test/spine/spineAtlasManifest.test.ts b/test/spine/spineAtlasManifest.test.ts index 5a27e2f..2a24b3d 100644 --- a/test/spine/spineAtlasManifest.test.ts +++ b/test/spine/spineAtlasManifest.test.ts @@ -1,9 +1,9 @@ import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { spineAtlasManifestMod } from '../../src/spine/spineAtlasManifestMod.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'spine'; diff --git a/test/spine/spineAtlasMipmap.test.ts b/test/spine/spineAtlasMipmap.test.ts index 975cc36..548189b 100644 --- a/test/spine/spineAtlasMipmap.test.ts +++ b/test/spine/spineAtlasMipmap.test.ts @@ -1,9 +1,9 @@ import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { mipmap } from '../../src/image/index.js'; import { spineAtlasMipmap } from '../../src/spine/spineAtlasMipmap.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'spine'; diff --git a/test/texture-packer/texturePacker.test.ts b/test/texture-packer/texturePacker.test.ts index f392af4..cb2188a 100644 --- a/test/texture-packer/texturePacker.test.ts +++ b/test/texture-packer/texturePacker.test.ts @@ -2,40 +2,15 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import sharp from 'sharp'; import { describe, expect, it, vi } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack, Logger } from '../../src/core/index.js'; import { texturePacker } from '../../src/texture-packer/texturePacker.js'; +import { createTPSFolder } from '../utils/createTPSFolder.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; -import type { File } from '../../shared/test/index.js'; +import type { File } from '../utils/index.js'; const pkg = 'texture-packer'; -function genFolder(testName: string) -{ - const sprites: File[] = []; - - for (let i = 0; i < 10; i++) - { - sprites.push({ - name: `sprite${i}.png`, - content: assetPath(`image/sp-${i + 1}.png`), - }); - } - createFolder( - pkg, - { - name: testName, - files: [], - folders: [ - { - name: 'sprites{tps}', - files: sprites, - folders: [], - }, - ], - }); -} - describe('Texture Packer', () => { it('should create a sprite sheet', async () => @@ -44,7 +19,7 @@ describe('Texture Packer', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), @@ -83,7 +58,7 @@ describe('Texture Packer', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const size = 512; @@ -119,7 +94,7 @@ describe('Texture Packer', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), @@ -152,7 +127,7 @@ describe('Texture Packer', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), @@ -276,7 +251,7 @@ describe('Texture Packer', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), diff --git a/test/texture-packer/texturePackerAll.test.ts b/test/texture-packer/texturePackerAll.test.ts index fb3f3ba..44b31ef 100644 --- a/test/texture-packer/texturePackerAll.test.ts +++ b/test/texture-packer/texturePackerAll.test.ts @@ -1,44 +1,17 @@ import fs from 'fs-extra'; import { glob } from 'glob'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { AssetPack } from '../../src/core/index.js'; import { compress, mipmap } from '../../src/image/index.js'; import { texturePacker } from '../../src/texture-packer/texturePacker.js'; import { texturePackerCacheBuster } from '../../src/texture-packer/texturePackerCacheBuster.js'; import { texturePackerCompress } from '../../src/texture-packer/texturePackerCompress.js'; - -import type { File } from '../../shared/test/index.js'; +import { createTPSFolder } from '../utils/createTPSFolder.js'; +import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'texture-packer'; -function genFolder(testName: string) -{ - const sprites: File[] = []; - - for (let i = 0; i < 10; i++) - { - sprites.push({ - name: `sprite${i}.png`, - content: assetPath(`image/sp-${i + 1}.png`), - }); - } - createFolder( - pkg, - { - name: testName, - files: [], - folders: [ - { - name: 'sprites{tps}', - files: sprites, - folders: [], - }, - ], - }); -} - describe('Texture Packer All', () => { it('should create a sprite sheet mip, compress and cache bust', async () => @@ -47,7 +20,7 @@ describe('Texture Packer All', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), diff --git a/test/texture-packer/texturePackerCacheBuster.test.ts b/test/texture-packer/texturePackerCacheBuster.test.ts index c1cdfde..8b04212 100644 --- a/test/texture-packer/texturePackerCacheBuster.test.ts +++ b/test/texture-packer/texturePackerCacheBuster.test.ts @@ -1,42 +1,15 @@ import fs from 'fs-extra'; import { glob } from 'glob'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { AssetPack } from '../../src/core/index.js'; import { texturePacker } from '../../src/texture-packer/texturePacker.js'; import { texturePackerCacheBuster } from '../../src/texture-packer/texturePackerCacheBuster.js'; - -import type { File } from '../../shared/test/index.js'; +import { createTPSFolder } from '../utils/createTPSFolder.js'; +import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'texture-packer'; -function genFolder(testName: string) -{ - const sprites: File[] = []; - - for (let i = 0; i < 10; i++) - { - sprites.push({ - name: `sprite${i}.png`, - content: assetPath(`image/sp-${i + 1}.png`), - }); - } - createFolder( - pkg, - { - name: testName, - files: [], - folders: [ - { - name: 'sprites{tps}', - files: sprites, - folders: [], - }, - ], - }); -} - describe('Texture Packer Cache Buster', () => { it('should create a sprite sheet and correctly update json', async () => @@ -45,7 +18,7 @@ describe('Texture Packer Cache Buster', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), diff --git a/test/texture-packer/texturePackerCompress.test.ts b/test/texture-packer/texturePackerCompress.test.ts index 4c9135a..23784b6 100644 --- a/test/texture-packer/texturePackerCompress.test.ts +++ b/test/texture-packer/texturePackerCompress.test.ts @@ -1,40 +1,13 @@ import fs from 'fs-extra'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { compress } from '../../src/image/index.js'; import { texturePacker, texturePackerCompress } from '../../src/texture-packer/index.js'; - -import type { File } from '../../shared/test/index.js'; +import { createTPSFolder } from '../utils/createTPSFolder.js'; +import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'texture-packer'; -function genFolder(testName: string) -{ - const sprites: File[] = []; - - for (let i = 0; i < 10; i++) - { - sprites.push({ - name: `sprite${i}.png`, - content: assetPath(`image/sp-${i + 1}.png`), - }); - } - createFolder( - pkg, - { - name: testName, - files: [], - folders: [ - { - name: 'sprites{tps}', - files: sprites, - folders: [], - }, - ], - }); -} - describe('Texture Packer Compression', () => { it('should create a sprite sheet', async () => @@ -43,7 +16,7 @@ describe('Texture Packer Compression', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const compressOpt = { png: true, diff --git a/test/texture-packer/texturePackerManifest.test.ts b/test/texture-packer/texturePackerManifest.test.ts index 1c368d0..b36ee2f 100644 --- a/test/texture-packer/texturePackerManifest.test.ts +++ b/test/texture-packer/texturePackerManifest.test.ts @@ -1,41 +1,14 @@ import fs from 'fs-extra'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { texturePacker } from '../../src/texture-packer/index.js'; import { texturePackerManifestMod } from '../../src/texture-packer/texturePackerManifestMod.js'; - -import type { File } from '../../shared/test/index.js'; +import { createTPSFolder } from '../utils/createTPSFolder.js'; +import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'texture-packer'; -function genFolder(testName: string) -{ - const sprites: File[] = []; - - for (let i = 0; i < 10; i++) - { - sprites.push({ - name: `sprite${i}.png`, - content: assetPath(`image/sp-${i + 1}.png`), - }); - } - createFolder( - pkg, - { - name: testName, - files: [], - folders: [ - { - name: 'sprites{tps}', - files: sprites, - folders: [], - }, - ], - }); -} - describe('Texture Packer Compression', () => { it('should create a sprite sheet', async () => @@ -44,7 +17,7 @@ describe('Texture Packer Compression', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), @@ -88,7 +61,7 @@ describe('Texture Packer Compression', () => const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName); - genFolder(testName); + createTPSFolder(testName, pkg); const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), diff --git a/test/utils/createTPSFolder.ts b/test/utils/createTPSFolder.ts new file mode 100644 index 0000000..33e464e --- /dev/null +++ b/test/utils/createTPSFolder.ts @@ -0,0 +1,29 @@ +import { assetPath, createFolder } from '.'; + +import type { File } from '.'; + +export function createTPSFolder(testName: string, pkg: string): void +{ + const sprites: File[] = []; + + for (let i = 0; i < 10; i++) + { + sprites.push({ + name: `sprite${i}.png`, + content: assetPath(`image/sp-${i + 1}.png`), + }); + } + createFolder( + pkg, + { + name: testName, + files: [], + folders: [ + { + name: 'sprites{tps}', + files: sprites, + folders: [], + }, + ], + }); +} diff --git a/shared/test/index.ts b/test/utils/index.ts similarity index 100% rename from shared/test/index.ts rename to test/utils/index.ts diff --git a/test/webfont/Webfont.test.ts b/test/webfont/Webfont.test.ts index 38cbf6d..f694367 100644 --- a/test/webfont/Webfont.test.ts +++ b/test/webfont/Webfont.test.ts @@ -1,10 +1,10 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; -import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../../shared/test/index.js'; import { AssetPack } from '../../src/core/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { msdfFont, sdfFont, webfont } from '../../src/webfont/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; const pkg = 'webfont';