Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test:
cd packages/xmpp.js/ && npm run prepublish
npm install
make bundle
npx jest
npm run test
make lint
make bundlesize

Expand All @@ -40,7 +40,7 @@ e2e:
cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2_sm > /dev/null
cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2_fast > /dev/null
npm run e2e
node --test browser.test.js
node --test test/browser.js

clean:
make stop
Expand Down
38 changes: 19 additions & 19 deletions babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ module.exports = function config(api) {
const isTest = api.env("test");

if (isTest) {
return {
plugins: [
[
"@babel/plugin-transform-react-jsx",
{
pragma: "xml",
throwIfNamespace: false,
},
],
[
"babel-plugin-jsx-pragmatic",
{
module: "@xmpp/xml",
import: "xml",
},
],
"@babel/plugin-transform-modules-commonjs",
],
};
return {};
// return {
// plugins: [
// [
// "@babel/plugin-transform-react-jsx",
// {
// pragma: "xml",
// throwIfNamespace: false,
// },
// ],
// [
// "babel-plugin-jsx-pragmatic",
// {
// module: "@xmpp/xml",
// import: "xml",
// },
// ],
// ],
// };
}

return {
Expand Down
11 changes: 6 additions & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export default [
...globals.builtin,
...globals["shared-node-browser"],
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
// parserOptions: {
// ecmaFeatures: {
// jsx: false,
// },
// },
sourceType: "module",
},

Expand Down Expand Up @@ -128,6 +128,7 @@ export default [
"@xmpp/websocket",
"selfsigned",
"@xmpp/events",
"@jest/globals",
],
},
],
Expand Down
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
"<rootDir>/packages/test/",
],
setupFilesAfterEnv: ["jest-extended/all"],
transform: {},
};
50 changes: 9 additions & 41 deletions package-lock.json

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

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
"type": "module",
"devDependencies": {
"@babel/core": "^7.28.5",
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
"@babel/plugin-transform-react-jsx": "^7.27.1",
"@babel/plugin-transform-runtime": "^7.28.5",
"@babel/preset-env": "^7.28.5",
"@babel/runtime": "^7.28.4",
"@jest/globals": "^30.2.0",
"@rollup/plugin-babel": "^6.1.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-terser": "^0.4.4",
"babel-jest": "^30.2.0",
"babel-plugin-jsx-pragmatic": "^1.0.2",
"bytes": "^3.1.2",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8",
Expand All @@ -31,12 +28,13 @@
"lerna": "^9.0.3",
"lint-staged": "^16.2.7",
"prettier": "^3.7.4",
"promise-port": "^1.0.1",
"rollup": "^4.53.3",
"selfsigned": "^5.2.0"
},
"scripts": {
"test": "node ./node_modules/.bin/jest --forceExit",
"e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./node_modules/.bin/jest --forceExit --runInBand --config e2e.config.cjs",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --forceExit",
"e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 node --experimental-vm-modules ./node_modules/.bin/jest --forceExit --runInBand --config e2e.config.cjs",
"preversion": "make bundle"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions packages/client-core/test/Client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JID } from "@xmpp/test";
import { JID, xml } from "@xmpp/test";

import Client from "../lib/Client.js";

Expand Down Expand Up @@ -36,17 +36,17 @@ test("header", () => {

entity.jid = null;
entity.isSecure = () => false;
expect(entity.header(<foo />)).toEqual(<foo />);
expect(entity.header(xml("foo"))).toEqual(xml("foo"));

entity.jid = null;
entity.isSecure = () => true;
expect(entity.header(<foo />)).toEqual(<foo />);
expect(entity.header(xml("foo"))).toEqual(xml("foo"));

entity.jid = new JID("foo@bar/example");
entity.isSecure = () => false;
expect(entity.header(<foo />)).toEqual(<foo />);
expect(entity.header(xml("foo"))).toEqual(xml("foo"));

entity.jid = new JID("foo@bar/example");
entity.isSecure = () => true;
expect(entity.header(<foo />)).toEqual(<foo from="foo@bar" />);
expect(entity.header(xml("foo"))).toEqual(xml("foo", { from: "foo@bar" }));
});
70 changes: 37 additions & 33 deletions packages/client-core/test/fast.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { jest } from "@jest/globals";
import { tick } from "@xmpp/events";
import { mockClient } from "@xmpp/test";
import { mockClient, xml } from "@xmpp/test";
import { datetime } from "@xmpp/time";
import { Element } from "@xmpp/xml";

