treewide: Enable strict equality everywhere

Making test-functions strict required some test adjustments where we
incorrectly expected an number while we receive in fact a string. As
getAttribute() returns either a string or null.
This commit is contained in:
Jelle van der Waa 2026-10-30 11:34:14 +01:00 committed by Freya Gustavsson
parent 78d5d35b38
commit ad4176e4ca
6 changed files with 24 additions and 24 deletions

View file

@ -11,7 +11,7 @@ import { getFiles, getTestFiles, all_subdirs } from './files.js';
const srcdir = import.meta.dirname;
const production = process.env.NODE_ENV === 'production';
const useWasm = os.arch() != 'x64';
const useWasm = os.arch() !== 'x64';
// ensure node_modules is present and up to date
child_process.spawnSync('tools/node-modules', ['make_package_lock_json'], { stdio: 'inherit', cwd: srcdir });
@ -173,7 +173,7 @@ async function build() {
podir: path.join(srcdir, 'po'),
subdirs: args.onlydir ? [args.onlydir] : all_subdirs,
// login page does not have cockpit.js, but reads window.cockpit_po
wrapper: subdir => subdir == "static" ? "window.cockpit_po = PO_DATA;" : undefined,
wrapper: subdir => subdir === "static" ? "window.cockpit_po = PO_DATA;" : undefined,
}),
// copy the static asset files determined in ./files.js

View file

