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 || {};
|
|
|
|
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore if */
|
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 {
|
2021-06-28 00:41:05 +02:00
|
|
|
namespace._start_template_mocking();
|
2022-01-08 10:27:06 +01:00
|
|
|
namespace.with_overrides(({override, override_rewire}) => {
|
|
|
|
f({override, override_rewire, mock_template: namespace._mock_template});
|
2021-06-16 14:38:37 +02:00
|
|
|
});
|
2021-06-28 00:41:05 +02:00
|
|
|
namespace._finish_template_mocking();
|
2022-04-09 23:44:38 +02:00
|
|
|
} catch (error) /* istanbul ignore next */ {
|
2020-12-01 00:39:47 +01:00
|
|
|
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
|
|
|
};
|