Skip to content

Commit

Permalink
setup testing
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Jan 14, 2019
1 parent 5680b06 commit e6755ad
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 32 deletions.
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
preset: 'ts-jest',
globals: {
'ts-jest': {
diagnostics: {
// warnOnly: true,
},
tsConfig: {
types: [
"node",
"jest",
],
},
},
},
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest --maxWorkers=4",
"lint": "tslint --project tsconfig.json"
},
"husky": {
Expand Down Expand Up @@ -44,8 +45,11 @@
"devDependencies": {
"@types/debug": "0.0.31",
"@types/fs-extra": "^5.0.4",
"@types/jest": "^23.3.12",
"@types/sharp": "^0.21.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"ts-jest": "^23.10.5",
"tslint": "^5.12.1",
"tslint-ionic-rules": "0.0.21",
"typescript": "^3.2.2"
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isSupportedPlatform } from '../platform';

describe('cordova-res', () => {

describe('platform', () => {

describe('isSupportedPlatform', () => {

it('should support android', async () => {
expect(isSupportedPlatform('android')).toEqual(true);
});

it('should support ios', async () => {
expect(isSupportedPlatform('ios')).toEqual(true);
});

it('should not support garbage', async () => {
expect(isSupportedPlatform('garbage')).toEqual(false);
});

});

});

});
33 changes: 1 addition & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ensureDir } from '@ionic/utils-fs';
import * as Debug from 'debug';
import * as path from 'path';
import * as sharp from 'sharp';

import { isSupportedPlatform, runPlatform } from './platform';
import { Platform, RESOURCES } from './resources';

const debug = Debug('cordova-res');
Expand Down Expand Up @@ -37,33 +36,3 @@ export async function run(): Promise<void> {
process.stdout.write(e.stack ? e.stack : e.toString());
}
}

export function isSupportedPlatform(platform?: string): platform is Platform {
return platform === 'ios' || platform === 'android';
}

export async function runPlatform(platform: Platform): Promise<void> {
const plt = RESOURCES[platform];

let images = 0;

await Promise.all(Object.entries(plt).map(async ([ type, config]) => {
debug('Building %s resources for %s platform', type, platform);

const dir = path.join('resources', platform, type);
await ensureDir(dir);

await Promise.all(config.images.map(async image => {
const p = path.join(dir, image.name);
debug('Generating %o (%ox%o)', p, image.width, image.height);

await sharp(`./resources/${type}.png`)
.resize(image.width, image.height)
.toFile(p);

images++;
}));
}));

process.stdout.write(`Generated ${images} images for ${platform}\n`);
}
38 changes: 38 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ensureDir } from '@ionic/utils-fs';
import * as Debug from 'debug';
import * as path from 'path';
import * as sharp from 'sharp';

import { Platform, RESOURCES } from './resources';

const debug = Debug('cordova-res:platform');

export async function runPlatform(platform: Platform): Promise<void> {
const plt = RESOURCES[platform];

let images = 0;

await Promise.all(Object.entries(plt).map(async ([ type, config]) => {
debug('Building %s resources for %s platform', type, platform);

const dir = path.join('resources', platform, type);
await ensureDir(dir);

await Promise.all(config.images.map(async image => {
const p = path.join(dir, image.name);
debug('Generating %o (%ox%o)', p, image.width, image.height);

await sharp(`./resources/${type}.png`)
.resize(image.width, image.height)
.toFile(p);

images++;
}));
}));

process.stdout.write(`Generated ${images} images for ${platform}\n`);
}

export function isSupportedPlatform(platform?: string): platform is Platform {
return platform === 'ios' || platform === 'android';
}

0 comments on commit e6755ad

Please sign in to comment.