From c504048f4a00c1674fdd572814a61a4e79d8d8c5 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Fri, 20 Dec 2024 21:38:08 +0100 Subject: [PATCH] Remove sinon --- eslint.config.mjs | 10 +---- package-lock.json | 87 -------------------------------------- package.json | 1 - packages/jid/test/index.js | 6 +-- packages/starttls/test.js | 28 ++++++------ 5 files changed, 17 insertions(+), 115 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 8554be0b..3c3edd07 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -55,14 +55,8 @@ export default [ // node // https://github.com/eslint-community/eslint-plugin-n/ "n/no-unpublished-require": 0, // doesn't play nice with monorepo - "n/no-extraneous-require": [ - "error", - { allowModules: ["sinon", "@xmpp/test"] }, - ], - "n/no-extraneous-import": [ - "error", - { allowModules: ["sinon", "@xmpp/test"] }, - ], + "n/no-extraneous-require": ["error", { allowModules: ["@xmpp/test"] }], + "n/no-extraneous-import": ["error", { allowModules: ["@xmpp/test"] }], "n/hashbang": "off", // promise diff --git a/package-lock.json b/package-lock.json index c4fbec98..cf41dafa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,6 @@ "node-fetch": "^2.6.12", "prettier": "^3.4.2", "selfsigned": "^2.4.1", - "sinon": "^19.0.2", "uglify-js": "^3.19.3" }, "engines": { @@ -3900,37 +3899,6 @@ "type-detect": "4.0.8" } }, - "node_modules/@sinonjs/fake-timers": { - "version": "13.0.5", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@sinonjs/commons": "^3.0.1" - } - }, - "node_modules/@sinonjs/samsam": { - "version": "8.0.2", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "lodash.get": "^4.4.2", - "type-detect": "^4.1.0" - } - }, - "node_modules/@sinonjs/samsam/node_modules/type-detect": { - "version": "4.1.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/@sinonjs/text-encoding": { - "version": "0.7.3", - "dev": true, - "license": "(Unlicense OR Apache-2.0)" - }, "node_modules/@tufjs/canonical-json": { "version": "2.0.0", "dev": true, @@ -6721,14 +6689,6 @@ "node": ">=0.8.0" } }, - "node_modules/diff": { - "version": "7.0.0", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/diff-sequences": { "version": "29.6.3", "dev": true, @@ -10641,11 +10601,6 @@ "dev": true, "license": "MIT" }, - "node_modules/just-extend": { - "version": "6.2.0", - "dev": true, - "license": "MIT" - }, "node_modules/kind-of": { "version": "6.0.3", "license": "MIT", @@ -11510,11 +11465,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.get": { - "version": "4.4.2", - "dev": true, - "license": "MIT" - }, "node_modules/lodash.ismatch": { "version": "4.4.0", "dev": true, @@ -12407,18 +12357,6 @@ "dev": true, "license": "MIT" }, - "node_modules/nise": { - "version": "6.1.1", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.1", - "@sinonjs/text-encoding": "^0.7.3", - "just-extend": "^6.2.0", - "path-to-regexp": "^8.1.0" - } - }, "node_modules/node-abi": { "version": "2.30.1", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.30.1.tgz", @@ -13487,14 +13425,6 @@ "dev": true, "license": "ISC" }, - "node_modules/path-to-regexp": { - "version": "8.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=16" - } - }, "node_modules/path-type": { "version": "4.0.0", "dev": true, @@ -14680,23 +14610,6 @@ "simple-concat": "^1.0.0" } }, - "node_modules/sinon": { - "version": "19.0.2", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.2", - "@sinonjs/samsam": "^8.0.1", - "diff": "^7.0.0", - "nise": "^6.1.1", - "supports-color": "^7.2.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/sinon" - } - }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", diff --git a/package.json b/package.json index c5d225d8..c52a1223 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "node-fetch": "^2.6.12", "prettier": "^3.4.2", "selfsigned": "^2.4.1", - "sinon": "^19.0.2", "uglify-js": "^3.19.3" }, "scripts": { diff --git a/packages/jid/test/index.js b/packages/jid/test/index.js index f99a6db7..f8cf4e29 100644 --- a/packages/jid/test/index.js +++ b/packages/jid/test/index.js @@ -1,16 +1,14 @@ "use strict"; -const { spy } = require("sinon"); const jid = require(".."); const JID = require("../lib/JID"); test("equal calls equals on the first argument with the second argument", () => { const A = jid("foo"); const B = jid("bar"); - spy(A, "equals"); + const spy_equals = jest.spyOn(A, "equals"); jid.equal(A, B); - expect(A.equals.calledWith(B)).toBe(true); - A.equals.restore(); + expect(spy_equals).toHaveBeenCalledWith(B); }); test("JID exports lib/JID", () => { diff --git a/packages/starttls/test.js b/packages/starttls/test.js index 494c982e..7fc0b240 100644 --- a/packages/starttls/test.js +++ b/packages/starttls/test.js @@ -1,6 +1,7 @@ "use strict"; -const { mock, stub } = require("sinon"); +jest.mock("tls"); + const { mockClient, promise, delay } = require("@xmpp/test"); const tls = require("tls"); const net = require("net"); @@ -18,17 +19,9 @@ test("success", async () => { const { socket, options } = entity; options.domain = "foobar"; - const mockTLS = mock(tls); - const expectTLSConnect = mockTLS - .expects("connect") - .once() - .withArgs({ socket, host: "foobar" }) - .callsFake(() => { - return new EventEmitter(); - }); - - stub(entity, "_attachSocket"); - stub(entity, "restart"); + tls.connect.mockImplementation(() => { + return new EventEmitter(); + }); entity.mockInput( @@ -36,13 +29,16 @@ test("success", async () => { , ); - expect(await promise(entity, "send")).toEqual(); + expect(await promise(entity, "send")).toEqual( + , + ); entity.mockInput(); await delay(); - expectTLSConnect.verify(); + expect(tls.connect).toHaveBeenCalledTimes(1); + expect(tls.connect).toHaveBeenCalledWith({ socket, host: "foobar" }); }); test("failure", async () => { @@ -55,7 +51,9 @@ test("failure", async () => { , ); - expect(await promise(entity, "send")).toEqual(); + expect(await promise(entity, "send")).toEqual( + , + ); entity.mockInput();