Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
tancredi committed Oct 2, 2021
1 parent cc3a38b commit b6c90de
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/core/__tests__/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseConfig } from '../config-parser';
import { checkPath } from '../../utils/fs-async';
import { DEFAULT_OPTIONS } from '../../constants';

const checkPathMock = (checkPath as any) as jest.Mock;
const checkPathMock = checkPath as any as jest.Mock;

jest.mock('../../utils/fs-async', () => ({ checkPath: jest.fn() }));

Expand Down
10 changes: 5 additions & 5 deletions src/core/__tests__/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { getGeneratorOptions } from '../../generators/generator-options';
import { parseConfig } from '../config-parser';
import { DEFAULT_OPTIONS } from '../../constants';

const generateAssetsMock = (generateAssets as any) as jest.Mock;
const parseConfigMock = (parseConfig as any) as jest.Mock;
const writeAssetsMock = (writeAssets as any) as jest.Mock;
const loadAssetsMock = (loadAssets as any) as jest.Mock;
const getGeneratorOptionsMock = (getGeneratorOptions as any) as jest.Mock;
const generateAssetsMock = generateAssets as any as jest.Mock;
const parseConfigMock = parseConfig as any as jest.Mock;
const writeAssetsMock = writeAssets as any as jest.Mock;
const loadAssetsMock = loadAssets as any as jest.Mock;
const getGeneratorOptionsMock = getGeneratorOptions as any as jest.Mock;

