Skip to content

meta(core): convert unit/model tests to TypeScript - #18564

Merged
WikiRik merged 5 commits into
mainfrom
wikirik-agent/ts-unit-model-tests
Oct 20, 2026
Merged

WikiRik merged 5 commits into
mainfrom
wikirik-agent/ts-unit-model-tests

Conversation

@wikirik-agent

@wikirik-agent wikirik-agent commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

This converts the 12 remaining JavaScript tests in test/unit/model to TypeScript, so the folder is now TypeScript only. It follows #18563, which did the same for test/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 this context is replaced with beforeEach2/beforeAll2 or plain let variables. For the small files where nearly every line used this, 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._warnOnInvalidOptions and Model.findAll, Model.findAndCountAll, Model.findOne, Model._expandIncludeAll, Model options.underscored, Model.update and Model.upsert. Model#bulkCreate becomes Model.bulkCreate, because it is a static method. The files use sequelize directly instead of aliasing it as current.

Describes that wrapped a single test (bulkCreate's validations, findAndCountAll's should handle promise rejection), or that only wrapped a dialect check (upsert), are flattened. upsert now 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:

Sequelize.Model and Sequelize.ValidationError are runtime aliases that the Sequelize class typings don't declare, so the tests import Model and ValidationError instead.

Intentionally invalid inputs are marked with @ts-expect-error: class instances as where, a string as attributes, and errors constructed without arguments. One more @ts-expect-error sits on getAssociationWithModel(Task). Its typings require the alias, but model.js treats 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: removed underscored: true from an attribute definition. It isn't an attribute option and had no effect, as the expected purchaseCount column shows.
  • destroy: removed the stub and the deloptions/cloneOptions setup, which no test used.
  • validation: removed await from 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 was

    try {
      await this.User.findAndCountAll({});
      throw new Error();
    } catch {
      expect(this.stub.callCount).to.eql(0);
    }

    The catch also caught the throw new Error(), so the test passed whether or not findAndCountAll rejected. It now awaits .to.be.rejected. The process.on('unhandledRejection') listener it added was never removed, and the stubs were reset instead of restored. Both are cleaned up in after now. (If findAndCountAll regressed to leaving the count rejection unhandled, mocha's own handler would crash the whole run. I checked this by mutating the built lib/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. and Expected 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, the len$, max$ and min$ entries were meant to cover the shorthand form (len: [2, 4] instead of len: { args: [2, 4] }). The loop stripped the $ before it looked up checks[validator], so they re-ran len/max/min under 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 ones
  • the arguments passed directly (len: [2, 4], max: 23, isUUID: 4, …), and true for validators without arguments (and isAlpha/isAlphanumeric, which accept both): these must reject with the default Validation <name> on name failed message, because the shorthand has nowhere to put a custom one

So every validator that takes arguments now gets shorthand coverage, not just the three $ entries. The old generator also added msg/args to the shared spec object, 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 _extractValidatorArgs ignore 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:

  • The validator rework generates one more test than the old generator (172 instead of 171), because it adds shorthand forms but no longer re-runs len/max/min under the $ titles.
  • validation.test's should allow $in returned early inside the test on dialects without ARRAY support, 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, and test/unit/model on all 9 dialects.

List of Breaking Changes

None, tests only.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Migrated model test coverage to typed TypeScript and modern module syntax.
    • Expanded coverage for querying, counting, updating, deleting, creating, upserting, associations, validation, and attribute handling.
    • Added verification for field mapping, timestamp behavior, association options, invalid inputs, rejection handling, and subquery selection.
    • Improved test isolation, fixture management, and stub cleanup across model test suites.

@wikirik-agent
wikirik-agent requested a review from a team as a code owner October 20, 2026 01:47
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 86e0b118-5083-41df-a3d2-879cdc4ffde7
📥 Commits

Reviewing files that changed from the base of the PR and between d6de1e6 and 93a7265.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eaaf355a-643e-4367-ade3-b2b3344755c2
📥 Commits

Reviewing files that changed from the base of the PR and between 42c3083 and d6de1e6.

📒 Files selected for processing: 11
  • packages/core/test/unit/model/bulk-create.test.ts
  • packages/core/test/unit/model/count.test.ts
  • packages/core/test/unit/model/destroy.test.ts
  • packages/core/test/unit/model/find-all.test.ts
  • packages/core/test/unit/model/find-and-count-all.test.ts
  • packages/core/test/unit/model/find-one.test.ts
  • packages/core/test/unit/model/include.test.ts
  • packages/core/test/unit/model/underscored.test.ts
  • packages/core/test/unit/model/update.test.ts
  • packages/core/test/unit/model/upsert.test.ts
  • packages/core/test/unit/model/validation.test.ts
🚧 Files skipped from review as they are similar to previous changes: 5
  • packages/core/test/unit/model/count.test.ts
  • packages/core/test/unit/model/find-all.test.ts
  • packages/core/test/unit/model/underscored.test.ts
  • packages/core/test/unit/model/bulk-create.test.ts
  • packages/core/test/unit/model/update.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

Model unit tests were migrated to TypeScript across query, association, write, and validation suites. The changes add typed fixtures, expand coverage, and remove the corresponding JavaScript test files.

Changes: Model unit tests

Layer / File(s) Summary
Query and finder test coverage
packages/core/test/unit/model/count.test.*, packages/core/test/unit/model/find-all.test.*, packages/core/test/unit/model/find-and-count-all.test.*, packages/core/test/unit/model/find-create-find.test.ts, packages/core/test/unit/model/find-one.test.ts
Tests now use TypeScript fixtures and stubs. Coverage includes aggregate options, finder validation and attributes, rejection handling, limit injection, and internal method dispatch.
Include and association test coverage
packages/core/test/unit/model/include.test.ts, packages/core/test/unit/model/underscored.test.*
Tests cover include expansion, attributes, scopes, association normalization and lookup, subquery planning, and explicit field preservation.
Model write-operation test coverage
packages/core/test/unit/model/bulk-create.test.ts, packages/core/test/unit/model/destroy.test.*, packages/core/test/unit/model/update.test.*, packages/core/test/unit/model/upsert.test.*
Tests cover field mapping, invalid where values, input preservation, model selection, timestamps, and dialect-gated upsert behavior.
Typed validation tests and null handling
packages/core/test/unit/model/validation.test.ts
Validation tests now use typed fixtures, normalized cases, direct validation-error imports, dialect gating, and explicit null-value behavior checks.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Other

Suggested reviewers: ephys

Merge Risk: ⚪ Minimal · up to d6de1

This change converts existing model unit tests to TypeScript and tightens several assertions. It does not alter library behavior, so users face no direct impact, and it appears ready to merge once normal CI checks pass.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: converting the core model unit tests to TypeScript.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 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 getTestDialectTeaser in 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, as bulk-create.test.ts does with describe('Model#bulkCreate', ...). update.test.ts Line 5-7 and upsert.test.ts Line 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 getTestDialectTeaser from 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 in find-all.test.ts (Line 6, Line 13), find-and-count-all.test.ts (Line 4, Line 6), and find-one.test.ts (Line 5, Line 7). Use a plain describe title, as find-create-find.test.ts already 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 getTestDialectTeaser in the updated test naming.

This file still calls getTestDialectTeaser('Model') in the changed describe line. 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 to underscored.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" in packages/**/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
📥 Commits

Reviewing files that changed from the base of the PR and between 76de3cc and 30484f4.

📒 Files selected for processing: 19
  • packages/core/test/unit/model/bulk-create.test.ts
  • packages/core/test/unit/model/count.test.js
  • packages/core/test/unit/model/count.test.ts
  • packages/core/test/unit/model/destroy.test.js
  • packages/core/test/unit/model/destroy.test.ts
  • packages/core/test/unit/model/find-all.test.js
  • packages/core/test/unit/model/find-all.test.ts
  • packages/core/test/unit/model/find-and-count-all.test.js
  • packages/core/test/unit/model/find-and-count-all.test.ts
  • packages/core/test/unit/model/find-create-find.test.ts
  • packages/core/test/unit/model/find-one.test.ts
  • packages/core/test/unit/model/include.test.ts
  • packages/core/test/unit/model/underscored.test.js
  • packages/core/test/unit/model/underscored.test.ts
  • packages/core/test/unit/model/update.test.js
  • packages/core/test/unit/model/update.test.ts
  • packages/core/test/unit/model/upsert.test.js
  • packages/core/test/unit/model/upsert.test.ts
  • packages/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.

wikirik-agent and others added 5 commits October 20, 2026 23:06
- 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]>
@WikiRik
WikiRik force-pushed the wikirik-agent/ts-unit-model-tests branch from d6de1e6 to 93a7265 Compare October 20, 2026 14:06
@WikiRik
WikiRik merged commit 93dfcf8 into main Oct 20, 2026
@WikiRik
WikiRik deleted the wikirik-agent/ts-unit-model-tests branch October 20, 2026 22:59
papandreou added a commit to papandreou/sequelize that referenced this pull request Oct 23, 2026
* 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
papandreou added a commit to papandreou/sequelize that referenced this pull request Oct 23, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants