Repository navigation
meta(core): convert unit/model tests to TypeScript - #18564
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
🔇 Additional comments: 18
packages/core/test/unit/model/bulk-create.test.ts: 1
1-5: LGTM!Also applies to: 25-25
packages/core/test/unit/model/destroy.test.ts: 2
9-38: LGTM!
5-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Replace
getTestDialectTeaserin the converted suite titles.The repository is phasing out
getTestDialectTeaser(). New and updated tests should not use it. This PR rewrites this file as a new TypeScript file, so this is the right time to drop the helper. Use a plain title instead, asbulk-create.test.tsdoes withdescribe('Model#bulkCreate', ...).update.test.tsLine 5-7 andupsert.test.tsLine 5-7 have the same pattern. Update them in the same way.♻️ Proposed change
-import { sequelize as current, getTestDialectTeaser } from '../../support'; +import { sequelize as current } from '../../support'; -describe(getTestDialectTeaser('Model'), () => { +describe('Model', () => {Based on learnings: "do not use
Support.getTestDialectTeaser()for dialect-specific test naming/description... new or updated tests should avoid it."Source: Learnings
packages/core/test/unit/model/update.test.ts: 1
8-122: LGTM!packages/core/test/unit/model/upsert.test.ts: 1
8-98: LGTM!packages/core/test/unit/model/validation.test.ts: 5
1-24: LGTM!
191-269: LGTM!
298-365: LGTM!
429-547: LGTM!
584-882: LGTM!packages/core/test/unit/model/count.test.ts: 2
9-38: LGTM!Also applies to: 40-64
5-7: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Remove
getTestDialectTeaserfrom the new TypeScript test files.These tests are not dialect-specific. The repository is phasing out
getTestDialectTeaser()for new or updated tests. The same pattern is infind-all.test.ts(Line 6, Line 13),find-and-count-all.test.ts(Line 4, Line 6), andfind-one.test.ts(Line 5, Line 7). Use a plain describe title, asfind-create-find.test.tsalready does.♻️ Proposed change
-import { beforeAll2, sequelize as current, getTestDialectTeaser } from '../../support'; +import { beforeAll2, sequelize as current } from '../../support'; -describe(getTestDialectTeaser('Model'), () => { +describe('Model', () => {Based on learnings: "new or updated tests should avoid it and use the currently recommended convention for dialect-specific descriptions."
Source: Learnings
packages/core/test/unit/model/find-all.test.ts: 1
1-157: LGTM!packages/core/test/unit/model/find-and-count-all.test.ts: 1
1-38: LGTM!packages/core/test/unit/model/find-create-find.test.ts: 1
1-4: LGTM!Also applies to: 13-23, 32-41, 53-60, 72-72
packages/core/test/unit/model/find-one.test.ts: 1
1-18: LGTM!Also applies to: 20-27, 40-40, 57-57
packages/core/test/unit/model/underscored.test.ts: 1
1-120: LGTM!packages/core/test/unit/model/include.test.ts: 1
5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Replace
getTestDialectTeaserin the updated test naming.This file still calls
getTestDialectTeaser('Model')in the changeddescribeline. The retrieved learning says this helper is being phased out. Updated tests should use the recommended convention for dialect-specific descriptions. Confirm the convention with the maintainers and apply it to this file. Apply the same change tounderscored.test.ts.The helper still works, so this is a low-impact consistency issue.
Based on learnings: "do not use
Support.getTestDialectTeaser()for dialect-specific test naming/description" inpackages/**/test/**/*.test.{js,ts}.Also applies to: 13-13
Source: Learnings
ℹ️ Review info
⚙️ Run configuration
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
88fad744-fc14-41db-97ad-20e137d9805d
📒 Files selected for processing: 19
packages/core/test/unit/model/bulk-create.test.tspackages/core/test/unit/model/count.test.jspackages/core/test/unit/model/count.test.tspackages/core/test/unit/model/destroy.test.jspackages/core/test/unit/model/destroy.test.tspackages/core/test/unit/model/find-all.test.jspackages/core/test/unit/model/find-all.test.tspackages/core/test/unit/model/find-and-count-all.test.jspackages/core/test/unit/model/find-and-count-all.test.tspackages/core/test/unit/model/find-create-find.test.tspackages/core/test/unit/model/find-one.test.tspackages/core/test/unit/model/include.test.tspackages/core/test/unit/model/underscored.test.jspackages/core/test/unit/model/underscored.test.tspackages/core/test/unit/model/update.test.jspackages/core/test/unit/model/update.test.tspackages/core/test/unit/model/upsert.test.jspackages/core/test/unit/model/upsert.test.tspackages/core/test/unit/model/validation.test.ts
💤 Files with no reviewable changes: 7
- packages/core/test/unit/model/update.test.js
- packages/core/test/unit/model/underscored.test.js
- packages/core/test/unit/model/count.test.js
- packages/core/test/unit/model/find-and-count-all.test.js
- packages/core/test/unit/model/destroy.test.js
- packages/core/test/unit/model/upsert.test.js
- packages/core/test/unit/model/find-all.test.js
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- find-and-count-all: the try/catch also caught the error thrown when findAndCountAll resolved, so the test passed either way. The unhandledRejection listener and the stubs were never removed. - find-all: await the findAll call instead of leaving it floating. - destroy, update: check the rejection message instead of a bare rejected. - upsert: assert that the upsert is fulfilled, not just that it does not reject with a ValidationError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The len$, max$ and min$ entries were meant to cover the shorthand form
(`len: [2, 4]` instead of `len: { args: [2, 4] }`), but the loop
stripped the $ before looking the entry up, so they re-ran len, max and
min instead.
Each check now lists its arguments once, and the generator derives every
form from them: an options object with and without a custom message, the
arguments passed directly, and `true` for validators that accept it.
Shorthand failures assert the default message, as there is nowhere to
put a custom one. The options objects are created per test; previously
the generator mutated the shared spec, so tests depended on their order.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the getTestDialectTeaser wrappers with plain titles (Model.count, Model.findAll, Model.update, ...), use the sequelize instance from the support file directly instead of aliasing it as current, and flatten describes that wrapped a single test or that only wrapped a dialect check. Model#bulkCreate becomes Model.bulkCreate, as it is a static method, and the findAndCountAll rejection test now checks the error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test returned early on dialects without ARRAY support, so it was reported as passing without checking anything. Co-Authored-By: Claude Opus 5.5 <[email protected]>
d6de1e6 to
93a7265
Compare
* origin/main: (54 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/postgres/src/query-interface.js
* origin/main: (26 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/core/src/abstract-dialect/query-generator.js # packages/core/src/abstract-dialect/query-interface-typescript.ts # packages/core/test/unit/model/bulk-create.test.js # packages/core/test/unit/sql/insert.test.js
Pull Request Checklist
Description of Changes
This converts the 12 remaining JavaScript tests in
test/unit/modelto TypeScript, so the folder is now TypeScript only. It follows #18563, which did the same fortest/unit/instance, and the two PRs touch different files. The first commit is the conversion, the second one fixes the assertions, the third one reworks the generated validator tests, and the last two follow up on the review of #18563.The mocha
thiscontext is replaced withbeforeEach2/beforeAll2or plainletvariables. For the small files where nearly every line usedthis, git shows a delete and an add instead of a rename.Suite names
As in #18563, the
getTestDialectTeaser('Model')wrappers are replaced by the method each suite tests:Model.count,Model.destroy,Model._warnOnInvalidOptionsandModel.findAll,Model.findAndCountAll,Model.findOne,Model._expandIncludeAll,Model options.underscored,Model.updateandModel.upsert.Model#bulkCreatebecomesModel.bulkCreate, because it is a static method. The files usesequelizedirectly instead of aliasing it ascurrent.Describes that wrapped a single test (
bulkCreate'svalidations,findAndCountAll'sshould handle promise rejection), or that only wrapped a dialect check (upsert), are flattened.upsertnow returns early from the suite instead. Nested describes that group tests sharing a fixture are kept.Typing notes
The typings don't cover these internals, so the tests use small local types or casts, each with a comment:
_warnOnInvalidOptions,_conformIncludes,_expandIncludeAllqueryRawreturning the model instance when called with theinstanceoption (as any, as in meta(core): convert unit/instance tests to TypeScript #18563)upsertKeysoption passed tobulkInsertSequelize.ModelandSequelize.ValidationErrorare runtime aliases that theSequelizeclass typings don't declare, so the tests importModelandValidationErrorinstead.Intentionally invalid inputs are marked with
@ts-expect-error: class instances aswhere, a string asattributes, and errors constructed without arguments. One more@ts-expect-errorsits ongetAssociationWithModel(Task). Its typings require the alias, butmodel.jstreats it as optional when there is only one association. That one should probably be fixed in the typings in a follow-up.Smaller changes:
bulk-create: removedunderscored: truefrom an attribute definition. It isn't an attribute option and had no effect, as the expectedpurchaseCountcolumn shows.destroy: removed the stub and thedeloptions/cloneOptionssetup, which no test used.validation: removedawaitfrom 8 sinon-chai assertions. They aren't promises (await-thenable), so the assertions behave exactly as before.Assertions that could not fail, or were weaker than they look
find-and-count-all: the test wasThe
catchalso caught thethrow new Error(), so the test passed whether or notfindAndCountAllrejected. It now awaits.to.be.rejected. Theprocess.on('unhandledRejection')listener it added was never removed, and the stubs were reset instead of restored. Both are cleaned up inafternow. (IffindAndCountAllregressed to leaving thecountrejection unhandled, mocha's own handler would crash the whole run. I checked this by mutating the builtlib/model.js, so the regression doesn't depend on the listener to be caught.)find-all:MyModel.findAll()was left floating (no-floating-promises). It is awaited now.destroy/update: "can detect complex objects" used a bare.to.be.rejected. They now check the actual messages,Invalid value received for the "where" option.andExpected plain object, array or sequelize method in the options.where parameter.upsert:.not.to.be.rejectedWith(ValidationError)also passed if the call rejected with any other error. It is now.to.be.fulfilled.Shorthand validator forms were never tested
In
validation.test, thelen$,max$andmin$entries were meant to cover the shorthand form (len: [2, 4]instead oflen: { args: [2, 4] }). The loop stripped the$before it looked upchecks[validator], so they re-ranlen/max/minunder the same titles. This has been the case since 2015.The third commit reworks the generator. Each check lists its arguments once, and the generator derives these forms from them:
{ args }and{ args, msg }: must reject the failing values with the custom message, and accept the passing oneslen: [2, 4],max: 23,isUUID: 4, …), andtruefor validators without arguments (andisAlpha/isAlphanumeric, which accept both): these must reject with the defaultValidation <name> on name failedmessage, because the shorthand has nowhere to put a custom oneSo every validator that takes arguments now gets shorthand coverage, not just the three
$entries. The old generator also addedmsg/argsto the sharedspecobject, so later tests saw leftovers from earlier ones. The options are now created per test. The old{ args: true, msg }form for validators without arguments is gone. It was the same as{ args, msg }for every validator that takes arguments.To check that this coverage is real, I made the built
_extractValidatorArgsignore shorthand arguments (test.args || []). 16 of the new tests fail, while the old file still passed all of its tests.Two changes to the number of tests:
len/max/minunder the$titles.validation.test'sshould allow $inreturned early inside the test on dialects withoutARRAYsupport, so it was reported as passing without checking anything. It is now only registered on dialects that support arrays.Apart from those, the test counts per dialect are the same as before the conversion.
Verified:
tsc -b test/tsconfig.json, eslint, prettier, andtest/unit/modelon all 9 dialects.List of Breaking Changes
None, tests only.
🤖 Generated with Claude Code
Summary by CodeRabbit