thelounge/test/util.js

68 lines
1.2 KiB
JavaScript
Raw Normal View History

"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");
function MockClient() {
this.config = {
browser: {},
};
}
util.inherits(MockClient, EventEmitter);
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
);
return message;
2015-09-30 22:39:57 +00:00
};
function sanitizeLog(callback) {
return function (...args) {
// 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,
""
);
callback(stdout + "\n");
};
}
module.exports = {
createClient() {
2015-09-30 22:39:57 +00:00
return new MockClient();
},
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
},
createWebserver() {
2015-09-30 22:39:57 +00:00
return express();
},
sanitizeLog,
isRunningOnCI() {
return process.env.CI || process.env.GITHUB_ACTIONS;
},
2015-09-30 22:39:57 +00:00
};