Skip to content

Commit

Permalink
fix: added locker flag to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhefferman-sfdc committed Jan 16, 2025
1 parent 3eee968 commit d33fb13
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ export const LightningElement: LightningElementConstructor = function (

setPrototypeOf(elm, bridge.prototype);

if (lwcRuntimeFlags.ENABLE_LEGACY_LOCKER_SUPPORT) {
vm.component = this;
}
vm.component = this;

// Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
// component creation and passes hooks to instrument all the component interactions with the
Expand All @@ -259,9 +257,7 @@ export const LightningElement: LightningElementConstructor = function (
vm.getHook = getHook;
}

if (lwcRuntimeFlags.ENABLE_LEGACY_LOCKER_SUPPORT) {
markLockerLiveObject(this);
}
markLockerLiveObject(this);

// Linking elm, shadow root and component with the VM.
associateVM(this, vm);
Expand Down
5 changes: 3 additions & 2 deletions packages/@lwc/engine-core/src/framework/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { addErrorComponentStack } from '../shared/error';
import { evaluateTemplate, setVMBeingRendered, getVMBeingRendered } from './template';
import { runWithBoundaryProtection } from './vm';
import { logOperationStart, logOperationEnd, OperationId } from './profiler';
import { LightningElement } from './base-lightning-element';
import type { Template } from './template';
import type { VM } from './vm';
import type { LightningElement, LightningElementConstructor } from './base-lightning-element';
import type { LightningElementConstructor } from './base-lightning-element';
import type { VNodes } from './vnodes';

export let isInvokingRender: boolean = false;
Expand Down Expand Up @@ -59,7 +60,7 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru
// invoked by accessing the component on the vm.
const isInvalidConstructor = lwcRuntimeFlags.ENABLE_LEGACY_LOCKER_SUPPORT
? vmBeingConstructed.component !== result
: !(result instanceof Ctor);
: !(result instanceof LightningElement);

if (isInvalidConstructor) {
throw new TypeError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, LightningElement } from 'lwc';
import { createElement, LightningElement, setFeatureFlagForTest } from 'lwc';
import { isNativeShadowRootInstance, isSyntheticShadowRootInstance } from 'test-utils';

import Test from 'x/test';
Expand Down Expand Up @@ -97,6 +97,12 @@ describe.runIf(process.env.NATIVE_SHADOW)('native shadow', () => {
});

describe('locker integration', () => {
beforeEach(() => {
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', true);
});
afterEach(() => {
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', false);
});
it('should support component class that extend a mirror of the LightningElement', () => {
function SecureBaseClass() {
if (this instanceof SecureBaseClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NotReturningThis from 'x/notReturningThis';
import ParentThrowingBeforeSuper from 'x/parentThrowingBeforeSuper';
import DefinedComponent from 'x/definedComponent';
import UndefinedComponent from 'x/undefinedComponent';
import ReturningBad from 'x/returningBad'
import ReturningBad from 'x/returningBad';

it('should throw when trying to invoke the constructor manually', () => {
const func = () => {
Expand Down Expand Up @@ -81,7 +81,7 @@ it("[W-6981076] shouldn't throw when a component with an invalid child in unmoun
expect(() => document.body.removeChild(elm)).not.toThrow();
});

fit('should fail when the constructor returns something other than an instance of itself', () => {
it('should fail when the constructor returns something other than an instance of itself', () => {
expect(() => {
createElement('x-returning-bad', { is: ReturningBad });
}).toThrowError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { LightningElement } from 'lwc'
import { LightningElement } from 'lwc';

export default class MyClass extends LightningElement {
constructor() {
super()
super();

const bad = {}
LightningElement.call(bad)
const bad = {};
LightningElement.call(bad);

return bad
return bad;
}
}

let counter = -1
Object.defineProperty(MyClass, Symbol.hasInstance, {
value: function() {
console.log('counter', ++counter)
return true;
},
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { createElement } from 'lwc';
import { createElement, setFeatureFlagForTest } from 'lwc';

import LockerIntegration from 'x/lockerIntegration';
import LockerLiveComponent from 'x/lockerLiveComponent';
import LockerHooks, { hooks } from 'x/lockerHooks';

beforeEach(() => {
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', true);
});
afterEach(() => {
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', false);
});
it('should support Locker integration which uses a wrapped LightningElement base class', () => {
const elm = createElement('x-secure-parent', { is: LockerIntegration });
document.body.appendChild(elm);
Expand Down

0 comments on commit d33fb13

Please sign in to comment.