View | Details | Raw Unified | Return to bug 40809
Collapse All | Expand All

(-)a/t/cypress/support/e2e.js (-11 / +16 lines)
Lines 25-44 Link Here
25
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
25
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26
26
27
// Error on JS warnings
27
// Error on JS warnings
28
function safeToString(arg) {
29
    try {
30
        return JSON.stringify(arg);
31
    } catch (e) {
32
        return `[object ${arg.constructor?.name || typeof arg}]`;
33
    }
34
}
35
36
function stringifyArgs(args) {
37
    return args.map(safeToString).join(" ");
38
}
28
Cypress.on("window:before:load", win => {
39
Cypress.on("window:before:load", win => {
29
    win.console.warn = (...args) => {
40
    win.console.warn = (...args) => {
30
        if (args[0] && typeof args[0] === "string") {
41
        const message = stringifyArgs(args);
31
            throw new Error(`JS Warning detected: ${args[0]}`);
42
        throw new Error(`JS Warning detected: ${message}`);
32
        }
33
    };
43
    };
34
    win.console.log = (...args) => {
44
    win.console.log = (...args) => {
35
        if (args[0] && typeof args[0] === "string") {
45
        const message = stringifyArgs(args);
36
            if (args[0].match(/DataTables warning: /)) {
46
        if (message.match(/DataTables warning: /)) {
37
                throw new Error(
47
            throw new Error(`DataTables warning detected in log: ${message}`);
38
                    `DataTables warning detected in log: ${args[0]}`
39
                );
40
            }
41
            console.log(args[0]);
42
        }
48
        }
43
    };
49
    };
44
});
50
});
45
- 

Return to bug 40809