From 294781737b06a6a6ecc3dd095da0a522ed6a2e2c Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Wed, 12 Oct 2022 16:26:44 -0500 Subject: [PATCH] Fix tests for Windows --- src/project.ts | 2 - test/platforms/android.asset.test.ts | 93 +++++++++------------------- 2 files changed, 28 insertions(+), 67 deletions(-) diff --git a/src/project.ts b/src/project.ts index e19dcf0..fac41ca 100644 --- a/src/project.ts +++ b/src/project.ts @@ -14,8 +14,6 @@ export class Project extends MobileProject { constructor(projectRoot: string = process.cwd(), config: MobileProjectConfig, private assetPath: string = 'assets') { super(projectRoot, config); - // const projectRoot = join((config.android ?? config.ios)?.path ?? '', '../'); - this.directory = projectRoot; this.assetDir = join(projectRoot, assetPath); diff --git a/test/platforms/android.asset.test.ts b/test/platforms/android.asset.test.ts index 8bd4163..bb953f4 100644 --- a/test/platforms/android.asset.test.ts +++ b/test/platforms/android.asset.test.ts @@ -1,11 +1,4 @@ -import { - copy, - pathExists, - readdirp, - readFile, - rm, - statSync, -} from '@ionic/utils-fs'; +import { copy, pathExists, readdirp, readFile, rm, statSync } from '@ionic/utils-fs'; import tempy from 'tempy'; import sharp from 'sharp'; import { join } from 'path'; @@ -59,40 +52,31 @@ describe('Android asset test', () => { await rm(fixtureDir, { force: true, recursive: true }); }); - async function verifySizes( - generatedAssets: OutputAsset[], - ) { + async function verifySizes(generatedAssets: OutputAsset[]) { const sizedSet = await Promise.all( - generatedAssets.map(async asset => { + generatedAssets.map(async (asset) => { const dest = Object.values(asset.destFilenames)[0]; const pipe = sharp(dest); const metadata = await pipe.metadata(); - return ( - metadata.width === asset.template.width && - metadata.height === asset.template.height - ); - }), + return metadata.width === asset.template.width && metadata.height === asset.template.height; + }) ); - expect(sizedSet.every(e => !!e)).toBe(true); + expect(sizedSet.every((e) => !!e)).toBe(true); } it('Should generate android legacy icons', async () => { const assets = await ctx.project.loadInputAssets(); const strategy = new AndroidAssetGenerator(); - let generatedAssets = ((await assets.icon?.generate( - strategy, - ctx.project, - )) ?? []) as OutputAsset[]; + let generatedAssets = ((await assets.icon?.generate(strategy, ctx.project)) ?? + []) as OutputAsset[]; // Expect legacy main icons and rounded to be generated expect(generatedAssets.length).toBe(12); const template = generatedAssets[0].template; - Object.values(generatedAssets[0].destFilenames).map(async f => - expect(await pathExists(f)).toBe(true), - ); + Object.values(generatedAssets[0].destFilenames).map(async (f) => expect(await pathExists(f)).toBe(true)); await verifySizes(generatedAssets); }); @@ -101,27 +85,19 @@ describe('Android asset test', () => { const assets = await ctx.project.loadInputAssets(); const strategy = new AndroidAssetGenerator(); - let generatedAssets = ((await assets.iconForeground?.generate( - strategy, - ctx.project, - )) ?? []) as OutputAsset[]; + let generatedAssets = ((await assets.iconForeground?.generate(strategy, ctx.project)) ?? + []) as OutputAsset[]; expect(generatedAssets.length).toBe(6); - Object.values(generatedAssets[0].destFilenames).map(async f => - expect(await pathExists(f)).toBe(true), - ); + Object.values(generatedAssets[0].destFilenames).map(async (f) => expect(await pathExists(f)).toBe(true)); - generatedAssets = ((await assets.iconBackground?.generate( - strategy, - ctx.project, - )) ?? []) as OutputAsset[]; + generatedAssets = ((await assets.iconBackground?.generate(strategy, ctx.project)) ?? + []) as OutputAsset[]; expect(generatedAssets.length).toBe(6); - Object.values(generatedAssets[0].destFilenames).map(async f => - expect(await pathExists(f)).toBe(true), - ); + Object.values(generatedAssets[0].destFilenames).map(async (f) => expect(await pathExists(f)).toBe(true)); await verifySizes(generatedAssets); }); @@ -130,18 +106,14 @@ describe('Android asset test', () => { const assets = await ctx.project.loadInputAssets(); const strategy = new AndroidAssetGenerator(); - let generatedAssets = - (await assets.splash?.generate(strategy, ctx.project)) ?? []; + let generatedAssets = (await assets.splash?.generate(strategy, ctx.project)) ?? []; expect(generatedAssets.length).toBe(12); - generatedAssets = - (await assets.splashDark?.generate(strategy, ctx.project)) ?? []; + generatedAssets = (await assets.splashDark?.generate(strategy, ctx.project)) ?? []; expect(generatedAssets.length).toBe(12); - await verifySizes( - generatedAssets as OutputAsset[], - ); + await verifySizes(generatedAssets as OutputAsset[]); }); }); @@ -159,21 +131,16 @@ describe('Android Asset Test - Logo Only', () => { assets = await ctx.project.loadInputAssets(); }); - async function verifySizes( - generatedAssets: OutputAsset[], - ) { + async function verifySizes(generatedAssets: OutputAsset[]) { const sizedSet = await Promise.all( - generatedAssets.map(async asset => { + generatedAssets.map(async (asset) => { const dest = Object.values(asset.destFilenames)[0]; const pipe = sharp(dest); const metadata = await pipe.metadata(); - return ( - metadata.width === asset.template.width && - metadata.height === asset.template.height - ); - }), + return metadata.width === asset.template.width && metadata.height === asset.template.height; + }) ); - expect(sizedSet.every(e => !!e)).toBe(true); + expect(sizedSet.every((e) => !!e)).toBe(true); } afterAll(async () => { @@ -205,10 +172,8 @@ describe('Android Asset Test - Logo Only', () => { splashBackgroundColor: '#999999', splashBackgroundColorDark: '#122140', }); - let generatedAssets = ((await assets.logo?.generate( - strategy, - ctx.project, - )) ?? []) as OutputAsset[]; + let generatedAssets = ((await assets.logo?.generate(strategy, ctx.project)) ?? + []) as OutputAsset[]; expect(generatedAssets.length).toBe(48); await verifySizes(generatedAssets); @@ -219,10 +184,8 @@ describe('Android Asset Test - Logo Only', () => { splashBackgroundColor: '#999999', splashBackgroundColorDark: '#122140', }); - let generatedAssets = ((await assets.logoDark?.generate( - strategy, - ctx.project, - )) ?? []) as OutputAsset[]; + let generatedAssets = ((await assets.logoDark?.generate(strategy, ctx.project)) ?? + []) as OutputAsset[]; expect(generatedAssets.length).toBe(12); await verifySizes(generatedAssets); @@ -239,7 +202,7 @@ describe('Android Asset Test - Logo Only', () => { Object.keys(asset.destFilenames).forEach(async (name) => { let filename = asset.getDestFilename(name); - expect(filename).toEqual(expect.stringContaining('/app/src/demo/res/')); + expect(filename).toEqual(expect.stringContaining(join('app', 'src', 'demo', 'res'))); expect(await pathExists(filename)).toBe(true); }); });