Repository navigation
DF-1509: Convert the server, page controller and component tests to JavaScript with JSDoc - #506
Open
alexluckett wants to merge 7 commits into
Open
alexluckett wants to merge 7 commits into
alexluckett wants to merge 7 commits into
Conversation
…elper to JavaScript with JSDoc
The AutocompleteField, CheckboxesField, DatePartsField, DeclarationField, Details, EastingNorthingField, EmailAddressField, custom validation message and default translator tests are now .js files typed with JSDoc and checked by tsc.
The FileUploadField, GeospatialField, HiddenField, Html, InsetText, LatLongField, List, LocationFieldBase, LocationFieldHelpers and Markdown tests are now .js files typed with JSDoc and checked by tsc.
…avaScript with JSDoc
|
jbarnsley10
reviewed
Nov 25, 2026
| expect(errors.advancedSettingsErrors).not.toBeEmpty() | ||
| }) | ||
|
|
||
| /* eslint-disable jsdoc/valid-types -- the JSDoc type parser rejects a method signature in a type literal; tsc reads it */ |
Contributor
There was a problem hiding this comment.
It's annoying that you have to do this
jbarnsley10
reviewed
Nov 25, 2026
| function buildRequest(path: string, query = {}): FormContextRequest { | ||
| /** | ||
| * @param {string} path | ||
| * @returns {FormContextRequest} |
Contributor
There was a problem hiding this comment.
Missing JSdoc for query param
jbarnsley10
reviewed
Nov 25, 2026
|
|
||
| jest.mock('~/src/server/plugins/engine/helpers') | ||
|
|
||
| function buildMockModel( |
jbarnsley10
reviewed
Nov 25, 2026
|
|
||
| jest.mock('~/src/server/plugins/engine/services/formsService.js') | ||
| jest.mock('~/src/server/plugins/engine/services/uploadService.js') | ||
| jest.mock('~/src/server/plugins/engine/helpers.ts', () => { |
Contributor
There was a problem hiding this comment.
Should this be a .js file, or is that in a later PR?
jbarnsley10
approved these changes
Nov 25, 2026
jbarnsley10
left a comment
Contributor
There was a problem hiding this comment.
LGTM - took a loooong time to go through.
A few tiny comments but those issues are clearly not causing a lint error.
One suggestion is to alphabetic order the footer imports on each line (not necessarily the line order, just the order of types listed per line being imported). Apparently there are 6 files where the types are out of order
map/routes/index.js:277
postcode-lookup/routes/index.js:336
formsService.js:48
geospatial-map.js:1137
geospatial-map.js:1141
file-form-service.js:178
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Proposed change
Part of the TypeScript to JavaScript migration (v6), this PR is stacked on the lint settings PR and converts 60 test files, together with the
test/helpers/validation-helpershelper, to JavaScript with JSDoc types. It covers the server, route, repeater and service tests, the page controller tests, and the component and component helper tests; no source files change. Converting the tests before the code they test means that each later source PR is checked by tests that have not changed. Each area is a separate commit, for reviewers who would rather read it in steps.@importblock at the end of each file, annotations are now@type,@paramand@returns,ascasts are JSDoc casts, andsatisfiesis@satisfies.jest.mocked(x), so;(getPage as jest.Mock).mockReturnValue(page)becomesjest.mocked(getPage).mockReturnValue(page). Prettier, configured without semicolons, cannot keep a JSDoc cast at the start of a line. When a typed mock would reject a partial value, the cast goes inside the call instead:jest.mocked(/** @type {jest.Mock} */ (getCacheService)). Becausejest.mockedsimply returns its argument, this is the only change at runtime (inroutes/index.testandpostcode-lookup.test).toEqual<FormSubmissionError[]>(…)is nowtoEqual(/** @satisfies {FormSubmissionError[]} */ (…)), which keeps the same check, since JavaScript has no way to pass a type argument.tscbut not by the JSDoc lint parser: the method signatures inTestableFileUploadPageControllerand in two casts inDatePartsField.test, and the mapped type invalidation-helpers. These sit inside ajsdoc/valid-typesdisable block.LocationFieldHelpers.test.jshas one new lint disable.@typescript-eslint/no-base-to-stringchecks the type oflabelbefore the JSDoc cast is applied, so it reportslabel.toString()even though the cast giveslabelatoStringmethod; the disable comment explains this.TelephoneNumberField.testhad an@importcomment part-way through the file. TypeScript ignored it but JavaScript does not, so it has been merged into the block at the end of the file.helpers/state.test,const params = {}now has/** @type {FormQuery} */. In JavaScript an empty object literal can grow, so without the annotationtscwill not accept it as theFormQuerythatstripParamexpects.eslint-disablecomments for rules that only apply to TypeScript have been removed, as lint reports them as unused in JavaScript.@ts-expect-errorcomments on partial mocks are unchanged, becausetscstill reports an error under each of them.PaymentField.test.jsincludes thegetReferencemocks added onmainwith the payment reference fix.jest.mock('…/x.ts')paths that point at source files still written in TypeScript are left as they are; the source PRs will update them.Apart from the
jest.mockedcalls, each converted test compiles to the same code as before. The full test suite gives the same results as onmain(2,583 passed, 13 skipped).Jira ticket: DF-1509
Type of change
Checklist
README.mdanddocs/*(where appropriate, e.g. new features).npm run test).npm run lint).npm run format).