@sockethub/irc2as 4.0.0-alpha.3 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/package.json +12 -21
- package/src/as-emitter.js +258 -255
- package/src/index.js +273 -230
- package/src/index.test.data.js +492 -108
- package/src/index.test.js +85 -82
- package/coverage/tmp/coverage-93092-1649152170899-0.json +0 -1
package/src/index.test.js
CHANGED
|
@@ -1,93 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const expect = chai.expect;
|
|
1
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { validateActivityStream } from "@sockethub/schemas";
|
|
4
|
+
import equal from "fast-deep-equal";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ircdata =
|
|
10
|
-
const inputs = ircdata.split(
|
|
6
|
+
import { IrcToActivityStreams } from "./index.js";
|
|
7
|
+
import { TestData } from "./index.test.data.js";
|
|
8
|
+
const ircdata = readFileSync(__dirname + "/index.test.data.irc.txt", "utf-8");
|
|
9
|
+
const inputs = ircdata.split("\n");
|
|
11
10
|
|
|
12
11
|
function matchStream(done) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
return (stream) => {
|
|
13
|
+
expect(typeof stream.published).toEqual("string");
|
|
14
|
+
delete stream.published;
|
|
15
|
+
let matched = false;
|
|
16
|
+
for (let i = 0; i <= TestData.length; i++) {
|
|
17
|
+
matched = equal(stream, TestData[i]);
|
|
18
|
+
if (matched) {
|
|
19
|
+
// when matched, remove output entry from list
|
|
20
|
+
TestData.splice(i, 1);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!matched) {
|
|
25
|
+
console.log();
|
|
26
|
+
console.log("available matches:" + JSON.stringify(TestData));
|
|
27
|
+
console.log("failed to find match for: " + JSON.stringify(stream));
|
|
28
|
+
return done(new Error("failed matching " + JSON.stringify(stream)));
|
|
29
|
+
}
|
|
30
|
+
const err = validateActivityStream(stream);
|
|
31
|
+
if (err) {
|
|
32
|
+
return done(new Error(err + " - " + JSON.stringify(stream)));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
describe(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
describe("IrcToActivityStreams", () => {
|
|
38
|
+
let irc2as,
|
|
39
|
+
pongs = 0,
|
|
40
|
+
pings = 0;
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
irc2as = new IrcToActivityStreams({ server: "localhost" });
|
|
43
|
+
expect(irc2as).toHaveProperty("events");
|
|
44
|
+
expect(typeof irc2as.events.on).toEqual("function");
|
|
45
|
+
irc2as.events.on("unprocessed", (string) => {
|
|
46
|
+
console.log("unprocessed> " + string);
|
|
47
|
+
});
|
|
48
|
+
irc2as.events.on("pong", () => {
|
|
49
|
+
pongs++;
|
|
50
|
+
});
|
|
51
|
+
irc2as.events.on("ping", () => {
|
|
52
|
+
pings++;
|
|
53
|
+
});
|
|
50
54
|
});
|
|
51
|
-
irc2as.events.on('ping', (time) => {
|
|
52
|
-
pings++;
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
describe("inputs generate expected outputs", () => {
|
|
57
|
+
it("inputs generate expected outputs", (done) => {
|
|
58
|
+
irc2as.events.on("incoming", matchStream(done));
|
|
59
|
+
irc2as.events.on("error", matchStream(done));
|
|
60
|
+
for (let i = 0; inputs.length > i; i++) {
|
|
61
|
+
irc2as.input(inputs[i]);
|
|
62
|
+
}
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
expect(TestData.length).toEqual(0);
|
|
65
|
+
done();
|
|
66
|
+
}, 0);
|
|
67
|
+
});
|
|
68
|
+
it("ping and pong count", () => {
|
|
69
|
+
expect(pings).toEqual(2);
|
|
70
|
+
expect(pongs).toEqual(3);
|
|
71
|
+
});
|
|
71
72
|
});
|
|
72
|
-
});
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
describe("handle many room joins", () => {
|
|
75
|
+
let totalCount = 0;
|
|
76
|
+
it("send join messages", (done) => {
|
|
77
|
+
irc2as.events.on("incoming", () => {
|
|
78
|
+
totalCount += 1;
|
|
79
|
+
if (totalCount === 5 * 100) {
|
|
80
|
+
done();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
for (let i = 0; i < 5; i++) {
|
|
84
|
+
let names =
|
|
85
|
+
":hitchcock.freenode.net 353 hyper_slvrbckt @ #kosmos-random :hyper_slvrbckt ";
|
|
86
|
+
for (let n = 0; n < 100; n++) {
|
|
87
|
+
names += ` gregkare${i}${n} hal8000${i}${n} botka${i}${n} raucao${i}${n} galfert${i}${n}`;
|
|
88
|
+
}
|
|
89
|
+
irc2as.input(names);
|
|
90
|
+
}
|
|
91
|
+
irc2as.input(
|
|
92
|
+
":hitchcock.freenode.net 366 hyper_slvrbckt #kosmos-random :End of /NAMES list.",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
91
95
|
});
|
|
92
|
-
});
|
|
93
96
|
});
|