Skip to content

meta(core): convert unit/instance tests to TypeScript - #18563

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

WikiRik merged 4 commits into
mainfrom
wikirik-agent/ts-unit-instance-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 11 remaining JavaScript tests in test/unit/instance to TypeScript, so the folder is now TypeScript only. The diffs are kept small so git detects the renames. Imports become ESM, Support.x becomes named imports, and the mocha this context in get and is-soft-deleted is replaced with beforeEach2.

The commits can be reviewed separately: the first one is the conversion, the second one fixes the assertions, and the third one follows up on review.

Suite names

Following review, the getTestDialectTeaser('Instance') wrappers are gone. Each suite is named after the method it tests, Model.build for the static method and Model#get, Model#isSoftDeleted and Model#previous for instance methods, like the other files in the folder. The files use the sequelize instance from the support file directly instead of aliasing it as current.

The options tests describes in decrement, destroy, increment, reload, restore and save only scoped a queryRaw stub for a single test. They are removed: the stub is created in the test and restored with sinon.restore() after each test.

Issues found by the type checker

  • build.test: timestamp: false was a typo for timestamps: false.
  • reload.test / restore.test: deletedAt: {} declared an attribute with no type. It made no difference at runtime, because paranoid models add the deletedAt attribute themselves, so it is removed.
  • set.test stubs queryInterface.getNextPrimaryKeyValue, a @private method of the JS query interface that is missing from the typings. The stub stays in place, cast to that method's shape.
  • The queryRaw stubs in decrement, destroy and increment resolved to a made-up model-like object that nothing read. They now resolve to [[], 0], like the other TypeScript unit tests. save, restore and reload need a model-like result, because that is what queryRaw returns when it is called with instance or plain. Those stubs keep their values with an as any and a comment, since the queryRaw overloads can't express that return type.

Assertions that could not fail

The stricter lint rules for TypeScript (no-floating-promises) flagged that the "even if options are not given" tests for destroy, increment, restore and save were empty:

expect(() => {
  instance.destroy();
}).to.not.throw();

These methods are async, so they never throw synchronously, and the test passed even if the promise rejected. The tests now await expect(...).to.be.fulfilled. I checked that they do fail now when the stubbed result is wrong: save, restore and reload reject with a TypeError if queryRaw resolves to [[], 0].

In set.test, expect(user.get('date')).not.to.be.NaN could not fail for a Date object. It now checks getTime(). A duplicated assertion is also removed.

Verified: tsc -b test/tsconfig.json, eslint, prettier, and the instance unit tests on all 9 dialects (sqlite3, postgres, mysql, mariadb, mssql, db2, ibmi, snowflake, oracle).

List of Breaking Changes

None, tests only.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded instance-operation coverage for build, save, reload, restore, destroy, increment, and decrement scenarios.
    • Added validation for primary-key requirements and successful operations on persisted instances.
    • Added coverage for date and UUID defaults, JSON value handling, attribute getters, previous values, and soft-deletion status.
    • Converted instance setter tests to TypeScript with stronger type assertions.
    • Replaced duplicate JavaScript getter tests with equivalent TypeScript coverage.

wikirik-agent and others added 2 commits October 20, 2026 01:38
The "options are not given" tests for destroy, increment, restore and
save wrapped the returned promise in a synchronous `.to.not.throw()`,
so they passed even if the call rejected. They now await the promise.

In set.test.ts, `expect(date).not.to.be.NaN` could not fail for a Date
object, so it now checks getTime(), and a duplicated assertion is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wikirik-agent
wikirik-agent requested a review from a team as a code owner October 20, 2026 01:38
@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: afa65d24-821d-4980-b343-2b4550923644
📥 Commits

Reviewing files that changed from the base of the PR and between 950079a and 2e0f260.

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: 683d508a-fa3b-40be-97fb-081fb0a13abd
📥 Commits

Reviewing files that changed from the base of the PR and between 8856ab8 and 950079a.

📒 Files selected for processing: 10
  • packages/core/test/unit/instance/build.test.ts
  • packages/core/test/unit/instance/decrement.test.ts
  • packages/core/test/unit/instance/destroy.test.ts
  • packages/core/test/unit/instance/get.test.ts
  • packages/core/test/unit/instance/increment.test.ts
  • packages/core/test/unit/instance/is-soft-deleted.test.ts
  • packages/core/test/unit/instance/previous.test.ts
  • packages/core/test/unit/instance/reload.test.ts
  • packages/core/test/unit/instance/restore.test.ts
  • packages/core/test/unit/instance/save.test.ts
🚧 Files skipped from review as they are similar to previous changes: 4
  • packages/core/test/unit/instance/reload.test.ts
  • packages/core/test/unit/instance/restore.test.ts
  • packages/core/test/unit/instance/destroy.test.ts
  • packages/core/test/unit/instance/build.test.ts

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

📝 Walkthrough

The PR expands instance unit-test coverage for build defaults, attribute access, mutations, lifecycle methods, and soft-delete state. It also converts the set tests to TypeScript imports and removes the former JavaScript get test file.

Changes: Instance unit tests

Layer / File(s) Summary
Build and attribute access tests
packages/core/test/unit/instance/build.test.ts, packages/core/test/unit/instance/get.test.ts, packages/core/test/unit/instance/get.test.js, packages/core/test/unit/instance/set.test.ts, packages/core/test/unit/instance/previous.test.ts
Tests cover timestamp, UUID, column, and JSONB defaults; getter behavior; typed JSONB and date assertions; and previous values. The JavaScript get test file was removed.
Instance mutation operations
packages/core/test/unit/instance/decrement.test.ts, packages/core/test/unit/instance/increment.test.ts, packages/core/test/unit/instance/destroy.test.ts, packages/core/test/unit/instance/save.test.ts
Tests cover missing-primary-key rejection and successful optionless operations. Successful paths use stubbed queries and restore Sinon state.
Reload, restore, and soft-delete tests
packages/core/test/unit/instance/reload.test.ts, packages/core/test/unit/instance/restore.test.ts, packages/core/test/unit/instance/is-soft-deleted.test.ts
Tests cover primary-key validation, persisted paranoid instance operations, paranoid validation, and soft-delete state detection.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 95007

No merge-blocking issue is identified in the converted instance tests; normal checks can proceed.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the primary change: converting the unit/instance test suite to TypeScript. It is concise and specific.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 11 files.

✨ Finishing Touches
📝 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.

Replace the getTestDialectTeaser wrappers with plain titles (Model.build,
Model#get, Model#isSoftDeleted, Model#previous), use the sequelize
instance from the support file directly instead of aliasing it as
current, and remove the "options tests" describes that only scoped a
queryRaw stub. The stub is now created in the test and restored with
sinon.restore() after each test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@WikiRik
WikiRik enabled auto-merge (squash) October 20, 2026 08:47
@WikiRik
WikiRik merged commit 7c30901 into main Oct 20, 2026
@WikiRik
WikiRik deleted the wikirik-agent/ts-unit-instance-tests branch October 20, 2026 09:19
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