Skip to content

Commit

Permalink
Merge pull request #86 from mbland/improved-type-checking
Browse files Browse the repository at this point in the history
Improve JS type checking, bump vitest and others
  • Loading branch information
mbland committed Jan 18, 2024
2 parents 8cee0fb + 9a25a0c commit a3f6693
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 204 deletions.
12 changes: 6 additions & 6 deletions strcalc/src/main/frontend/components/calculator.js
Expand Up @@ -11,23 +11,23 @@ export default class Calculator {
* Initializes the Calculator within the document.
* @param {object} params - parameters made available to all initializers
* @param {Element} params.appElem - parent Element containing all components
* @param {import('./calculators.js').StrCalcDescriptors} params.calculators -
* @param {import("./calculators.js").StrCalcDescriptors} params.calculators -
* calculator implementations
* @param {Function} [params.instantiate] - alternative template instantiation
* function for testing
* @param {HandlebarsPrecompiler.TemplateRenderer} [params.render] -
* alternative template rendering function for testing
* @returns {void}
*/
init({ appElem, calculators, instantiate = Template }) {
init({ appElem, calculators, render = Template }) {
const calcOptions = Object.entries(calculators)
.map(([k, v]) => ({ value: k, label: v.label }))
const t = instantiate({ calcOptions })
const t = render({ calcOptions })
const [ form, resultElem ] = t.children

appElem.appendChild(t)

/** @type {(HTMLInputElement | null)} */
const numbers = document.querySelector('#numbers')
if (numbers === null) return console.error('missing numbers input')
if (numbers === null) return void console.error('missing numbers input')
numbers.focus()

form.addEventListener(
Expand Down
2 changes: 1 addition & 1 deletion strcalc/src/main/frontend/components/calculator.test.js
Expand Up @@ -102,7 +102,7 @@ describe('Calculator', () => {
}

new Calculator().init(
{ appElem: page.appElem, calculators, instantiate: BadTemplate }
{ appElem: page.appElem, calculators, render: BadTemplate }
)

expect(await vi.waitFor(loggedError))
Expand Down
12 changes: 9 additions & 3 deletions strcalc/src/main/frontend/components/template.d.ts
Expand Up @@ -4,8 +4,14 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

declare namespace HandlebarsPrecompiler {
export interface TemplateRenderer {
(context: any, options?: Handlebars.RuntimeOptions): DocumentFragment
}
}

declare module "*.hbs" {
export const RawTemplate: HandlebarsTemplateDelegate
export default function (context: any, options?: RuntimeOptions):
DocumentFragment
export const RawTemplate: Handlebars.TemplateDelegate
const Template: HandlebarsPrecompiler.TemplateRenderer
export default Template
}
12 changes: 0 additions & 12 deletions strcalc/src/main/frontend/jsconfig.json

This file was deleted.

24 changes: 11 additions & 13 deletions strcalc/src/main/frontend/package.json
Expand Up @@ -30,29 +30,27 @@
"test-ci": "pnpm lint && pnpm jsdoc && pnpm typecheck && vitest run --config ci/vitest.config.js && vitest run --config ci/vitest.config.browser.js",
"coverage": "vitest run --coverage",
"jsdoc": "jsdoc-cli-wrapper -c ./jsdoc.json .",
"typecheck": "npx -p typescript tsc -p jsconfig.json --noEmit --pretty"
"typecheck": "npx tsc"
},
"devDependencies": {
"@rollup/pluginutils": "^5.1.0",
"@stylistic/eslint-plugin-js": "^1.5.3",
"@types/chai": "^4.3.11",
"@vitest/browser": "^1.2.0",
"@vitest/coverage-istanbul": "^1.2.0",
"@vitest/coverage-v8": "^1.2.0",
"@vitest/ui": "^1.2.0",
"@stylistic/eslint-plugin-js": "^1.5.4",
"@vitest/browser": "^1.2.1",
"@vitest/coverage-istanbul": "^1.2.1",
"@vitest/coverage-v8": "^1.2.1",
"@vitest/ui": "^1.2.1",
"eslint": "^8.56.0",
"eslint-plugin-jsdoc": "^46.10.1",
"eslint-plugin-vitest": "^0.3.20",
"handlebars": "^4.7.8",
"jsdoc": "^4.0.2",
"jsdoc-cli-wrapper": "^1.0.5",
"jsdoc-cli-wrapper": "^1.0.6",
"jsdoc-plugin-typescript": "^2.2.1",
"jsdom": "^23.2.0",
"rollup-plugin-handlebars-precompiler": "^1.0.0",
"test-page-opener": "^1.0.5",
"rollup-plugin-handlebars-precompiler": "^1.0.2",
"test-page-opener": "^1.0.6",
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vitest": "^1.2.0",
"webdriverio": "^8.27.2"
"vitest": "^1.2.1",
"webdriverio": "^8.28.6"
}
}

0 comments on commit a3f6693

Please sign in to comment.