From e6d0b98c668beb813c2ea854f2c078f4dec408f4 Mon Sep 17 00:00:00 2001 From: kamei Date: Wed, 1 Feb 2023 00:12:03 +0900 Subject: [PATCH] Enabled type check for test (#573) * chore: enabled type check for test * fix: fix types * chore: separate tscofnig for build * chore: fix types --- packages/animation/package.json | 2 +- packages/animation/src/animation.test.ts | 2 +- packages/animation/tsconfig.lib.json | 7 +++++++ packages/core/package.json | 2 +- packages/core/src/svg.test.ts | 19 ++++++++++--------- packages/core/tsconfig.lib.json | 7 +++++++ packages/img-trace/package.json | 2 +- .../img-trace/src/__test__/loadPngData.ts | 4 +++- packages/img-trace/src/palette.test.ts | 2 +- packages/img-trace/src/trace.test.ts | 4 ++-- packages/img-trace/tsconfig.json | 2 +- packages/img-trace/tsconfig.lib.json | 7 +++++++ packages/react/package.json | 2 +- packages/react/tsconfig.lib.json | 7 +++++++ tsconfig.json | 4 ++-- 15 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 packages/animation/tsconfig.lib.json create mode 100644 packages/core/tsconfig.lib.json create mode 100644 packages/img-trace/tsconfig.lib.json create mode 100644 packages/react/tsconfig.lib.json diff --git a/packages/animation/package.json b/packages/animation/package.json index 69eae1cf0..15f8f2437 100644 --- a/packages/animation/package.json +++ b/packages/animation/package.json @@ -39,7 +39,7 @@ "dev:tsc": "NODE_ENV=development tsc -w", "build": "npm-run-all -p lib:*", "lib:rollup": "NODE_ENV=production rollup -c", - "lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly", + "lib:tsc": "NODE_ENV=production tsc -p ./tsconfig.lib.json", "clear": "rimraf lib/*", "typecheck": "tsc --noEmit", "lint": "eslint ./src --ext .js,.ts,.tsx", diff --git a/packages/animation/src/animation.test.ts b/packages/animation/src/animation.test.ts index d1e6f76bb..3cb2908cb 100644 --- a/packages/animation/src/animation.test.ts +++ b/packages/animation/src/animation.test.ts @@ -25,7 +25,7 @@ describe('animation.ts', () => { // TODO Improve test pattern it('toAnimationElement', () => { const svg = generateAnimation() - const testAnimation: FrameAnimation = (paths, count) => { + const testAnimation: FrameAnimation = (paths, count: any) => { const update = [] for (let i = 0; i < paths.length; i += 1) { // Test property diff --git a/packages/animation/tsconfig.lib.json b/packages/animation/tsconfig.lib.json new file mode 100644 index 000000000..d9a8180b6 --- /dev/null +++ b/packages/animation/tsconfig.lib.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true + }, + "exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"] +} diff --git a/packages/core/package.json b/packages/core/package.json index 950f28c95..e1b38f844 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -38,7 +38,7 @@ "dev:tsc": "NODE_ENV=development tsc -w", "build": "npm-run-all -p lib:*", "lib:rollup": "NODE_ENV=production rollup -c", - "lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly", + "lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly -p ./tsconfig.lib.json", "clear": "rimraf lib/*", "typecheck": "tsc --noEmit", "lint": "eslint ./src --ext .js,.ts,.tsx", diff --git a/packages/core/src/svg.test.ts b/packages/core/src/svg.test.ts index 854218bea..d93040ce5 100644 --- a/packages/core/src/svg.test.ts +++ b/packages/core/src/svg.test.ts @@ -74,17 +74,17 @@ describe('svg.ts', () => { }) it('point is not overwritten', () => { clone.point = new Point(1.5, 1) - expect(cmd.point.x).toBe(1) + expect(cmd.point?.x).toBe(1) expect(clone.point.x).toBe(1.5) }) it('cl is not overwritten', () => { clone.cl = new Point(0.1, 0.1) - expect(cmd.cl.x).toBe(0.25) + expect(cmd.cl?.x).toBe(0.25) expect(clone.cl.x).toBe(0.1) }) it('cr is not overwritten', () => { clone.cr = new Point(1.2, 0.1) - expect(cmd.cr.x).toBe(0.75) + expect(cmd.cr?.x).toBe(0.75) expect(clone.cr.x).toBe(1.2) }) }) @@ -99,15 +99,15 @@ describe('svg.ts', () => { it('addCommand', () => { expect(path.commands.length).toBe(2) expect(path.commands[0].type).toBe(COMMAND_TYPE.MOVE) - expect(path.commands[0].point.x).toBe(1) - expect(path.commands[0].point.y).toBe(1) + expect(path.commands[0].point?.x).toBe(1) + expect(path.commands[0].point?.y).toBe(1) }) it('scale', () => { path.scale(2) expect(path.attrs.strokeWidth).toBe('2') expect(path.commands[0].type).toBe(COMMAND_TYPE.MOVE) - expect(path.commands[0].point.x).toBe(2) - expect(path.commands[0].point.y).toBe(2) + expect(path.commands[0].point?.x).toBe(2) + expect(path.commands[0].point?.y).toBe(2) }) describe('parseCommandString', () => { beforeEach(() => { @@ -138,10 +138,11 @@ describe('svg.ts', () => { const clone = origin .clone() .addCommand(new Command(COMMAND_TYPE.LINE, [2, 2])) - clone.commands[0].point = new Point(3, clone.commands[0].point.y) + + clone.commands[0].point = new Point(3, clone.commands[0].point?.y as any) expect(origin.commands.length).toBe(1) expect(clone.commands.length).toBe(2) - expect(origin.commands[0].point.x).toBe(1) + expect(origin.commands[0].point?.x).toBe(1) expect(clone.commands[0].point.x).toBe(3) }) describe('toJson and toElement', () => { diff --git a/packages/core/tsconfig.lib.json b/packages/core/tsconfig.lib.json new file mode 100644 index 000000000..d9a8180b6 --- /dev/null +++ b/packages/core/tsconfig.lib.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true + }, + "exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"] +} diff --git a/packages/img-trace/package.json b/packages/img-trace/package.json index 6308c5edb..eb3f14347 100644 --- a/packages/img-trace/package.json +++ b/packages/img-trace/package.json @@ -40,7 +40,7 @@ "dev:tsc": "NODE_ENV=development tsc -w", "build": "npm-run-all -p lib:*", "lib:rollup": "NODE_ENV=production rollup -c", - "lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly", + "lib:tsc": "NODE_ENV=production tsc -p ./tsconfig.lib.json", "clear": "rimraf lib/*", "typecheck": "tsc --noEmit", "lint": "eslint ./src --ext .js,.ts,.tsx", diff --git a/packages/img-trace/src/__test__/loadPngData.ts b/packages/img-trace/src/__test__/loadPngData.ts index 2a040c63d..341cad0f3 100644 --- a/packages/img-trace/src/__test__/loadPngData.ts +++ b/packages/img-trace/src/__test__/loadPngData.ts @@ -1,4 +1,6 @@ import { readFile } from 'fs' +// @ts-ignore +// eslint-disable-next-line import/no-unresolved import PNGReader from 'png.js' interface PngData { width: number @@ -15,7 +17,7 @@ export const loadPngData = (filepath: string, cb: (png: PngData) => void) => { const reader = new PNGReader(bytes) - reader.parse((err, png) => { + reader.parse((err: any, png: any) => { if (err) { console.log(err) throw err diff --git a/packages/img-trace/src/palette.test.ts b/packages/img-trace/src/palette.test.ts index ab606372b..92608a5b1 100644 --- a/packages/img-trace/src/palette.test.ts +++ b/packages/img-trace/src/palette.test.ts @@ -17,7 +17,7 @@ describe('palette.ts', () => { it(`colorQuantCycles: ${ colorQuantCycles || 'default' } ;numberOfColors: ${numberOfColors || 'default'}`, (done) => { - loadPngData(testimage, (imgd) => { + loadPngData(testimage, (imgd: any) => { expect( getTestResult( Palette.imageData(imgd, { colorQuantCycles, numberOfColors }) diff --git a/packages/img-trace/src/trace.test.ts b/packages/img-trace/src/trace.test.ts index 025b460d0..02764ef70 100644 --- a/packages/img-trace/src/trace.test.ts +++ b/packages/img-trace/src/trace.test.ts @@ -34,9 +34,9 @@ describe('trace.ts', () => { it(`${testname}`, (done) => { loadPngData(testimage, (png) => { const svg = new ImgTrace({ - palettes: Palette.imageData(png), + palettes: Palette.imageData(png as any), ...testopts, - }).load(png) + }).load(png as any) const data = svgObjectToElement(svg.toJson()).outerHTML /** DEBUG * */ diff --git a/packages/img-trace/tsconfig.json b/packages/img-trace/tsconfig.json index d9f828551..68705a6aa 100644 --- a/packages/img-trace/tsconfig.json +++ b/packages/img-trace/tsconfig.json @@ -4,7 +4,7 @@ "rootDir": "./src", "outDir": "./lib", "declaration": true, - "declarationDir": "./lib", + "declarationDir": "./lib" }, "include": ["src/**/*"] } diff --git a/packages/img-trace/tsconfig.lib.json b/packages/img-trace/tsconfig.lib.json new file mode 100644 index 000000000..d9a8180b6 --- /dev/null +++ b/packages/img-trace/tsconfig.lib.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true + }, + "exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"] +} diff --git a/packages/react/package.json b/packages/react/package.json index 21df03126..6265b52a6 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -37,7 +37,7 @@ "dev:tsc": "NODE_ENV=development tsc -w", "build": "npm-run-all -p lib:*", "lib:rollup": "NODE_ENV=production rollup -c", - "lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly", + "lib:tsc": "NODE_ENV=production tsc -p ./tsconfig.lib.json", "clear": "rimraf lib/*", "typecheck": "tsc --noEmit", "lint": "eslint ./src --ext .js,.ts,.tsx", diff --git a/packages/react/tsconfig.lib.json b/packages/react/tsconfig.lib.json new file mode 100644 index 000000000..d9a8180b6 --- /dev/null +++ b/packages/react/tsconfig.lib.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "emitDeclarationOnly": true + }, + "exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"] +} diff --git a/tsconfig.json b/tsconfig.json index 13e8923fc..ca5438de9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "baseUrl": ".", "target": "es6", // TODO: change esnext "module": "esnext", - "lib": ["esnext","es2020","es2019","es2018", "es2017", "dom"], + "lib": ["esnext", "es2020", "es2019", "es2018", "es2017", "dom"], "jsx": "react", "moduleResolution": "node", "allowSyntheticDefaultImports": true, @@ -21,5 +21,5 @@ "plugins": [], "typeRoots": ["node_modules/@types"] }, - "exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"] + "exclude": ["node_modules"] }