@ -51,7 +51,7 @@ function ph_wait_visible(sel) {
const el = window.cur_doc.querySelector(sel);
if (el === null)
return false;
return el.tagName == "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(el.style.visibility == "hidden" || el.style.display == "none"));
return el.tagName === "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(el.style.visibility === "hidden" || el.style.display === "none"));
}, 10000, "timed out waiting for " + sel + " to be visible");
}
@ -60,7 +60,7 @@ function ph_wait_not_visible(sel) {
const el = window.cur_doc.querySelector(sel);
if (el === null)
return true;
return !(el.tagName == "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(el.style.visibility == "hidden" || el.style.display == "none")));
return !(el.tagName === "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(el.style.visibility === "hidden" || el.style.display === "none")));
}, 10000, "timed out waiting for " + sel + " to be visible");
}
@ -77,7 +77,7 @@ function ph_mouse(sel, type, x, y, btn, ctrlKey, shiftKey, altKey, metaKey) {
const el = window.cur_doc.querySelector(sel);
/* The element has to be visible, and not collapsed */
if (el.offsetWidth <= 0 && el.offsetHeight <= 0 && el.tagName != 'svg')
if (el.offsetWidth <= 0 && el.offsetHeight <= 0 && el.tagName !== 'svg')
throw new Error(sel + " is not visible");
/* The event has to actually work */

View file

@ -249,11 +249,11 @@ class StorageHelpers(MachineCase):
self.browser.wait_val(sel + " .size-unit select", unit)
self.browser.wait_val(sel + " .size-text input", str(val))
elif ftype == "select":
self.browser.wait_attr(sel, "data-value", val)
self.browser.wait_attr(sel, "data-value", str(val))
elif ftype == "checkbox":
self.browser.wait_visible(sel + (":checked" if val else ":not(:checked)"))
else:
self.browser.wait_val(sel, val)
self.browser.wait_val(sel, str(val))
def dialog_wait_error(self, field: str, val: str) -> None:
# XXX - allow for more than one error

View file

@ -110,7 +110,7 @@ window.ph_count = function(sel) {
};
window.ph_count_check = function(sel, expected_num) {
return (window.ph_count(sel) == expected_num);
return (window.ph_count(sel) === expected_num);
};
window.ph_val = function(sel) {
@ -130,7 +130,7 @@ window.ph_set_val = function(sel, val) {
};
window.ph_has_val = function(sel, val) {
return window.ph_val(sel) == val;
return window.ph_val(sel) === val;
};
window.ph_collected_text_is = function(sel, val) {
@ -174,7 +174,7 @@ window.ph_set_attr = function(sel, attr, val) {
};
window.ph_has_attr = function(sel, attr, val) {
return window.ph_attr(sel, attr) == val;
return window.ph_attr(sel, attr) === val;
};
window.ph_attr_contains = function(sel, attr, val) {
@ -186,7 +186,7 @@ window.ph_mouse = function(sel, type, x, y, btn, ctrlKey, shiftKey, altKey, meta
const el = window.ph_find(sel);
/* The element has to be visible, and not collapsed */
if (el.offsetWidth <= 0 && el.offsetHeight <= 0 && el.tagName != 'svg')
if (el.offsetWidth <= 0 && el.offsetHeight <= 0 && el.tagName !== 'svg')
throw new Error(sel + " is not visible");
/* The event has to actually work */
@ -250,13 +250,13 @@ window.ph_set_checked = function(sel, val) {
if (el.checked === undefined)
throw new Error(sel + " is not checkable");
if (el.checked != val)
if (el.checked !== val)
window.ph_mouse(sel, "click", 0, 0, 0);
};
window.ph_is_visible = function(sel) {
const el = window.ph_find(sel);
return el.tagName == "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(getComputedStyle(el).visibility == "hidden" || getComputedStyle(el).display == "none"));
return el.tagName === "svg" || ((el.offsetWidth > 0 || el.offsetHeight > 0) && !(getComputedStyle(el).visibility === "hidden" || getComputedStyle(el).display === "none"));
};
window.ph_is_present = function(sel) {
@ -265,11 +265,11 @@ window.ph_is_present = function(sel) {
};
window.ph_in_text = function(sel, text) {
return window.ph_text(sel).indexOf(text) != -1;
return window.ph_text(sel).indexOf(text) !== -1;
};
window.ph_text_is = function(sel, text) {
return window.ph_text(sel) == text;
return window.ph_text(sel) === text;
};
window.ph_text_matches = function(sel, pattern) {
@ -399,7 +399,7 @@ window.ph_count_animations = function(sel) {
window.ph_set_texts = function(new_texts) {
for (const sel in new_texts) {
const elts = window.ph_select(sel);
if (elts.length == 0)
if (elts.length === 0)
throw new Error(sel + " not found");
for (let elt of elts) {
// We have to be careful to not replace any actual nodes
@ -415,13 +415,13 @@ window.ph_set_texts = function(new_texts) {
//
// However, for convenience, this function digs into
// elements that have exactly one other child element.
while (elt.children.length == 1)
while (elt.children.length === 1)
elt = elt.children[0];
if (elt.children.length != 0)
if (elt.children.length !== 0)
throw new Error(sel + " can not be mocked since it contains more than text");
let subst = new_texts[sel];
for (const n of elt.childNodes) {
if (n.nodeType == 3) { // 3 == TEXT
if (n.nodeType === 3) { // 3 == TEXT
n.data = subst;
subst = "";
}

View file

@ -559,7 +559,7 @@ OnCalendar=daily
# Check what's going on while playground/preloaded is still invisible
b.switch_to_top()
b.wait_attr('iframe[name="cockpit1:localhost/playground/preloaded"]', 'data-loaded', 1)
b.wait_attr('iframe[name="cockpit1:localhost/playground/preloaded"]', 'data-loaded', "1")
b.switch_to_frame("cockpit1:localhost/playground/preloaded")
b.wait_js_func('ph_text_is', "#host", m.execute("hostname").replace("\n", ""))
time.sleep(3)

View file

@ -223,7 +223,7 @@ PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/
b.wait_in_text(line_sel(n), '$')
# Test changing of font size
b.wait_val("#toolbar input", 16)
b.wait_val("#toolbar input", "16")
current_style = b.attr(".xterm-accessibility-tree div:first-child", "style")
b.click("#toolbar button[aria-label='Increase by one']")
new_style = b.attr(".xterm-accessibility-tree div:first-child", "style")
@ -246,16 +246,16 @@ PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/
b.wait_visible('.terminal')
b.wait_in_text(line_sel(n), '$')
b.wait_attr_contains(".xterm-scrollable-element", "style", white_style)
b.wait_val("#toolbar input", 17)
b.wait_val("#toolbar input", "17")
b.wait_attr(".xterm-accessibility-tree div:first-child", "style", new_style)
b.click("#toolbar button[aria-label='Decrease by one']")
b.wait_val("#toolbar input", 16)
b.wait_val("#toolbar input", "16")
b.wait_attr(".xterm-accessibility-tree div:first-child", "style", current_style)
# Check limit for font size
for i in range(15, 5, -1):
b.click("#toolbar button[aria-label='Decrease by one']")
b.wait_val("#toolbar input", i)
b.wait_val("#toolbar input", str(i))
b.wait_visible("#toolbar button[aria-label='Decrease by one']:disabled")
@testlib.skipBrowser("WebGL2 is not supported in firefox headless mode, terminal page will not load", "firefox")