From b1153073295fc1408b6b0b04e935cfba9014d4b5 Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Sat, 24 Dec 2022 15:01:02 -0800 Subject: [PATCH] Add type checking, fix TypeScript configs, fix a few errors that show up in `tsc` --- jsconfig.json | 2 +- package.json | 5 +++-- test/bad-external.spec.ts | 7 +++---- test/shared.ts | 11 +++++------ test/tsconfig.json | 4 ---- tsconfig.base.json | 29 +++++++++++++++++++++++++++++ tsconfig.json | 30 +++--------------------------- 7 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 test/tsconfig.json create mode 100644 tsconfig.base.json diff --git a/jsconfig.json b/jsconfig.json index 192df60..c802454 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,4 +1,4 @@ { "exclude": ["node_modules"], - "include": ["src", "test", "typings"] + "include": ["src", "typings"] } diff --git a/package.json b/package.json index e820266..59f6a59 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,11 @@ "eslint-check": "eslint app.js src/**/*.js vite.config.ts test/**/*.ts", "eslint-fix": "eslint app.js src/**/*.js vite.config.ts test/**/*.ts --fix", "prettier-fix": "prettier --write .", - "test": "vitest run --coverage && npm run prettier-fix && npm run eslint-fix && node update-readme-with-shield-badge.js", + "test": "vitest run --coverage && npm run prettier-fix && npm run eslint-fix && tsc && node update-readme-with-shield-badge.js", "test:watch": "vitest", "build-docs": "rimraf docs && ./node_modules/.bin/jsdoc -c jsdoc.config.js", - "develop": "DEBUG=api,transformer,markdown,language node app.js & http-server test/forms -p 8081" + "develop": "DEBUG=api,transformer,markdown,language node app.js & http-server test/forms -p 8081", + "tsc": "tsc" }, "repository": { "type": "git", diff --git a/test/bad-external.spec.ts b/test/bad-external.spec.ts index 0973e4e..e249609 100644 --- a/test/bad-external.spec.ts +++ b/test/bad-external.spec.ts @@ -1,10 +1,9 @@ import { NAMESPACES } from '../src/transformer'; import { - Document, + DocumentConstructor as Document, getTransformedForm, getTransformedModelDocument, parser, - XMLDocument, } from './shared'; import type { @@ -129,7 +128,7 @@ describe('for incompatible forms that require preprocessing', () => { it('preprocess fn does nothing if not provided...', async () => { const doc = await getTransformedModelDocument('bad-external.xml'); - expect(doc).to.be.an.instanceOf(XMLDocument); + expect(doc).to.be.an.instanceOf(Document); expect(doc.getElementsByTagName('instance')).to.have.length(2); expect(doc.getElementById('existing')).to.not.be.null; expect(doc.getElementById('existing')!.getAttribute('src')).to.equal( @@ -145,7 +144,7 @@ describe('for incompatible forms that require preprocessing', () => { 'text/xml' ); - expect(preprocessedModel).to.be.an.instanceOf(XMLDocument); + expect(preprocessedModel).to.be.an.instanceOf(Document); expect( preprocessedModel.getElementsByTagName('instance') ).to.have.length(4); diff --git a/test/shared.ts b/test/shared.ts index 41668b2..f22721d 100644 --- a/test/shared.ts +++ b/test/shared.ts @@ -81,15 +81,14 @@ export const getTransformedModelDocument = async ( }; /** - * TODO: `@xmldom/xmldom` does not export `Document`. It's pretty linkely that @see {@link https://github.com/WebReflection/linkedom | `linkedom`}: + * TODO: `@xmldom/xmldom` does not export `Document`. It's pretty linkely that {@link https://github.com/WebReflection/linkedom linkedom}: * * 1. Does export it. * 2. Is a drop-in replacement for `@xmldom/xmldom`. * 3. Could very possibly go away soon anyway ;) */ -export const Document = parser.parseFromString('', 'text/html').constructor; +const document = parser.parseFromString('', 'text/html'); -/** - * TODO: this is at least temporarily a necessary fib. - */ -export const XMLDocument = Document; +export const DocumentConstructor = document.constructor; + +export type Document = typeof document; diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index d0791da..0000000 --- a/test/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../tsconfig.json", - "files": ["../typings/test.d.ts"] -} diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..0151e33 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "allowUnreachableCode": false, + "baseUrl": ".", + "checkJs": false, + "declaration": false, + "downlevelIteration": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "forceConsistentCasingInFileNames": true, + "inlineSourceMap": true, + "lib": ["ES2018"], + "module": "amd", + "moduleResolution": "node", + "noEmit": true, + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "es2018", + "types": ["node"] + }, + "exclude": ["node_modules", "typings/test.d.ts"], + "include": ["src", "typings"] +} diff --git a/tsconfig.json b/tsconfig.json index a78b4ab..95ac83f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,29 +1,5 @@ { - "compilerOptions": { - "allowJs": true, - "allowSyntheticDefaultImports": true, - "allowUnreachableCode": false, - "baseUrl": ".", - "checkJs": false, - "declaration": false, - "downlevelIteration": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "forceConsistentCasingInFileNames": true, - "inlineSourceMap": true, - "lib": ["ES2018"], - "module": "amd", - "moduleResolution": "node", - "noEmit": true, - "noFallthroughCasesInSwitch": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "strict": true, - "target": "es2018", - "types": ["node"] - }, - "exclude": ["node_modules", "typings/test.d.ts"], - "include": ["src", "test", "typings"] + "extends": "./tsconfig.base.json", + "include": ["test", "typings"], + "files": ["./typings/test.d.ts"] }