forked from thelounge/thelounge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
67 lines (59 loc) · 1.23 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
const EventEmitter = require("events").EventEmitter;
const util = require("util");
const _ = require("lodash");
const express = require("express");
const Network = require("../src/models/network");
const Chan = require("../src/models/chan");
function MockClient() {
this.config = {
browser: {},
};
}
util.inherits(MockClient, EventEmitter);
MockClient.prototype.createMessage = function (opts) {
const message = _.extend(
{
text: "dummy message",
nick: "test-user",
target: "#test-channel",
previews: [],
},
opts
);
return message;
};
function sanitizeLog(callback) {
return function (...args) {
// 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");
};
}
module.exports = {
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;
},
};