Skip to content

Commit

Permalink
Remove sinon
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 20, 2024
1 parent cfdc97e commit c504048
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 115 deletions.
10 changes: 2 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 0 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 2 additions & 4 deletions packages/jid/test/index.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
28 changes: 13 additions & 15 deletions packages/starttls/test.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -18,31 +19,26 @@ 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(
<features xmlns="http://etherx.jabber.org/streams">
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
</features>,
);

expect(await promise(entity, "send")).toEqual(<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />);
expect(await promise(entity, "send")).toEqual(
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />,
);

entity.mockInput(<proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />);

await delay();

expectTLSConnect.verify();
expect(tls.connect).toHaveBeenCalledTimes(1);
expect(tls.connect).toHaveBeenCalledWith({ socket, host: "foobar" });
});

test("failure", async () => {
Expand All @@ -55,7 +51,9 @@ test("failure", async () => {
</features>,
);

expect(await promise(entity, "send")).toEqual(<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />);
expect(await promise(entity, "send")).toEqual(
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />,
);

entity.mockInput(<failure xmlns="urn:ietf:params:xml:ns:xmpp-tls" />);

Expand Down

0 comments on commit c504048

Please sign in to comment.