Skip to content

Commit d33fb13

Browse files
fix: added locker flag to tests
1 parent 3eee968 commit d33fb13

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

packages/@lwc/engine-core/src/framework/base-lightning-element.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ export const LightningElement: LightningElementConstructor = function (
244244

245245
setPrototypeOf(elm, bridge.prototype);
246246

247-
if (lwcRuntimeFlags.ENABLE_LEGACY_LOCKER_SUPPORT) {
248-
vm.component = this;
249-
}
247+
vm.component = this;
250248

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

262-
if (lwcRuntimeFlags.ENABLE_LEGACY_LOCKER_SUPPORT) {
263-
markLockerLiveObject(this);
264-
}
260+
markLockerLiveObject(this);
265261

266262
// Linking elm, shadow root and component with the VM.
267263
associateVM(this, vm);

packages/@lwc/engine-core/src/framework/invoker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { addErrorComponentStack } from '../shared/error';
1111
import { evaluateTemplate, setVMBeingRendered, getVMBeingRendered } from './template';
1212
import { runWithBoundaryProtection } from './vm';
1313
import { logOperationStart, logOperationEnd, OperationId } from './profiler';
14+
import { LightningElement } from './base-lightning-element';
1415
import type { Template } from './template';
1516
import type { VM } from './vm';
16-
import type { LightningElement, LightningElementConstructor } from './base-lightning-element';
17+
import type { LightningElementConstructor } from './base-lightning-element';
1718
import type { VNodes } from './vnodes';
1819

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

6465
if (isInvalidConstructor) {
6566
throw new TypeError(

packages/@lwc/integration-karma/test/api/createElement/index.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createElement, LightningElement } from 'lwc';
1+
import { createElement, LightningElement, setFeatureFlagForTest } from 'lwc';
22
import { isNativeShadowRootInstance, isSyntheticShadowRootInstance } from 'test-utils';
33

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

9999
describe('locker integration', () => {
100+
beforeEach(() => {
101+
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', true);
102+
});
103+
afterEach(() => {
104+
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', false);
105+
});
100106
it('should support component class that extend a mirror of the LightningElement', () => {
101107
function SecureBaseClass() {
102108
if (this instanceof SecureBaseClass) {

packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NotReturningThis from 'x/notReturningThis';
55
import ParentThrowingBeforeSuper from 'x/parentThrowingBeforeSuper';
66
import DefinedComponent from 'x/definedComponent';
77
import UndefinedComponent from 'x/undefinedComponent';
8-
import ReturningBad from 'x/returningBad'
8+
import ReturningBad from 'x/returningBad';
99

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

84-
fit('should fail when the constructor returns something other than an instance of itself', () => {
84+
it('should fail when the constructor returns something other than an instance of itself', () => {
8585
expect(() => {
8686
createElement('x-returning-bad', { is: ReturningBad });
8787
}).toThrowError(
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import { LightningElement } from 'lwc'
1+
import { LightningElement } from 'lwc';
22

33
export default class MyClass extends LightningElement {
44
constructor() {
5-
super()
5+
super();
66

7-
const bad = {}
8-
LightningElement.call(bad)
7+
const bad = {};
8+
LightningElement.call(bad);
99

10-
return bad
10+
return bad;
1111
}
1212
}
13-
14-
let counter = -1
15-
Object.defineProperty(MyClass, Symbol.hasInstance, {
16-
value: function() {
17-
console.log('counter', ++counter)
18-
return true;
19-
},
20-
});

packages/@lwc/integration-karma/test/integrations/locker/index.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { createElement } from 'lwc';
1+
import { createElement, setFeatureFlagForTest } from 'lwc';
22

33
import LockerIntegration from 'x/lockerIntegration';
44
import LockerLiveComponent from 'x/lockerLiveComponent';
55
import LockerHooks, { hooks } from 'x/lockerHooks';
6-
6+
beforeEach(() => {
7+
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', true);
8+
});
9+
afterEach(() => {
10+
setFeatureFlagForTest('ENABLE_LEGACY_LOCKER_SUPPORT', false);
11+
});
712
it('should support Locker integration which uses a wrapped LightningElement base class', () => {
813
const elm = createElement('x-secure-parent', { is: LockerIntegration });
914
document.body.appendChild(elm);

0 commit comments

Comments
 (0)