mirror of
https://github.com/thelounge/thelounge
synced 2024-11-23 04:23:13 +00:00
dd05ee3a65
Co-authored-by: Eric Nemchik <eric@nemchik.com> Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
71 lines
1.3 KiB
TypeScript
71 lines
1.3 KiB
TypeScript
import _ from "lodash";
|
|
import express from "express";
|
|
import Network from "../server/models/network";
|
|
import Chan from "../server/models/chan";
|
|
import {EventEmitter} from "events";
|
|
import {Message} from "../server/models/msg";
|
|
|
|
class MockClient extends EventEmitter {
|
|
config: {
|
|
browser: any;
|
|
};
|
|
|
|
constructor() {
|
|
super();
|
|
|
|
this.config = {
|
|
browser: {},
|
|
};
|
|
}
|
|
|
|
createMessage(opts: any) {
|
|
const message = _.extend(
|
|
{
|
|
text: "dummy message",
|
|
nick: "test-user",
|
|
target: "#test-channel",
|
|
previews: [],
|
|
},
|
|
opts
|
|
) as Message;
|
|
|
|
return message;
|
|
}
|
|
}
|
|
|
|
function sanitizeLog(callback: (log: string) => void) {
|
|
return function (...args: string[]) {
|
|
// Concats and removes ANSI colors. See https://stackoverflow.com/a/29497680
|
|
const stdout = args
|
|
.join(" ")
|
|
.replace(
|
|
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
|
""
|
|
);
|
|
|
|
callback(stdout + "\n");
|
|
};
|
|
}
|
|
|
|
export default {
|
|
createClient() {
|
|
return new MockClient();
|
|
},
|
|
createNetwork() {
|
|
return new Network({
|
|
host: "example.com",
|
|
channels: [
|
|
new Chan({
|
|
name: "#test-channel",
|
|
}),
|
|
],
|
|
});
|
|
},
|
|
createWebserver() {
|
|
return express();
|
|
},
|
|
sanitizeLog,
|
|
isRunningOnCI() {
|
|
return process.env.CI || process.env.GITHUB_ACTIONS;
|
|
},
|
|
};
|