From 99f7029cae7e36dbf0e76aadf410d47affbae2c1 Mon Sep 17 00:00:00 2001 From: Netanel Basal Date: Tue, 1 Nov 2022 19:04:10 +0200 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20test=20for=20type?= =?UTF-8?q?=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svg-generator/__snapshots__/index.spec.js.snap | 10 ++++++++++ svg-generator/generator.ts | 12 +++++++----- svg-generator/index.spec.ts | 5 ++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/svg-generator/__snapshots__/index.spec.js.snap b/svg-generator/__snapshots__/index.spec.js.snap index f57cb1c..ef379fc 100644 --- a/svg-generator/__snapshots__/index.spec.js.snap +++ b/svg-generator/__snapshots__/index.spec.js.snap @@ -76,3 +76,13 @@ export const groupTwoIcons = [childOneIcon, childTwoIcon]; }, ] `; + +exports[`createTree should create the type file 1`] = ` +"export {}; +declare global { + interface SvgIcons { + icons: 'foo' | 'bar' | 'foo-bar'; + } +} +" +`; diff --git a/svg-generator/generator.ts b/svg-generator/generator.ts index f7463ed..9e80492 100644 --- a/svg-generator/generator.ts +++ b/svg-generator/generator.ts @@ -17,7 +17,7 @@ export function generateSVGIcons(config: Config | null) { removeOldIcons(resolve(mergedConfig.outputPath)); const virtualTree = createTree(mergedConfig.srcPath, mergedConfig.outputPath, mergedConfig); - const names: string[] = []; + let names: string[] = []; if (mergedConfig.rootBarrelFile) { const allExports = virtualTree @@ -27,16 +27,18 @@ export function generateSVGIcons(config: Config | null) { outputFileSync(join(mergedConfig.outputPath, `${mergedConfig.rootBarrelFileName}.ts`), allExports, { encoding: 'utf-8', }); + + names = virtualTree.filter(({ name }) => name !== INDEX).map(({ name }) => name); } else { virtualTree.forEach(({ path, content, name }) => { name !== INDEX && names.push(name); outputFileSync(path, content, { encoding: 'utf-8' }); }); - - outputFileSync(`${mergedConfig.typesPath}/types/svg.d.ts`, createTypeFile(names), { - encoding: 'utf-8', - }); } + + outputFileSync(`${mergedConfig.typesPath}/types/svg.d.ts`, createTypeFile(names), { + encoding: 'utf-8', + }); } function removeOldIcons(outputPath: string) { diff --git a/svg-generator/index.spec.ts b/svg-generator/index.spec.ts index 3175496..b9e2367 100644 --- a/svg-generator/index.spec.ts +++ b/svg-generator/index.spec.ts @@ -1,11 +1,11 @@ import mock from 'mock-fs'; +import { createTypeFile } from './create-types'; import { createTree } from './tree'; import { defaults } from './types'; const srcPath = `src/assets/svg`; describe('createTree', () => { - it('should create the correct tree', () => { mock({ [`${srcPath}/one.svg`]: 'one', @@ -27,4 +27,7 @@ describe('createTree', () => { expect(result).toMatchSnapshot(); }); + it('should create the type file', () => { + expect(createTypeFile(['foo', 'bar', 'foo-bar'])).toMatchSnapshot(); + }); });