2026-03-29 12:24:30 +02:00
|
|
|
import {showGlobalErrorMessage, shouldIgnoreError} from './errors.ts';
|
2024-01-21 22:23:08 +08:00
|
|
|
|
|
|
|
|
test('showGlobalErrorMessage', () => {
|
|
|
|
|
document.body.innerHTML = '<div class="page-content"></div>';
|
|
|
|
|
showGlobalErrorMessage('test msg 1');
|
|
|
|
|
showGlobalErrorMessage('test msg 2');
|
|
|
|
|
showGlobalErrorMessage('test msg 1'); // duplicated
|
|
|
|
|
|
|
|
|
|
expect(document.body.innerHTML).toContain('>test msg 1 (2)<');
|
|
|
|
|
expect(document.body.innerHTML).toContain('>test msg 2<');
|
|
|
|
|
expect(document.querySelectorAll('.js-global-error').length).toEqual(2);
|
|
|
|
|
});
|
2026-02-12 21:59:13 +01:00
|
|
|
|
|
|
|
|
test('shouldIgnoreError', () => {
|
|
|
|
|
for (const url of [
|
2026-03-29 12:24:30 +02:00
|
|
|
'https://gitea.test/assets/js/monaco.D14TzjS9.js',
|
|
|
|
|
'https://gitea.test/assets/js/editor.api2.BdhK7zNg.js',
|
|
|
|
|
'https://gitea.test/assets/js/editor.worker.BYgvyFya.js',
|
2026-02-12 21:59:13 +01:00
|
|
|
]) {
|
|
|
|
|
const err = new Error('test');
|
|
|
|
|
err.stack = `Error: test\n at ${url}:1:1`;
|
|
|
|
|
expect(shouldIgnoreError(err)).toEqual(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const otherError = new Error('test');
|
|
|
|
|
otherError.stack = 'Error: test\n at https://gitea.test/assets/js/index.js:1:1';
|
|
|
|
|
expect(shouldIgnoreError(otherError)).toEqual(false);
|
|
|
|
|
});
|