Skip to content

Commit

Permalink
test(ssr): add tests for @wire errors (#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Nov 21, 2024
1 parent 08ec091 commit 7e27944
Show file tree
Hide file tree
Showing 42 changed files with 215 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/@lwc/engine-server/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,22 @@ function testFixtures(options?: RollupLwcOptions) {
pattern: '**/index.js',
},
async ({ filename, dirname, config }) => {
const compiledFixturePath = await compileFixture({
input: filename,
dirname,
options,
});
let compiledFixturePath;

try {
compiledFixturePath = await compileFixture({
input: filename,
dirname,
options,
});
} catch (err: any) {
// Filter out the stacktrace, just include the LWC error message
const message = err?.message?.match(/(LWC\d+[^\n]+)/)?.[1];
return {
'expected.html': '',
'error.txt': message ?? '',
};
}

// The LWC engine holds global state like the current VM index, which has an impact on
// the generated HTML IDs. So the engine has to be re-evaluated between tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1200: Computed property in @wire config must be a constant or primitive literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
const symbol = Symbol.for("key");
export default class Test extends LightningElement {
// accidentally an array expression = oops!
@wire(Adapter, { [[symbol]]: "$prop1", key2: ["fixed", "array"] })
wiredFoo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1200: Computed property in @wire config must be a constant or primitive literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
let key1 = 'key1'
export default class Test extends LightningElement {
@wire(Adapter, { [key1]: "$prop1", key2: ["fixed", "array"] })
wiredFoo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1200: Computed property in @wire config must be a constant or primitive literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@wire(Adapter, { [/key1/]: "$prop1", key2: ["fixed", "array"] })
wiredFoo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1199: Cannot use a template literal as a computed property key. Instead, use a string or extract the value to a constant.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@wire(Adapter, { [`key1`]: "$prop1", key2: ["fixed", "array"] })
wiredFoo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1105: Method or property can only have 1 @wire decorator
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@wire(Adapter, { key1: "$prop1", key2: ["fixed", "array"] })
@wire(Adapter, { key1: "$prop1", key2: ["fixed", "array"] })
multipleWire;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1095: @wire method or property cannot be used with @api
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { api, wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@api
@wire(Adapter, { key1: "$prop1", key2: ["fixed"] })
wiredWithApi() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1095: @wire method or property cannot be used with @api
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { api, wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@api
@wire(Adapter, { key1: "$prop1", key2: ["fixed", "array"] })
wiredPropWithApi;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LWC1095: @wire method or property cannot be used with @track
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-wire';
export { default } from 'x/wire';
export * from 'x/wire';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Adapter {
constructor(dataCallback) {
this.callback = dataCallback;
}

connect() {}

update() {
this.callback(true);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { track, wire, LightningElement } from "lwc";
import { Adapter } from "x/adapter";
export default class Test extends LightningElement {
@track
@wire(Adapter, { key1: "$prop1", key2: ["fixed", "array"] })
wiredWithTrack;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ export const expectedFailures = new Set([
'superclass/render-in-superclass/unused-default-in-subclass/index.js',
'superclass/render-in-superclass/unused-default-in-superclass/index.js',
'svgs/index.js',
'wire/errors/throws-when-computed-prop-is-expression/index.js',
'wire/errors/throws-when-computed-prop-is-let-variable/index.js',
'wire/errors/throws-when-computed-prop-is-regexp-literal/index.js',
'wire/errors/throws-when-computed-prop-is-template-literal/index.js',
'wire/errors/throws-when-using-2-wired-decorators/index.js',
'wire/errors/throws-when-wired-method-is-combined-with-@api/index.js',
'wire/errors/throws-when-wired-property-is-combined-with-@api/index.js',
'wire/errors/throws-when-wired-property-is-combined-with-@track/index.js',
]);

0 comments on commit 7e27944

Please sign in to comment.