Expand All @@ -11,16 +12,17 @@ test("requests and saves token if server advertises fast", async () => {
const spy_saveToken = jest.spyOn(fast, "saveToken");

entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<fast xmlns="urn:xmpp:fast:0">
<mechanism>{mechanism}</mechanism>
</fast>
</inline>
</authentication>
</features>,
// prettier-ignore
xml('features', { xmlns: "http://etherx.jabber.org/streams" },
xml('authentication', { xmlns: "urn:xmpp:sasl:2" },
xml('mechanism', {}, "PLAIN"),
xml('inline', {},
xml('fast', { xmlns: "urn:xmpp:fast:0" },
xml('mechanism', {}, mechanism)
)
)
)
),
);

const authenticate = await entity.catchOutgoing();
Expand All @@ -37,12 +39,11 @@ test("requests and saves token if server advertises fast", async () => {
expect(spy_saveToken).not.toHaveBeenCalled();

entity.mockInput(
<success xmlns="urn:xmpp:sasl:2">
<token expiry={expiry} xmlns="urn:xmpp:fast:0" token={token} />
<authorization-identifier>
username@localhost/rOYwkWIywtnF
</authorization-identifier>
</success>,
// prettier-ignore
xml('success', { xmlns: "urn:xmpp:sasl:2" },
xml('token', { expiry, xmlns: "urn:xmpp:fast:0" , token}),
xml('authorization-identifier', {}, "username@localhost/rOYwkWIywtnF")
),
);

expect(spy_saveToken).toHaveBeenCalledWith({ token, expiry, mechanism });
Expand All @@ -64,16 +65,17 @@ async function setupFast() {
};

entity.mockInput(
<features xmlns="http://etherx.jabber.org/streams">
<authentication xmlns="urn:xmpp:sasl:2">
<mechanism>PLAIN</mechanism>
<inline>
<fast xmlns="urn:xmpp:fast:0">
<mechanism>{mechanism}</mechanism>
</fast>
</inline>
</authentication>
</features>,
// prettier-ignore
xml('features', { xmlns: "http://etherx.jabber.org/streams" },
xml('authentication', { xmlns: "urn:xmpp:sasl:2" },
xml('mechanism', {}, "PLAIN"),
xml('inline', {},
xml('fast', { xmlns: "urn:xmpp:fast:0" },
xml('mechanism', {}, mechanism)
)
)
)
),
);

expect(fast.mechanism).toBe(mechanism);
Expand All @@ -94,9 +96,10 @@ test("deletes the token if server replies with not-authorized", async () => {

expect(spy_deleteToken).not.toHaveBeenCalled();
entity.mockInput(
<failure xmlns="urn:xmpp:sasl:2">
<not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
</failure>,
// prettier-ignore
xml("failure", { xmlns: "urn:xmpp:sasl:2" },
xml("not-authorized", { xmlns: "urn:ietf:params:xml:ns:xmpp-sasl" }),
),
);
await tick();
expect(spy_deleteToken).toHaveBeenCalled();
Expand All @@ -109,9 +112,10 @@ test("deletes the token if server replies with credentials-expired", async () =>
// credentials-expired
expect(spy_deleteToken).not.toHaveBeenCalled();
entity.mockInput(
<failure xmlns="urn:xmpp:sasl:2">
<credentials-expired xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
</failure>,
// prettier-ignore
xml("failure", { xmlns: "urn:xmpp:sasl:2" },
xml("credentials-expired", { xmlns: "urn:ietf:params:xml:ns:xmpp-sasl" }),
),
);
await tick();
expect(spy_deleteToken).toHaveBeenCalled();
Expand Down
1 change: 1 addition & 0 deletions packages/connection/test/_closeStream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from "@jest/globals";
import { EventEmitter, promise, TimeoutError } from "@xmpp/events";
import { xml } from "@xmpp/test";

Expand Down
5 changes: 4 additions & 1 deletion packages/connection/test/disconnect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { jest } from "@jest/globals";
import { xml } from "@xmpp/test";

import Connection from "../index.js";

test("disconnect", async () => {
Expand Down Expand Up @@ -69,7 +72,7 @@ test("disconnect with _closeStream and _closeSocket rejections", async () => {

test("resolves if socket property is undefined", async () => {
const conn = new Connection();
conn.footerElement = () => <foo />;
conn.footerElement = () => xml("foo");
conn.socket = undefined;
await conn.disconnect();
expect().pass();
Expand Down
Loading
Loading