Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function windowErrorListener(callback) {
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
// only be caught with window.addEventListener('error')
// - Note native lifecycle callbacks are all thrown asynchronously.
function customElementCallbackReactionErrorListener(callback) {
export function customElementCallbackReactionErrorListener(callback) {
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
? directErrorListener(callback)
: windowErrorListener(callback);
Expand Down
44 changes: 0 additions & 44 deletions packages/@lwc/integration-not-karma/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,6 @@
* An as yet uncategorized mishmash of helpers, relics of Karma
*/

// Listen for errors thrown directly by the callback
function directErrorListener(callback) {
try {
callback();
} catch (error) {
return error;
}
}

// Listen for errors using window.addEventListener('error')
function windowErrorListener(callback) {
let error;
function onError(event) {
event.preventDefault(); // don't log the error
error = event.error;
}

// Prevent jasmine from handling the global error. There doesn't seem to be another
// way to disable this behavior: https://github.com/jasmine/jasmine/pull/1860
const originalOnError = window.onerror;
window.onerror = null;
window.addEventListener('error', onError);

try {
callback();
} finally {
window.onerror = originalOnError;
window.removeEventListener('error', onError);
}
return error;
}

// For errors we expect to be thrown in the connectedCallback() phase
// of a custom element, there are two possibilities:
// 1) We're using non-native lifecycle callbacks, so the error is thrown synchronously
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
// only be caught with window.addEventListener('error')
// - Note native lifecycle callbacks are all thrown asynchronously.
export function customElementCallbackReactionErrorListener(callback) {
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
? directErrorListener(callback)
: windowErrorListener(callback);
}

export function extractDataIds(root) {
const nodes = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ENABLE_ELEMENT_INTERNALS_AND_FACE,
IS_SYNTHETIC_SHADOW_LOADED,
} from '../../../../helpers/constants.js';
import { customElementCallbackReactionErrorListener } from '../../../../helpers/utils.js';
import { customElementCallbackReactionErrorListener } from '../../../../helpers/matchers/errors.js';

const testConnectedCallbackError = (elm, msg) => {
const error = customElementCallbackReactionErrorListener(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createElement } from 'lwc';
import Test from 'x/test';
import ConnectedCallbackThrow from 'x/connectedCallbackThrow';
import XSlottedParent from 'x/slottedParent';
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';

function testConnectSlot(name, fn) {
it(`should invoke the connectedCallback the root element is added in the DOM via ${name}`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DisconnectedCallbackThrow from 'x/disconnectedCallbackThrow';
import DualTemplate from 'x/dualTemplate';
import ExplicitRender from 'x/explicitRender';
import { jasmine } from '../../../helpers/jasmine.js';
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';

function testDisconnectSlot(name, fn) {
it(`should invoke the disconnectedCallback when root element is removed from the DOM via ${name}`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createElement, registerTemplate } from 'lwc';
import DynamicTemplate, { template1, template2 } from 'x/dynamicTemplate';
import RenderThrow from 'x/renderThrow';
import RenderInvalid from 'x/renderInvalid';
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';

function testInvalidTemplate(type, template) {
it(`throws an error if returns ${type}`, () => {
Expand Down