Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Add type checking, fix TypeScript configs, fix a few errors that show…
Browse files Browse the repository at this point in the history
… up in `tsc`
  • Loading branch information
eyelidlessness committed Dec 25, 2022
1 parent c851a0b commit b115307
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"exclude": ["node_modules"],
"include": ["src", "test", "typings"]
"include": ["src", "typings"]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions test/bad-external.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { NAMESPACES } from '../src/transformer';
import {
Document,
DocumentConstructor as Document,
getTransformedForm,
getTransformedModelDocument,
parser,
XMLDocument,
} from './shared';

import type {
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions test/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<a>', 'text/html').constructor;
const document = parser.parseFromString('<a>', '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;
4 changes: 0 additions & 4 deletions test/tsconfig.json

This file was deleted.

29 changes: 29 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -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"]
}
30 changes: 3 additions & 27 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit b115307

Please sign in to comment.