Skip to content

refactor(core): share op prototypes and keep the es5 bundles es5 - #352

Merged
nev21 merged 1 commit into
mainfrom
nev21/SharedOps
Oct 24, 2026
Merged

nev21 merged 1 commit into
mainfrom
nev21/SharedOps

Conversation

@nev21

@nev21 nev21 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor
  • Build the to, is, has, deep, own, nested, strictly and numeric op tables once and share one prototype per table, instead of redefining 30 to 50 getters on every chain step. IAssertScopeFuncDef moves out of IAssertInst.ts into its own file for the shared tables to use.
  • The rebuilt tables also put equal, equals and eq on to and add Chai's at, so expect(5).to.be.at.least(5) works.
  • Replace bare Symbol.iterator and Error.captureStackTrace uses with ts-utils helpers or casts so the es5 bundles stay es5, and print accessor properties as [Getter] instead of calling them.
  • The default config sets timeout, slow and retries to 2000, 75 and 0 for the suite runner.

@nev21
nev21 requested review from a team as code owners October 24, 2026 19:37
Copilot AI balanced review requested due to automatic review settings October 24, 2026 19:37

@nev21 nev21 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@nev21
nev21 enabled auto-merge (squash) October 24, 2026 19:40
@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.71689% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.59%. Comparing base (7c27ebe) to head (99ad6b5).

Files with missing lines Patch % Lines
core/src/internal/_defaultFormatters.ts 91.66% 2 Missing ⚠️
core/src/assert/interface/IAssertScopeFuncDef.ts 50.00% 1 Missing ⚠️
core/src/assert/interface/ops/IHasOwnOp.ts 50.00% 1 Missing ⚠️
core/src/assert/ops/numericOp.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
+ Coverage   95.26%   95.59%   +0.32%     
==========================================
  Files         139      141       +2     
  Lines        6404     6471      +67     
  Branches     1640     1696      +56     
==========================================
+ Hits         6101     6186      +85     
+ Misses        303      285      -18     
Files with missing lines Coverage Δ
core/src/assert/adapters/evalAdapter.ts 100.00% <100.00%> (ø)
core/src/assert/assertInst.ts 88.46% <100.00%> (ø)
core/src/assert/assertScope.ts 98.21% <100.00%> (+0.31%) ⬆️
core/src/assert/funcs/hasProperty.ts 97.14% <100.00%> (-0.02%) ⬇️
core/src/assert/funcs/isExtensible.ts 100.00% <100.00%> (ø)
core/src/assert/funcs/isFrozen.ts 100.00% <100.00%> (ø)
core/src/assert/funcs/isSealed.ts 100.00% <100.00%> (ø)
core/src/assert/funcs/members.ts 100.00% <100.00%> (ø)
core/src/assert/funcs/throws.ts 97.01% <100.00%> (ø)
core/src/assert/funcs/valuesFunc.ts 98.33% <100.00%> (+0.01%) ⬆️
... and 30 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

🟡 Changes recommended

Getter-safe formatting remains incomplete, and prototype caching regresses support for frozen and mutable custom definition tables.

3 open issues
1 file not reviewed
  • common/config/rush/npm-shrinkwrap.json: Generated file
What changed in this PR

This PR reduces assertion-chain setup work by sharing operation tables and prototypes across tripwire instances. It also expands fluent assertion syntax and improves compatibility and formatting behavior.

Changes:

  • Cache operation definitions and prototypes, and extract their shared interface.
  • Add direct to equality assertions and Chai-style at chaining.
  • Update symbol and stack handling, guard accessor formatting, and add suite-runner defaults.
