From 1432058880798e5c2da228f04e278ef77f3cd265 Mon Sep 17 00:00:00 2001 From: Alberto Zaccagni Date: Tue, 16 Jul 2024 13:00:23 +0000 Subject: [PATCH] remove chai in favor of node:assert --- src/testing/testing.ts | 24 +++++++++++++----------- tests/testing/testing.test.ts | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/testing/testing.ts b/src/testing/testing.ts index 6c8f667..9982e9f 100644 --- a/src/testing/testing.ts +++ b/src/testing/testing.ts @@ -1,6 +1,5 @@ import {Node} from "../model/model"; -import {fail} from "assert"; -import {expect} from "chai"; +import {strictEqual,deepStrictEqual,fail} from "node:assert"; export function assertASTsAreEqual( expected: Node, @@ -10,7 +9,7 @@ export function assertASTsAreEqual( ): void { if (areSameType(expected, actual)) { if (considerPosition) { - expect(actual.position, `${context}.position`).to.eql(expected.position); + deepStrictEqual(actual.position, expected.position, `${context}.position`); } expected.features.forEach(expectedProperty => { const actualPropValue = actual.features.find(p => p.name == expectedProperty.name)!.value; @@ -25,10 +24,11 @@ export function assertASTsAreEqual( ); } else if (Array.isArray(actualPropValue) && Array.isArray(expectedPropValue)) { - expect( + strictEqual( actualPropValue.length, + expectedPropValue.length, `${context}, property ${expectedProperty.name} has length ${expectedPropValue.length}, but found ${actualPropValue.length}` - ).to.equal(expectedPropValue.length) + ); for (let i = 0; i < expectedPropValue.length; i++) { const expectedElement = expectedPropValue[i]; const actualElement = actualPropValue[i]; @@ -42,18 +42,20 @@ export function assertASTsAreEqual( ); } else if (typeof expectedElement != "object" && typeof actualElement != "object") { - expect( + strictEqual( actualElement, - `${context}, property ${expectedProperty.name}[${i}] is ${expectedPropValue[i]}, but found ${actualPropValue[i]}` - ).to.equal(expectedElement); + expectedElement, + `${context}, property ${expectedProperty.name}[${i}] is ${expectedPropValue[i]}, but found ${actualPropValue[i]}`, + ); } } } else { - expect( + strictEqual( actualPropValue, - `${context}, comparing property ${expectedProperty.name}` - ).to.equal(expectedPropValue); + expectedPropValue, + `${context}, property ${expectedProperty.name} is '${expectedPropValue}', but found '${actualPropValue}'` + ); } }); } diff --git a/tests/testing/testing.test.ts b/tests/testing/testing.test.ts index 084876e..b19c9ad 100644 --- a/tests/testing/testing.test.ts +++ b/tests/testing/testing.test.ts @@ -40,7 +40,7 @@ describe('AssertASTsAreEqual', function() { const simpleNode2 : Node = new SimpleNode("different node"); expect(() => assertASTsAreEqual(simpleNode1, simpleNode2) - ).to.throw("expected 'different node' to equal 'node'"); + ).to.throw(", property name is 'node', but found 'different node'"); }); it("two different node instances of two different types, but with same values must NOT pass", function () { const node1 : Node = new SimpleNode("node");