2020-12-01 00:39:47 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const namespace = require("./namespace");
|
2021-03-16 23:38:59 +01:00
|
|
|
const zblueslip = require("./zblueslip");
|
2021-02-23 12:05:28 +01:00
|
|
|
const $ = require("./zjquery");
|
2021-04-03 18:52:00 +02:00
|
|
|
const zpage_params = require("./zpage_params");
|
2020-12-01 00:39:47 +01:00
|
|
|
|
|
|
|
let current_file_name;
|
|
|
|
let verbose = false;
|
|
|
|
|
|
|
|
exports.set_current_file_name = (value) => {
|
|
|
|
current_file_name = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_verbose = (value) => {
|
|
|
|
verbose = value;
|
|
|
|
};
|
|
|
|
|
2021-02-23 12:05:28 +01:00
|
|
|
exports.run_test = (label, f, opts) => {
|
|
|
|
const {sloppy_$} = opts || {};
|
|
|
|
|
2020-12-01 00:39:47 +01:00
|
|
|
if (verbose) {
|
|
|
|
console.info(" test: " + label);
|
|
|
|
}
|
2021-02-23 12:05:28 +01:00
|
|
|
|
|
|
|
if (!sloppy_$ && $.clear_all_elements) {
|
|
|
|
$.clear_all_elements();
|
|
|
|
}
|
2021-04-03 18:52:00 +02:00
|
|
|
zpage_params.reset();
|
2021-02-23 12:05:28 +01:00
|
|
|
|
2020-12-01 00:39:47 +01:00
|
|
|
try {
|
|
|
|
namespace.with_overrides(f);
|
|
|
|
} catch (error) {
|
|
|
|
console.info("-".repeat(50));
|
|
|
|
console.info(`test failed: ${current_file_name} > ${label}`);
|
|
|
|
console.info();
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
// defensively reset blueslip after each test.
|
2021-03-16 23:38:59 +01:00
|
|
|
zblueslip.reset();
|
2020-12-01 00:39:47 +01:00
|
|
|
};
|