File Description
core/​test/​src/​support/​validate.symbol.test.ts Check symbol support and iterator identity.
core/​test/​src/​assert/​expect.to.test.ts Test decorative at chaining.
core/​test/​src/​assert/​deepEqual.test.ts Remove an unused test variable.
core/​test/​src/​assert/​context.test.ts Refresh copyright and final newline.
core/​test/​src/​assert/​addAssertFuncs.test.ts Remove an unused test interface.
core/​src/​internal/​parseStack.ts Update constant import and stack-limit typing.
core/​src/​internal/​formatManager.ts Reorganize imports and use shared constants.
core/​src/​internal/​captureStack.ts Cast nonstandard Error properties.
core/​src/​internal/​_defaultFormatters.ts Add descriptor checks for getter formatting.
core/​src/​index.ts Update imports for extracted definition types.
core/​src/​config/​defaultConfig.ts Add timeout, slow, and retry defaults.
core/​src/​config/​config.ts Reorder imports.
core/​src/​assert/​ops/​toOp.ts Share definitions and add equality aliases.
core/​src/​assert/​ops/​strictlyOp.ts Share strict operation tables.
core/​src/​assert/​ops/​propertyResultOp.ts Import extracted definition types.
core/​src/​assert/​ops/​ownOp.ts Share tables and use iterator-symbol helpers.
core/​src/​assert/​ops/​numericOp.ts Share numeric operation definitions.
core/​src/​assert/​ops/​nestedOp.ts Share nested operation tables.
core/​src/​assert/​ops/​isOp.ts Share definitions and add at.
core/​src/​assert/​ops/​includeOp.ts Update definition-type imports and naming.
core/​src/​assert/​ops/​hasOp.ts Share tables and use iterator-symbol helpers.
core/​src/​assert/​ops/​deepOp.ts Share deep operation definitions.
core/​src/​assert/​ops/​changeResultOp.ts Import extracted definition types.
core/​src/​assert/​ops/​allOp.ts Update definition and constant imports.
core/​src/​assert/​internal/​_instCreator.ts Add prototype tagging and scoped instance creation.
core/​src/​assert/​internal/​_blockLength.ts Use the shared constants path.
core/​src/​assert/​internal/​_AssertInstCore.ts Expose the empty assertion prototype internally.
core/​src/​assert/​internal/​_addAssertInstFuncs.ts Import extracted definition types.
core/​src/​assert/​interface/​ops/​IToOp.ts Expose direct equality operations in types.
core/​src/​assert/​interface/​ops/​IIsOp.ts Declare and document at.
core/​src/​assert/​interface/​IScopeContext.ts Reorder properties and their documentation.
core/​src/​assert/​interface/​IAssertScopeFuncDef.ts Add the standalone operation-definition interface.
core/​src/​assert/​interface/​IAssertScope.ts Use the extracted definition type.
core/​src/​assert/​interface/​funcs/​IncludeFn.ts Refresh copyright and final newline.
core/​src/​assert/​funcs/​valuesFunc.ts Use the shared constants path.
core/​src/​assert/​funcs/​throws.ts Rename the internal enum and clarify nullable messages.
core/​src/​assert/​funcs/​members.ts Reorder imports.
core/​src/​assert/​funcs/​isSealed.ts Clean up imports and file metadata.
core/​src/​assert/​funcs/​isFrozen.ts Clean up imports and file metadata.
core/​src/​assert/​funcs/​isExtensible.ts Clean up imports and file metadata.
core/​src/​assert/​funcs/​hasProperty.ts Reorder imports.
core/​src/​assert/​assertScope.ts Cache prototypes for default operation creation.
core/​src/​assert/​assertInst.ts Use extracted definition types.
core/​src/​assert/​adapters/​evalAdapter.ts Clean up imports and copyright.
common/​config/​rush/​npm-shrinkwrap.json Refresh transitive dependency versions.

Review effort: Balanced

Comment thread core/src/assert/assertScope.ts
Comment thread core/src/assert/assertScope.ts Outdated
Comment thread core/src/internal/_defaultFormatters.ts
nevware21-bot
nevware21-bot previously approved these changes Oct 24, 2026

@nevware21-bot nevware21-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.

Approved by nevware21-bot

- Build the to, is, has, deep, own, nested, strictly and numeric op tables once and share one prototype per table, instead of redefining 30 to 50 getters on every chain step. IAssertScopeFuncDef moves out of IAssertInst.ts into its own file for the shared tables to use.
- The rebuilt tables also put equal, equals and eq on to and add Chai's at, so expect(5).to.be.at.least(5) works.
- Replace bare Symbol.iterator and Error.captureStackTrace uses with ts-utils helpers or casts so the es5 bundles stay es5, and print accessor properties as [Getter] instead of calling them.
- The default config sets timeout, slow and retries to 2000, 75 and 0 for the suite runner.

fix(core): wire has.own to the own operation table and harden the shared operation prototypes

- Point has.own at hasOwnOp, which has existed since the initial prototype but was never reached: has.own went to ownOp, so the own forms of all, any, nested, lengthOf and sizeOf were unreachable from the has chain.
- Complete the hasOwnOp table so it is a superset of IOwnOp, binding the same ownIncludeOp and own property functions ownOp binds, setting the OWN context flag as ownOp does, and dropping the meaningless has.own.own entry.
- Add IHasOwnOp (@SInCE 0.2.0), IOwnOp plus the own forms of all, any, nested, lengthOf and sizeOf, type IHasOp.own with it and export it from the package index; every previously valid has.own expression still type-checks.
- createOperation skips caching the shared prototype on a frozen, sealed or otherwise non-extensible definition table instead of throwing a TypeError, and its doc states that a table is bound on first use and treated as immutable afterwards.
- Collect object keys for formatting with objKeys rather than objForEachKey, which read every value and so invoked getters before the [Getter] guard could decline to; a throwing getter no longer aborts the formatter.
- Keep the prototype self-reference guard in _isAccessorProp, with a comment that some older runtimes return the object itself from getPrototypeOf at the top of the chain.
- Tests: own and inherited getters are described as [Getter] and never invoked; frozen and sealed tables create working operations without anything written onto them, a mutable table shares one prototype, a custom handler creator takes the per-instance path, and a caller-supplied object is decorated in place; has.own refuses inherited properties for property and include and offers all, any, nested, lengthOf and sizeOf; hasOp, hasOwnOp and numericOp are exercised directly; deep.strictly equal, not, true and false; the change result's value chain and its non-numeric delta refusals.

@nevware21-bot nevware21-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.

Approved by nevware21-bot

@nev21
nev21 merged commit d3aa5fa into main Oct 24, 2026
9 checks passed
@nev21
nev21 deleted the nev21/SharedOps branch October 24, 2026 23:31
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.

3 participants