@sockethub/irc2as 4.0.0-alpha.4 → 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/src/index.test.js CHANGED
@@ -1,93 +1,96 @@
1
- const chai = require('chai');
2
- const schemas = require('@sockethub/schemas').default;
3
- const fs = require("fs");
4
- const equal = require('fast-deep-equal');
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
- const IRC2AS = require('./index');
8
- const outputs = require('./index.test.data');
9
- const ircdata = fs.readFileSync('./src/index.test.data.irc.txt', 'utf-8');
10
- const inputs = ircdata.split('\n');
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
- return (stream) => {
14
- expect(typeof stream.published).to.eql('string');
15
- delete stream.published;
16
- let matched = false;
17
- for (let i = 0; i <= outputs.length; i++) {
18
- matched = equal(stream, outputs[i]);
19
- if (matched) {
20
- // when matched, remove output entry from list
21
- outputs.splice(i, 1);
22
- break;
23
- }
24
- }
25
- if (! matched) {
26
- console.log();
27
- console.log('available matches:' + JSON.stringify(outputs));
28
- console.log('failed to find match for: ' + JSON.stringify(stream));
29
- return done(new Error('failed matching ' + JSON.stringify(stream)));
30
- }
31
- const err = schemas.validateActivityStream(stream);
32
- if (err) {
33
- return done(new Error(err + ' - ' + JSON.stringify(stream)));
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('IRC2AS', () => {
39
- let irc2as, pongs = 0, pings = 0;
40
- // it("provides expected properties", () => {
41
- beforeEach(() => {
42
- irc2as = new IRC2AS({server: 'localhost'});
43
- expect(irc2as).to.have.property('events');
44
- expect(typeof irc2as.events.on).to.equal('function');
45
- irc2as.events.on('unprocessed', (string) => {
46
- console.log('unprocessed> ' + string);
47
- });
48
- irc2as.events.on('pong', (time) => {
49
- pongs++;
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
- 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(outputs.length).to.equal(0);
65
- done();
66
- }, 0);
67
- });
68
- it("ping and pong count", () => {
69
- expect(pings).to.eql(2);
70
- expect(pongs).to.eql(3);
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
- 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 = ':hitchcock.freenode.net 353 hyper_slvrbckt @ #kosmos-random :hyper_slvrbckt ';
85
- for (let n = 0; n < 100; n++) {
86
- names += ` gregkare${i}${n} hal8000${i}${n} botka${i}${n} raucao${i}${n} galfert${i}${n}`;
87
- }
88
- irc2as.input(names);
89
- }
90
- irc2as.input(':hitchcock.freenode.net 366 hyper_slvrbckt #kosmos-random :End of /NAMES list.');
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
  });