From 47477eea98558e1986fa131238b59b43dc447e9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 17:15:11 +0000 Subject: [PATCH 1/6] Initial plan From c04b405d4c0e1746185673c7aaff7236be7a10d5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 17:18:47 +0000 Subject: [PATCH 2/6] Initial plan for deepStrictEqual fix Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com> --- common/config/rush/npm-shrinkwrap.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index b05944e..ca1a990 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -1447,9 +1447,9 @@ "integrity": "sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==" }, "node_modules/@types/node": { - "version": "25.2.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.2.1.tgz", - "integrity": "sha512-CPrnr8voK8vC6eEtyRzvMpgp3VyVRhgclonE7qYi6P9sXwYb59ucfrnmFBTaP0yUi8Gk4yZg/LlTJULGxvTNsg==", + "version": "25.2.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.2.3.tgz", + "integrity": "sha512-m0jEgYlYz+mDJZ2+F4v8D1AyQb+QzsNqRuI7xg1VQX/KlKS0qT9r1Mo16yo5F/MtifXFgaofIFsdFMox2SxIbQ==", "dependencies": { "undici-types": "~7.16.0" } @@ -5332,9 +5332,9 @@ } }, "node_modules/markdown-it": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", - "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz", + "integrity": "sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA==", "dependencies": { "argparse": "^2.0.1", "entities": "^4.4.0", From 848747fca54d7759c471b4cbfd01c379354371f3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 17:20:33 +0000 Subject: [PATCH 3/6] Fix deepStrictEqual to support deep value comparison Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com> --- core/src/assert/funcs/equal.ts | 5 -- core/test/src/assert/assert.equals.test.ts | 82 +++++++++++++++------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/core/src/assert/funcs/equal.ts b/core/src/assert/funcs/equal.ts index 9f75c5d..fd8abc4 100644 --- a/core/src/assert/funcs/equal.ts +++ b/core/src/assert/funcs/equal.ts @@ -495,11 +495,6 @@ function _deepEquals(value: T, expected: T, options: IEqualOptions): boolean return isEquals; } - if (options.strict === true) { - // If strict is set and we get here, then the values are not strictly equal - return false; - } - if (isPlainObject(value) && isPlainObject(expected)) { return _objEquals(value, expected, options); } diff --git a/core/test/src/assert/assert.equals.test.ts b/core/test/src/assert/assert.equals.test.ts index 3ba62c2..a87e99a 100644 --- a/core/test/src/assert/assert.equals.test.ts +++ b/core/test/src/assert/assert.equals.test.ts @@ -960,30 +960,24 @@ describe("assert.deepStrictEqual", function () { const obj5 = { a: 1, b: child2 }; const obj6 = { a: 1, b: child1 }; - assert.deepStrictEqual(obj1, obj1); // Same reference - assert.deepStrictEqual(obj2, obj2); // Same reference - assert.deepStrictEqual(obj3, obj3); // Same reference - assert.deepStrictEqual(obj4, obj4); // Same reference - assert.deepStrictEqual(obj5, obj5); // Same reference - assert.deepStrictEqual(obj6, obj6); // Same reference - checkError(function () { - assert.deepStrictEqual(obj4, obj6); - }, "expected {a:1,b:{c:2,d:3}} to deeply and strictly equal {a:1,b:{c:2,d:3}}"); - - - checkError(function () { - assert.deepStrictEqual(obj1, obj2, "Object mismatch"); // Same looking object - }, "Object mismatch: expected {a:1,b:2} to deeply and strictly equal {a:1,b:2}"); + // Same reference - should pass + assert.deepStrictEqual(obj1, obj1); + assert.deepStrictEqual(obj2, obj2); + assert.deepStrictEqual(obj3, obj3); + assert.deepStrictEqual(obj4, obj4); + assert.deepStrictEqual(obj5, obj5); + assert.deepStrictEqual(obj6, obj6); + // Same values - should pass (deep value equality) + assert.deepStrictEqual(obj1, obj2); + assert.deepStrictEqual(obj4, obj5); + assert.deepStrictEqual(obj4, obj6); + // Different values - should fail checkError(function () { assert.deepStrictEqual(obj1, obj3, "Object mismatch"); }, "Object mismatch: expected {a:1,b:2} to deeply and strictly equal {a:1,b:2,c:3}"); - checkError(function () { - assert.deepStrictEquals(obj4, obj5); - }, "expected {a:1,b:{c:2,d:3}} to deeply and strictly equal {a:1,b:{c:2,d:3}}"); - checkError(function () { const obj7 = { a: 1, b: { c: 2, d: 4 } }; assert.deepStrictEquals(obj5, obj7, "Nested object mismatch"); @@ -994,13 +988,14 @@ describe("assert.deepStrictEqual", function () { const arr1 = [1, [2, 3], 4]; const arr2 = [1, [2, 3], 4]; - assert.deepStrictEqual(arr1, arr1); // Same reference - assert.deepStrictEqual(arr2, arr2); // Same reference + // Same reference - should pass + assert.deepStrictEqual(arr1, arr1); + assert.deepStrictEqual(arr2, arr2); - checkError(function () { - assert.deepStrictEquals(arr1, arr2); - }, "expected [1,[2,3],4] to deeply and strictly equal [1,[2,3],4]"); + // Same values - should pass (deep value equality) + assert.deepStrictEqual(arr1, arr2); + // Different values - should fail checkError(function () { const arr3 = [1, [2, 4], 4]; assert.deepStrictEquals(arr1, arr3, "Nested array mismatch"); @@ -1011,13 +1006,14 @@ describe("assert.deepStrictEqual", function () { const combo1 = { a: [1, 2, { b: 3 }] }; const combo2 = { a: [1, 2, { b: 3 }] }; + // Same reference - should pass assert.deepStrictEquals(combo1, combo1); assert.deepStrictEquals(combo2, combo2); - checkError(function () { - assert.deepStrictEquals(combo1, combo2); - }, "expected {a:[1,2,{b:3}]} to deeply and strictly equal {a:[1,2,{b:3}]}"); + // Same values - should pass (deep value equality) + assert.deepStrictEquals(combo1, combo2); + // Different values - should fail checkError(function () { const combo3 = { a: [1, 2, { b: 4 }] }; assert.deepStrictEquals(combo1, combo3, "Combination mismatch"); @@ -1101,4 +1097,38 @@ describe("assert.deepStrictEqual", function () { assert.deepStrictEquals(0, false, "Number and boolean mismatch"); }, "Number and boolean mismatch: expected 0 to deeply and strictly equal false"); }); + + it("Deep comparison examples from requirements", function () { + // Objects with same values should pass + assert.deepStrictEqual({ a: 1 }, { a: 1 }); + + // Objects with different types should fail + checkError(function () { + assert.deepStrictEqual({ a: 1 }, { a: "1" }); + }, "expected {a:1} to deeply and strictly equal {a:\"1\"}"); + + // Arrays with same values should pass + assert.deepStrictEqual([1, 2], [1, 2]); + + // Arrays with different order should fail + checkError(function () { + assert.deepStrictEqual([1, 2], [2, 1]); + }, "expected [1,2] to deeply and strictly equal [2,1]"); + + // Nested objects with same values should pass + assert.deepStrictEqual({ a: { b: 1 } }, { a: { b: 1 } }); + + // Nested objects with different types should fail + checkError(function () { + assert.deepStrictEqual({ a: { b: 1 } }, { a: { b: "1" } }); + }, "expected {a:{b:1}} to deeply and strictly equal {a:{b:\"1\"}}"); + + // Arrays with objects with same values should pass + assert.deepStrictEqual([{ a: 1 }], [{ a: 1 }]); + + // Arrays with objects with different types should fail + checkError(function () { + assert.deepStrictEqual([{ a: 1 }], [{ a: "1" }]); + }, "expected [{a:1}] to deeply and strictly equal [{a:\"1\"}]"); + }); }); From d2d8deaa419bf7892f6258502e6d06ec138559ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 01:26:33 +0000 Subject: [PATCH 4/6] Add comprehensive tests for deepEqual with loose equality Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com> --- core/test/src/assert/assert.equals.test.ts | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/core/test/src/assert/assert.equals.test.ts b/core/test/src/assert/assert.equals.test.ts index a87e99a..133576b 100644 --- a/core/test/src/assert/assert.equals.test.ts +++ b/core/test/src/assert/assert.equals.test.ts @@ -841,6 +841,34 @@ describe("assert.deepEqual", function () { assertConfig.circularMsg = originalMsg; } }); + + it("Deep comparison examples with loose equality", function () { + // Objects with same values should pass + assert.deepEqual({ a: 1 }, { a: 1 }); + + // Objects with different types should pass (loose equality) + assert.deepEqual({ a: 1 }, { a: "1" }); + + // Arrays with same values should pass + assert.deepEqual([1, 2], [1, 2]); + + // Arrays with different order should fail (order matters) + checkError(function () { + assert.deepEqual([1, 2], [2, 1]); + }, "expected [1,2] to deeply equal [2,1]"); + + // Nested objects with same values should pass + assert.deepEqual({ a: { b: 1 } }, { a: { b: 1 } }); + + // Nested objects with different types should pass (loose equality) + assert.deepEqual({ a: { b: 1 } }, { a: { b: "1" } }); + + // Arrays with objects with same values should pass + assert.deepEqual([{ a: 1 }], [{ a: 1 }]); + + // Arrays with objects with different types should pass (loose equality) + assert.deepEqual([{ a: 1 }], [{ a: "1" }]); + }); }); describe("assert.deepEquals", function () { From 47eb64d5d271e1905bba137f28931b52edfd46a3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 01:30:54 +0000 Subject: [PATCH 5/6] Fix deepStrictEqual to perform deep value comparison Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com> --- common/config/rush/npm-shrinkwrap.json | 6 +++--- core/test/src/assert/assert.equals.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index ca1a990..e5e232e 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -6471,9 +6471,9 @@ } }, "node_modules/qs": { - "version": "6.14.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz", - "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==", + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", "dependencies": { "side-channel": "^1.1.0" }, diff --git a/core/test/src/assert/assert.equals.test.ts b/core/test/src/assert/assert.equals.test.ts index 133576b..484ecf4 100644 --- a/core/test/src/assert/assert.equals.test.ts +++ b/core/test/src/assert/assert.equals.test.ts @@ -1001,6 +1001,10 @@ describe("assert.deepStrictEqual", function () { assert.deepStrictEqual(obj4, obj5); assert.deepStrictEqual(obj4, obj6); + assert.deepStrictEqual(obj1, { a: 1, b: 2 }); + assert.deepStrictEqual(obj3, { a: 1, b: 2, c: 3 }); + assert.deepStrictEqual(obj4, { a: 1, b: { c: 2, d: 3 } }); + // Different values - should fail checkError(function () { assert.deepStrictEqual(obj1, obj3, "Object mismatch"); From 291cb95786fcaf0916a765298cb22d823d6a5f06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 03:23:27 +0000 Subject: [PATCH 6/6] Update documentation for deepStrictEqual changes in v0.1.7 Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com> --- docs/migration/migrating-from-node-assert.md | 261 +++++++++---------- 1 file changed, 119 insertions(+), 142 deletions(-) diff --git a/docs/migration/migrating-from-node-assert.md b/docs/migration/migrating-from-node-assert.md index ab1d2c2..2aefad8 100644 --- a/docs/migration/migrating-from-node-assert.md +++ b/docs/migration/migrating-from-node-assert.md @@ -49,78 +49,73 @@ Replace Node.js assert imports: ## 3. Key Behavioral Differences -### 3.1. `deepStrictEqual` - Instance vs. Structural Equality +### 3.1. `deepStrictEqual` - Behavior Change in v0.1.7 -**This is the most important difference to understand.** +> **⚠️ IMPORTANT:** The behavior of `deepStrictEqual` changed in **v0.1.7** to match Node.js behavior. -#### Node.js Behavior -Node.js's `assert.deepStrictEqual` performs **structural equality** comparison. It checks if objects have the same structure and values, even if they are different instances: +#### Versions < 0.1.7 (Old Behavior) +Prior to v0.1.7, Tripwire's `assert.deepStrictEqual` required **exact instance identity** for objects: ```js -// Node.js native assert -const assert = require('assert'); +// Tripwire < 0.1.7 (OLD BEHAVIOR) +import { assert } from '@nevware21/tripwire'; const obj1 = { a: 1, b: 2 }; const obj2 = { a: 1, b: 2 }; -assert.deepStrictEqual(obj1, obj2); // ✅ PASSES - structurally identical - -const result = Object.assign({}, { a: 1 }); -assert.deepStrictEqual(result, { a: 1 }); // ✅ PASSES +assert.deepStrictEqual(obj1, obj2); // ❌ FAILED - different instances ``` -#### Tripwire Behavior -Tripwire's `assert.deepStrictEqual` requires **exact instance identity** for objects. It checks both structure and that nested objects are the same instances: +#### Versions >= 0.1.7 (Current Behavior - Matches Node.js) +Starting in v0.1.7, Tripwire's `assert.deepStrictEqual` now performs **deep structural equality** with strict type checking, matching Node.js behavior: ```js -// Tripwire +// Tripwire >= 0.1.7 and Node.js native assert import { assert } from '@nevware21/tripwire'; const obj1 = { a: 1, b: 2 }; const obj2 = { a: 1, b: 2 }; -assert.deepStrictEqual(obj1, obj2); // ❌ FAILS - different instances +assert.deepStrictEqual(obj1, obj2); // ✅ PASSES - same structure and values const result = Object.assign({}, { a: 1 }); -assert.deepStrictEqual(result, { a: 1 }); // ❌ FAILS - different instances +assert.deepStrictEqual(result, { a: 1 }); // ✅ PASSES - deep value equality -// Same reference works -assert.deepStrictEqual(obj1, obj1); // ✅ PASSES +// Strict type checking still enforced +assert.deepStrictEqual({ a: 1 }, { a: "1" }); // ❌ FAILS - different types (number vs string) ``` -#### Migration Strategy +#### Migration from Versions < 0.1.7 -When migrating code that compares different object instances, use `deepEqual` instead of `deepStrictEqual`: +If you were using Tripwire < 0.1.7 and had changed `deepStrictEqual` to `deepEqual` as a workaround, you can now change them back: ```diff -// Before (Node.js) -const result = deepMerge({ a: 1 }, { b: 2 }); -- assert.deepStrictEqual(result, { a: 1, b: 2 }); - -// After (Tripwire) +// If you migrated from deepStrictEqual to deepEqual in older versions const result = deepMerge({ a: 1 }, { b: 2 }); -+ assert.deepEqual(result, { a: 1, b: 2 }); +- assert.deepEqual(result, { a: 1, b: 2 }); ++ assert.deepStrictEqual(result, { a: 1, b: 2 }); // Now works in v0.1.7+ ``` -Or use the fluent `expect` API: +#### Migration from Node.js -```js -import { expect } from '@nevware21/tripwire'; +If you're migrating from Node.js to Tripwire >= 0.1.7, `deepStrictEqual` works the same way - **no changes needed**: -const result = deepMerge({ a: 1 }, { b: 2 }); -expect(result).to.deep.equal({ a: 1, b: 2 }); // ✅ PASSES +```js +// Works identically in both Node.js and Tripwire >= 0.1.7 +const result = processData({ input: 'test' }); +assert.deepStrictEqual(result, { output: 'processed' }); // ✅ PASSES ``` ### 3.2. When to Use Each Assertion -| Assertion | Use Case | Node.js Behavior | Tripwire Behavior | -|-----------|----------|------------------|-------------------| +| Assertion | Use Case | Node.js Behavior | Tripwire >= 0.1.7 Behavior | +|-----------|----------|------------------|---------------------------| | `equal` | Loose equality (==) | Coerces types | Coerces types | | `strictEqual` | Strict equality (===) | Same reference/value | Same reference/value | -| `deepEqual` | Deep structural equality with type coercion | Structural comparison | Structural comparison | -| `deepStrictEqual` | Deep strict equality | Structural + strict type check | **Requires same instances** | +| `deepEqual` | Deep structural equality with type coercion | Structural comparison with type coercion | Structural comparison with type coercion | +| `deepStrictEqual` | Deep strict equality | Structural + strict type check | **Structural + strict type check** (matches Node.js) | -**Recommendation:** For most test cases involving object comparison, use `deepEqual` instead of `deepStrictEqual` when migrating to Tripwire. +**Note:** In Tripwire >= 0.1.7, `deepStrictEqual` now matches Node.js behavior exactly. Use it when you need deep structural comparison with strict type checking (e.g., `1` !== `"1"`). --- @@ -140,8 +135,8 @@ Most Node.js assert methods are supported in Tripwire with the same or similar b | `assert.notStrictEqual(actual, expected)` | `assert.notStrictEqual(actual, expected)` | Identical | | `assert.deepEqual(actual, expected)` | `assert.deepEqual(actual, expected)` | Identical | | `assert.notDeepEqual(actual, expected)` | `assert.notDeepEqual(actual, expected)` | Identical | -| `assert.deepStrictEqual(actual, expected)` | `assert.deepStrictEqual(actual, expected)` | ⚠️ **Different behavior** (see section 3.1) | -| `assert.notDeepStrictEqual(actual, expected)` | `assert.notDeepStrictEqual(actual, expected)` | ⚠️ **Different behavior** (see section 3.1) | +| `assert.deepStrictEqual(actual, expected)` | `assert.deepStrictEqual(actual, expected)` | ✅ **Identical in v0.1.7+** (structural + strict type check) | +| `assert.notDeepStrictEqual(actual, expected)` | `assert.notDeepStrictEqual(actual, expected)` | ✅ **Identical in v0.1.7+** | | `assert.throws(fn, error?)` | `assert.throws(fn, error?)` | Similar (error messages may differ) | | `assert.doesNotThrow(fn)` | `assert.doesNotThrow(fn)` | Similar | | `assert.fail(message)` | `assert.fail(message)` | Similar | @@ -202,25 +197,19 @@ assert.strictEqual(actual, expected); assert.notEqual(actual, unexpected); ``` -### 5.2. Deep Equality (Most Common Migration) +### 5.2. Deep Equality -**Before (Node.js):** -```js -const assert = require('assert'); - -const result = processData({ input: 'test' }); -assert.deepStrictEqual(result, { output: 'processed' }); -``` +> **Note:** In Tripwire >= 0.1.7, `deepStrictEqual` works the same as Node.js - no migration needed! -**After (Tripwire) - Option 1: Use deepEqual** +**Node.js and Tripwire >= 0.1.7:** ```js import { assert } from '@nevware21/tripwire'; const result = processData({ input: 'test' }); -assert.deepEqual(result, { output: 'processed' }); +assert.deepStrictEqual(result, { output: 'processed' }); // ✅ Works in both! ``` -**After (Tripwire) - Option 2: Use expect** +**Alternative - Using expect API:** ```js import { expect } from '@nevware21/tripwire'; @@ -228,39 +217,34 @@ const result = processData({ input: 'test' }); expect(result).to.deep.equal({ output: 'processed' }); ``` -### 5.3. Array Comparisons - -**Before (Node.js):** +**Using deepEqual for type coercion:** ```js -const assert = require('assert'); - -const arr = [1, 2, 3]; -assert.deepStrictEqual(arr, [1, 2, 3]); +// Use deepEqual when you want loose type checking +assert.deepEqual({ a: 1 }, { a: "1" }); // ✅ PASSES (1 == "1") +assert.deepStrictEqual({ a: 1 }, { a: "1" }); // ❌ FAILS (1 !== "1") ``` -**After (Tripwire):** +### 5.3. Array Comparisons + +> **Note:** In Tripwire >= 0.1.7, array comparisons work the same as Node.js! + +**Node.js and Tripwire >= 0.1.7:** ```js import { assert } from '@nevware21/tripwire'; const arr = [1, 2, 3]; -assert.deepEqual(arr, [1, 2, 3]); // Use deepEqual for new array instances +assert.deepStrictEqual(arr, [1, 2, 3]); // ✅ Works in both! + +// Type checking still enforced +assert.deepStrictEqual([1, 2], ["1", "2"]); // ❌ FAILS - different types +assert.deepEqual([1, 2], ["1", "2"]); // ✅ PASSES - loose equality ``` ### 5.4. Object Merging/Transformation -**Before (Node.js):** -```js -const assert = require('assert'); - -function mergeOptions(defaults, overrides) { - return Object.assign({}, defaults, overrides); -} - -const result = mergeOptions({ a: 1 }, { b: 2 }); -assert.deepStrictEqual(result, { a: 1, b: 2 }); -``` +> **Note:** In Tripwire >= 0.1.7, object transformations work the same as Node.js! -**After (Tripwire):** +**Node.js and Tripwire >= 0.1.7:** ```js import { assert } from '@nevware21/tripwire'; @@ -269,7 +253,7 @@ function mergeOptions(defaults, overrides) { } const result = mergeOptions({ a: 1 }, { b: 2 }); -assert.deepEqual(result, { a: 1, b: 2 }); // deepEqual for new instances +assert.deepStrictEqual(result, { a: 1, b: 2 }); // ✅ Works in both! ``` ### 5.5. Error Testing @@ -346,23 +330,33 @@ expect(arr).to.have.lengthOf(3); 4. **Review error messages** - they may differ from Node.js 5. **Remove Node.js assert** once migration is complete -### 6.2. Find and Replace Strategy +### 6.2. Migration Strategy for Tripwire >= 0.1.7 -Use these patterns to help with migration: +**Good news:** If you're migrating from Node.js to Tripwire >= 0.1.7, `deepStrictEqual` works identically - **no changes needed**! -**Find `deepStrictEqual` with new instances:** -```bash -# Search for patterns that likely create new instances -grep -r "deepStrictEqual.*{" test/ -grep -r "deepStrictEqual.*\[" test/ -grep -r "deepStrictEqual.*Object\." test/ -grep -r "deepStrictEqual.*Array\." test/ +**Update imports only:** +```diff +- const assert = require('assert'); ++ import { assert } from '@nevware21/tripwire'; + +// All deepStrictEqual calls work the same +assert.deepStrictEqual(obj1, obj2); // ✅ No changes needed ``` -**Replace pattern:** -```diff -- assert.deepStrictEqual(result, expectedObject); -+ assert.deepEqual(result, expectedObject); +**Key differences to remember:** +- `deepStrictEqual`: Deep structural equality with strict type checking (1 !== "1") +- `deepEqual`: Deep structural equality with type coercion (1 == "1") + +**Example:** +```js +import { assert } from '@nevware21/tripwire'; + +// Strict type checking +assert.deepStrictEqual({ a: 1 }, { a: 1 }); // ✅ PASSES +assert.deepStrictEqual({ a: 1 }, { a: "1" }); // ❌ FAILS - different types + +// Loose type coercion +assert.deepEqual({ a: 1 }, { a: "1" }); // ✅ PASSES - 1 == "1" ``` ### 6.3. Running Tests @@ -392,27 +386,27 @@ GitHub Copilot can help automate the migration. Use these prompts: ### Basic Import Migration ``` Replace all Node.js 'assert' or 'node:assert' imports with '@nevware21/tripwire' imports. -Keep all assertion calls unchanged initially. +All assertion calls work the same in Tripwire >= 0.1.7. ``` -### Deep Equality Migration +### For Tripwire < 0.1.7 Upgrades ``` -Find all uses of assert.deepStrictEqual that compare objects or arrays that are -different instances (created via Object.assign, spread operator, or factory functions). -Replace them with assert.deepEqual. +We're upgrading from Tripwire < 0.1.7 to >= 0.1.7. +Find uses of assert.deepEqual that were changed from deepStrictEqual as a workaround. +Change them back to deepStrictEqual since v0.1.7 matches Node.js behavior. ``` ### Full Migration to Expect ``` Convert Node.js assert style to Tripwire expect style: - assert.equal(a, b) → expect(a).to.equal(b) -- assert.deepEqual(a, b) → expect(a).to.deep.equal(b) +- assert.deepStrictEqual(a, b) → expect(a).to.deep.equal(b) - assert.throws(fn, Error) → expect(fn).to.throw(Error) Keep same test logic and behavior. ``` ### Tips for Copilot -- Review suggestions for `deepStrictEqual` → `deepEqual` conversions +- Tripwire >= 0.1.7 `deepStrictEqual` works identically to Node.js - Test in all environments after migration - Check that error message assertions still work (they may need regex patterns) @@ -420,80 +414,49 @@ Keep same test logic and behavior. ## 8. Common Migration Patterns -### Pattern 1: Object Factory Functions - -**Before:** -```js -function createUser(name, age) { - return { name, age }; -} +> **Note:** In Tripwire >= 0.1.7, these patterns work identically to Node.js - no migration needed! -assert.deepStrictEqual(createUser('Alice', 30), { name: 'Alice', age: 30 }); -``` +### Pattern 1: Object Factory Functions -**After:** +**Node.js and Tripwire >= 0.1.7:** ```js function createUser(name, age) { return { name, age }; } -assert.deepEqual(createUser('Alice', 30), { name: 'Alice', age: 30 }); +assert.deepStrictEqual(createUser('Alice', 30), { name: 'Alice', age: 30 }); // ✅ Works! ``` ### Pattern 2: Array Transformations -**Before:** -```js -const doubled = [1, 2, 3].map(x => x * 2); -assert.deepStrictEqual(doubled, [2, 4, 6]); -``` - -**After:** +**Node.js and Tripwire >= 0.1.7:** ```js const doubled = [1, 2, 3].map(x => x * 2); -assert.deepEqual(doubled, [2, 4, 6]); +assert.deepStrictEqual(doubled, [2, 4, 6]); // ✅ Works! ``` ### Pattern 3: Spread Operator -**Before:** -```js -const merged = { ...defaults, ...overrides }; -assert.deepStrictEqual(merged, { a: 1, b: 2 }); -``` - -**After:** +**Node.js and Tripwire >= 0.1.7:** ```js const merged = { ...defaults, ...overrides }; -assert.deepEqual(merged, { a: 1, b: 2 }); +assert.deepStrictEqual(merged, { a: 1, b: 2 }); // ✅ Works! ``` ### Pattern 4: Object.assign -**Before:** +**Node.js and Tripwire >= 0.1.7:** ```js const result = Object.assign({}, obj1, obj2); -assert.deepStrictEqual(result, expected); -``` - -**After:** -```js -const result = Object.assign({}, obj1, obj2); -assert.deepEqual(result, expected); +assert.deepStrictEqual(result, expected); // ✅ Works! ``` ### Pattern 5: JSON Parse/Stringify -**Before:** -```js -const clone = JSON.parse(JSON.stringify(original)); -assert.deepStrictEqual(clone, original); -``` - -**After:** +**Node.js and Tripwire >= 0.1.7:** ```js const clone = JSON.parse(JSON.stringify(original)); -assert.deepEqual(clone, original); +assert.deepStrictEqual(clone, original); // ✅ Works! ``` --- @@ -556,9 +519,14 @@ See the [Tripwire documentation](https://nevware21.github.io/tripwire/index.html ## 11. Troubleshooting -### Problem: Tests fail with "different instances" errors +### Problem: Using Tripwire < 0.1.7 -**Solution:** Replace `deepStrictEqual` with `deepEqual` for comparing objects/arrays that are different instances. +If you're using an older version of Tripwire (< 0.1.7), `deepStrictEqual` required instance identity. + +**Solution:** Upgrade to Tripwire >= 0.1.7 for Node.js-compatible behavior: +```bash +npm install @nevware21/tripwire@latest --save-dev +``` ### Problem: Error message tests are failing @@ -582,23 +550,32 @@ await assert.rejects(async () => fn(), /error pattern/); ## 12. Best Practices -1. **Prefer `deepEqual` over `deepStrictEqual`** for object comparisons unless you specifically need instance identity -2. **Use the `expect` API** for more expressive tests: +1. **Use `deepStrictEqual` for strict type checking** - In Tripwire >= 0.1.7, it works just like Node.js + ```js + assert.deepStrictEqual({ a: 1 }, { a: 1 }); // ✅ PASSES + assert.deepStrictEqual({ a: 1 }, { a: "1" }); // ❌ FAILS - type mismatch + ``` +2. **Use `deepEqual` for loose type coercion** when you want `1 == "1"` to pass: + ```js + assert.deepEqual({ a: 1 }, { a: "1" }); // ✅ PASSES + ``` +3. **Use the `expect` API** for more expressive tests: ```js expect(result).to.deep.equal(expected); expect(value).to.be.a.string(); ``` -3. **Use regex for error message matching** instead of exact strings -4. **Test in all target environments** (Node.js, browser, worker) -5. **Leverage Tripwire's additional assertions** for cleaner test code +4. **Use regex for error message matching** instead of exact strings +5. **Test in all target environments** (Node.js, browser, worker) +6. **Leverage Tripwire's additional assertions** for cleaner test code --- ## 13. Summary: Migration Checklist -- [ ] Install `@nevware21/tripwire` as a dev dependency +- [ ] Install `@nevware21/tripwire` >= 0.1.7 as a dev dependency - [ ] Update imports from `assert`/`node:assert` to `@nevware21/tripwire` -- [ ] Replace `assert.deepStrictEqual` with `assert.deepEqual` for object/array comparisons +- [ ] **No changes needed** for `deepStrictEqual` if using v0.1.7+ (it matches Node.js behavior) +- [ ] Use `deepEqual` when you need loose type coercion (e.g., `1 == "1"`) - [ ] Update error message assertions to use regex patterns - [ ] Test in all target environments (node, browser, worker) - [ ] Consider migrating to the `expect` API for new tests