Fix test failures on Windows

Fix broken regex, too tight time check, and lack of shell expansion on
Windows causing test cases to fail or not run at all.
This commit is contained in:
Hornwitser committed 2021-02-17 21:21:18 +01:00
1 parent 01e442c42e
commit 09c3f82226
5 files changed
+23 -19

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
"name": "root",
"private": true,
"scripts": {
"test": "mocha --exit --check-leaks -R spec --recursive test plugins/*/test",
"test": "mocha --exit --check-leaks -R spec --recursive test plugins/global_chat/test plugins/research_sync/test plugins/statistics_exporter/test plugins/subspace_storage/test",
"fast-test": "FAST_TEST=y npm test",
"cover": "nyc npm test",
"fast-cover": "FAST_TEST=y nyc npm test",
+1 -16
View File
@@ -11,24 +11,9 @@ const ini = require("ini");
const rconClient = require("rcon-client");
const libErrors = require("@clusterio/lib/errors");
const { logger } = require("@clusterio/lib/logging");
const { escapeRegExp } = require("@clusterio/lib/helpers");
/**
* Escapes text for inclusion in a RegExp
*
* Adds \ character in front of special meta characters in the passsed in
* text so that it can be embedded into a RegExp and only match the text.
*
* See https://stackoverflow.com/a/9310752
*
* @param {string} text - Text to escape RegExp meta chars in.
* @returns {string} escaped text.
* @inner
*/
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
/**
* Determines the version of Factorio the datadir is pointing to by
* reading the changelog.txt in it.
+17
View File
@@ -75,9 +75,26 @@ async function readStream(stream) {
}
/**
* Escapes text for inclusion in a RegExp
*
* Adds \ character in front of special meta characters in the passsed in
* text so that it can be embedded into a RegExp and only match the text.
*
* See https://stackoverflow.com/a/9310752
*
* @param {string} text - Text to escape RegExp meta chars in.
* @returns {string} escaped text.
*/
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
module.exports = {
basicType,
wait,
timeout,
readStream,
escapeRegExp,
};
+2 -1
View File
@@ -23,7 +23,8 @@ describe("lib/helpers", function() {
await libHelpers.wait(100);
let duration = Number(hrtime() - startNs) / 1e6;
assert(duration > 90 && duration < 110, `duration waited (${duration}ms) 10% of expected (100ms)`);
// On windows the time waited is normally up to 15 ms late with outliers in the 20ms range.
assert(duration > 90 && duration < 130, `duration (${duration}ms) not within (90-130)`);
});
});
+2 -1
View File
@@ -4,6 +4,7 @@ const fs = require("fs-extra");
const path = require("path");
const libPluginLoader = require("@clusterio/lib/plugin_loader");
const { escapeRegExp } = require("@clusterio/lib/helpers");
describe("lib/plugin_loader", function() {
@@ -34,7 +35,7 @@ describe("lib/plugin_loader", function() {
it("should throw on missing plugin", async function() {
await assert.rejects(
libPluginLoader.loadPluginInfos(new Map([["missing", missingPlugin]]), []),
new RegExp(`^Error: PluginError: Cannot find module '${missingPlugin}/info'`)
new RegExp(`^Error: PluginError: Cannot find module '${escapeRegExp(missingPlugin)}/info'`)
);
});
it("should load test plugin", async function() {