jest.mock('../../constants', () => ({
DEFAULT_OPTIONS: { hasDefaults: true, parsed: false }
Expand Down
2 changes: 1 addition & 1 deletion src/core/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ export const parseConfig = async (input: object = {}) => {
out[key] = val;
}

return (out as any) as RunnerOptions;
return out as any as RunnerOptions;
};
4 changes: 2 additions & 2 deletions src/generators/__tests__/generate-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jest.mock('../asset-types', () => {
};
});

const cast = <T>(val: any) => (val as unknown) as T;
const cast = <T>(val: any) => val as unknown as T;

const getGeneratorFn = (key: string) =>
generators[key as keyof typeof generators].generate;

describe('Generate assets', () => {
beforeEach(() => {
for (const gen of Object.values(generators)) {
((gen.generate as unknown) as jest.Mock).mockClear();
(gen.generate as unknown as jest.Mock).mockClear();
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/generators/__tests__/generator-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AssetsMap } from '../../utils/assets';
import { ASSET_TYPES, ASSET_TYPES_WITH_TEMPLATE } from '../../types/misc';
import { getCodepoints } from '../../utils/codepoints';

const getCodepointsMock = (getCodepoints as any) as jest.Mock;
const getCodepointsMock = getCodepoints as any as jest.Mock;

jest.mock('path');

Expand Down Expand Up @@ -69,7 +69,7 @@ describe('Font generator options', () => {
formatOptions,
pathOptions
} as any;
const assets = ({ __mock: 'runnerOptions__' } as unknown) as AssetsMap;
const assets = { __mock: 'runnerOptions__' } as unknown as AssetsMap;
const generatorOptions = getGeneratorOptions(options, assets);
expect(generatorOptions).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Font generator options', () => {
test('`getGeneratorOptions` calls `getCodepoints` with input assets and codepoints', () => {
const codepointsIn = { foo: 'bar' };
const options = { codepoints: codepointsIn } as any;
const assets = ({} as unknown) as AssetsMap;
const assets = {} as unknown as AssetsMap;

getGeneratorOptions(options, assets);

Expand All @@ -109,7 +109,7 @@ describe('Font generator options', () => {

test('`getGeneratorOptions` correctly processes templates option', () => {
const options = { templates: { html: 'user-template.hbs' } } as any;
const assets = ({} as unknown) as AssetsMap;
const assets = {} as unknown as AssetsMap;

expect(getGeneratorOptions(options, assets).templates.css).toMatch(
'/foo/templates-dir/css.hbs'
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cssGen from '../css';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test-font',
Expand Down
8 changes: 4 additions & 4 deletions src/generators/asset-types/__tests__/eot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import eotGen from '../eot';

const ttf2eot = (_ttf2eot as unknown) as jest.Mock<typeof _ttf2eot>;
const ttf2eot = _ttf2eot as unknown as jest.Mock<typeof _ttf2eot>;

jest.mock('ttf2eot', () =>
jest.fn(content => ({ buffer: `::eot(${content})::` }))
);

const mockOptions = (eotOptions = { __mock: 'options__' } as any) =>
(({} as unknown) as FontGeneratorOptions);
({} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`EOT` font generator', () => {
beforeEach(() => ttf2eot.mockClear());

test('resolves with the correctly processed return value of `ttf2eot`', async () => {
const result = await eotGen.generate(mockOptions(), ttf);
const ttfArr = new Uint8Array(('::ttf::' as unknown) as any[]);
const ttfArr = new Uint8Array('::ttf::' as unknown as any[]);

expect(ttf2eot).toHaveBeenCalledTimes(1);
expect(ttf2eot).toHaveBeenCalledWith(ttfArr);
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sassGen from '../sass';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/scss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scssGen from '../scss';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test',
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import svgGen from '../svg';

const SVGIcons2SVGFontStream = (_SVGIcons2SVGFontStream as unknown) as jest.Mock<
const SVGIcons2SVGFontStream = _SVGIcons2SVGFontStream as unknown as jest.Mock<
typeof _SVGIcons2SVGFontStream
>;

Expand Down Expand Up @@ -45,7 +45,7 @@ jest.mock('svgicons2svgfont', () => {
});

const mockOptions = (svgOptions = { __mock: 'options__' } as any) =>
(({
({
name: 'foo',
fontHeight: 1,
descent: 2,
Expand All @@ -56,7 +56,7 @@ const mockOptions = (svgOptions = { __mock: 'options__' } as any) =>
foo: { id: 'foo', absolutePath: '/root/foo.svg' },
bar: { id: 'bar', absolutePath: '/root/bar.svg' }
}
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

describe('`SVG` font generator', () => {
beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import ttfGen from '../ttf';

const svg2ttf = (_svg2ttf as unknown) as jest.Mock<typeof _svg2ttf>;
const svg2ttf = _svg2ttf as unknown as jest.Mock<typeof _svg2ttf>;

jest.mock('svg2ttf', () =>
jest.fn(content => ({ buffer: `::ttf(${content})::` }))
);

const mockOptions = (ttfOptions = { __mock: 'options__' } as any) =>
(({
({
formatOptions: { [FontAssetType.TTF]: ttfOptions }
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

const svg = '::svg::';

Expand Down
10 changes: 5 additions & 5 deletions src/generators/asset-types/__tests__/woff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import woffGen from '../woff';

const ttf2woff = (_ttf2woff as unknown) as jest.Mock<typeof _ttf2woff>;
const ttf2woff = _ttf2woff as unknown as jest.Mock<typeof _ttf2woff>;

jest.mock('ttf2woff', () =>
jest.fn(content => ({ buffer: `::woff(${content})::` }))
);

const mockOptions = (woffOptions = { __mock: 'options__' } as any) =>
(({
({
formatOptions: { [FontAssetType.WOFF]: woffOptions }
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`WOFF` font generator', () => {
beforeEach(() => {
Expand All @@ -23,7 +23,7 @@ describe('`WOFF` font generator', () => {

test('resolves with the correctly processed return value of `ttf2woff`', async () => {
const result = await woffGen.generate(mockOptions(), ttf);
const ttfArr = new Uint8Array(('::ttf::' as unknown) as any[]);
const ttfArr = new Uint8Array('::ttf::' as unknown as any[]);

expect(ttf2woff).toHaveBeenCalledTimes(1);
expect(ttf2woff).toHaveBeenCalledWith(ttfArr, { __mock: 'options__' });
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/woff2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import _ttf2woff2 from 'ttf2woff2';
import { FontGeneratorOptions } from '../../../types/generator';
import woff2Gen from '../woff2';

const ttf2woff2 = (_ttf2woff2 as unknown) as jest.Mock<typeof _ttf2woff2>;
const ttf2woff2 = _ttf2woff2 as unknown as jest.Mock<typeof _ttf2woff2>;

jest.mock('ttf2woff2', () =>
jest.fn(content => ({ buffer: `::woff2(${content})::` }))
);

const mockOptions = (woffOptions = { __mock: 'options__' } as any) =>
(({} as unknown) as FontGeneratorOptions);
({} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`WOFF2` font generator', () => {
beforeEach(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/generators/asset-types/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ const generator: FontGenerator = {
formatOptions: { ts } = {}
}) => {
const quote = Boolean(ts?.singleQuotes) ? "'" : '"';
const generateKind: Record<string, boolean> = (Boolean(ts?.types?.length)
? ts.types
: ['enum', 'constant', 'literalId', 'literalKey']
const generateKind: Record<string, boolean> = (
Boolean(ts?.types?.length)
? ts.types
: ['enum', 'constant', 'literalId', 'literalKey']
)
.map(kind => ({ [kind]: true }))
.reduce((prev, curr) => Object.assign(prev, curr), {});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetIconIdFn } from '../../types/misc';
import { DEFAULT_OPTIONS } from '../../constants';
import { writeFile } from '../fs-async';

const writeFileMock = (writeFile as any) as jest.Mock;
const writeFileMock = writeFile as any as jest.Mock;

jest.mock('path');
jest.mock('glob');
Expand Down
6 changes: 3 additions & 3 deletions src/utils/__tests__/fs-async.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFile, writeFile, stat, checkPath } from '../fs-async';
import * as fs from 'fs';

const readFileMock = (fs.readFile as any) as jest.Mock;
const writeFileMock = (fs.writeFile as any) as jest.Mock;
const statMock = (fs.stat as any) as jest.Mock;
const readFileMock = fs.readFile as any as jest.Mock;
const writeFileMock = fs.writeFile as any as jest.Mock;
const statMock = fs.stat as any as jest.Mock;

jest.mock('fs', () => ({
readFile: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../validation';
import { checkPath } from '../fs-async';

const checkPathMock = (checkPath as any) as jest.Mock;
const checkPathMock = checkPath as any as jest.Mock;

jest.mock('../fs-async', () => ({ checkPath: jest.fn() }));

Expand Down
34 changes: 17 additions & 17 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ export const parseFunction = (value: Function) => {
return value;
};

export const listMembersParser = <T extends string>(allowedValues: T[]) => (
values: string[]
) => {
for (const value of values) {
if (!allowedValues.includes(value as any)) {
throw new Error(
[
`${value} is not valid`,
`accepted values are: ${allowedValues.join(', ')}`
].join(' - ')
);
export const listMembersParser =
<T extends string>(allowedValues: T[]) =>
(values: string[]) => {
for (const value of values) {
if (!allowedValues.includes(value as any)) {
throw new Error(
[
`${value} is not valid`,
`accepted values are: ${allowedValues.join(', ')}`
].join(' - ')
);
}
}
}

return values as T[];
};
return values as T[];
};

export const removeUndefined = (object: Object) => {
for (const key of Object.keys(object)) {
Expand All @@ -68,9 +68,9 @@ export const parseBoolean = (val: any) => {
throw new Error(`must be a boolean value`);
};

const skipIfMatching = (match: any) => (fn: (value: any, cur?: any) => any) => (
val: any
) => (val === match ? match : fn(val));
const skipIfMatching =
(match: any) => (fn: (value: any, cur?: any) => any) => (val: any) =>
val === match ? match : fn(val);

export const parseDir = async (dirname: string) => {
if ((await checkPath(dirname, 'directory')) === false) {
Expand Down

0 comments on commit b6c90de

Please sign in to comment.