Skip to content

Commit

Permalink
Enabled type check for test (#573)
Browse files Browse the repository at this point in the history
* chore: enabled type check for test

* fix: fix types

* chore: separate tscofnig for build

* chore: fix types
  • Loading branch information
kmkzt authored Jan 31, 2023
1 parent 99892e8 commit e6d0b98
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/animation/src/animation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions packages/animation/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true
},
"exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"]
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/svg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true
},
"exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"]
}
2 changes: 1 addition & 1 deletion packages/img-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/img-trace/src/__test__/loadPngData.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/img-trace/src/palette.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions packages/img-trace/src/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 * */
Expand Down
2 changes: 1 addition & 1 deletion packages/img-trace/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rootDir": "./src",
"outDir": "./lib",
"declaration": true,
"declarationDir": "./lib",
"declarationDir": "./lib"
},
"include": ["src/**/*"]
}
7 changes: 7 additions & 0 deletions packages/img-trace/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true
},
"exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"]
}
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/react/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true
},
"exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,5 +21,5 @@
"plugins": [],
"typeRoots": ["node_modules/@types"]
},
"exclude": ["node_modules", "**/*.test.ts", "**/__test__/**/*"]
"exclude": ["node_modules"]
}

0 comments on commit e6d0b98

Please sign in to comment.