2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
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");
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
function MockClient() {
|
2019-07-16 09:51:22 +00:00
|
|
|
this.config = {
|
|
|
|
browser: {},
|
|
|
|
};
|
2014-11-17 20:14:28 +00:00
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2014-11-17 20:14:28 +00:00
|
|
|
util.inherits(MockClient, EventEmitter);
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
MockClient.prototype.createMessage = function (opts) {
|
2019-07-17 09:33:59 +00:00
|
|
|
const message = _.extend(
|
|
|
|
{
|
|
|
|
text: "dummy message",
|
|
|
|
nick: "test-user",
|
|
|
|
target: "#test-channel",
|
|
|
|
previews: [],
|
|
|
|
},
|
|
|
|
opts
|
|
|
|
);
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2016-12-09 20:46:53 +00:00
|
|
|
return message;
|
2015-09-30 22:39:57 +00:00
|
|
|
};
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2018-03-20 05:54:04 +00:00
|
|
|
function sanitizeLog(callback) {
|
2020-03-21 20:55:36 +00:00
|
|
|
return function (...args) {
|
2017-11-22 06:39:32 +00:00
|
|
|
// Concats and removes ANSI colors. See https://stackoverflow.com/a/29497680
|
2019-07-17 09:33:59 +00:00
|
|
|
const stdout = args
|
|
|
|
.join(" ")
|
|
|
|
.replace(
|
|
|
|
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
|
|
|
""
|
|
|
|
);
|
2017-12-09 07:11:05 +00:00
|
|
|
|
|
|
|
callback(stdout + "\n");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-11-17 20:14:28 +00:00
|
|
|
module.exports = {
|
2018-03-05 00:59:16 +00:00
|
|
|
createClient() {
|
2015-09-30 22:39:57 +00:00
|
|
|
return new MockClient();
|
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
createNetwork() {
|
2016-03-20 14:39:59 +00:00
|
|
|
return new Network({
|
|
|
|
host: "example.com",
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [
|
|
|
|
new Chan({
|
|
|
|
name: "#test-channel",
|
|
|
|
}),
|
|
|
|
],
|
2016-03-20 14:39:59 +00:00
|
|
|
});
|
2015-09-30 22:39:57 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
createWebserver() {
|
2015-09-30 22:39:57 +00:00
|
|
|
return express();
|
2017-11-15 06:35:15 +00:00
|
|
|
},
|
2018-03-20 05:54:04 +00:00
|
|
|
sanitizeLog,
|
2020-02-09 12:21:45 +00:00
|
|
|
isRunningOnCI() {
|
|
|
|
return process.env.CI || process.env.GITHUB_ACTIONS;
|
|
|
|
},
|
2015-09-30 22:39:57 +00:00
|
|
|
};
|