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");
|
2023-03-18 19:01:20 +01:00
|
|
|
const zpage_billing_params = require("./zpage_billing_params");
|
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;
|
|
|
|
};
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
exports.noop = () => {};
|
|
|
|
|
2022-05-07 02:53:53 +02:00
|
|
|
exports.suite = [];
|
|
|
|
|
2024-09-21 01:19:52 +02:00
|
|
|
async function execute_test(label, f) {
|
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
|
|
|
|
2024-09-21 01:19:52 +02:00
|
|
|
$.clear_all_elements();
|
2023-03-18 19:01:20 +01:00
|
|
|
zpage_billing_params.reset();
|
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-08-18 02:13:22 +02:00
|
|
|
await namespace.with_overrides(async (helpers) => {
|
|
|
|
await f({
|
2022-07-09 23:25:05 +02:00
|
|
|
...helpers,
|
|
|
|
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();
|
2022-05-07 02:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.run_test = (label, f, opts) => {
|
|
|
|
exports.suite.push(() => execute_test(label, f, opts));
|
2020-12-01 00:39:47 +01:00
|
|
|
};
|