-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathErrorScope.spec.ts
More file actions
70 lines (61 loc) · 2.08 KB
/
Copy pathErrorScope.spec.ts
File metadata and controls
70 lines (61 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { client } from "./setup";
describe("Error Scope", () => {
it("should capture and return error messages from popErrorScope", async () => {
const result = await client.eval(({ device }) => {
// Invalid WGSL shader with syntax error (missing closing parenthesis)
const invalidShaderWGSL = `@fragment
fn main() -> @location(0) vec4f {
return vec4(1.0, 0.0, 0.0, 1.0;
}`;
device.pushErrorScope("validation");
// This should generate a validation error due to syntax error
device.createShaderModule({
code: invalidShaderWGSL,
});
return device.popErrorScope().then((error) => {
if (error) {
return {
hasError: true,
message: error.message,
messageLength: error.message.length,
messageNotEmpty: error.message.length > 0,
messageContainsExpected:
error.message.includes("expected") ||
error.message.includes("error") ||
error.message.includes("parsing"),
};
} else {
return {
hasError: false,
message: "",
messageLength: 0,
messageNotEmpty: false,
messageContainsExpected: false,
};
}
});
});
expect(result.hasError).toBe(true);
expect(result.messageNotEmpty).toBe(true);
expect(result.messageLength).toBeGreaterThan(0);
// The error message should contain some indication that it's a parsing error
expect(result.messageContainsExpected).toBe(true);
});
it("should return null when no error occurs", async () => {
const result = await client.eval(({ device, shaders: { redFragWGSL } }) => {
device.pushErrorScope("validation");
// This should not generate any errors
device.createShaderModule({
code: redFragWGSL,
});
return device.popErrorScope().then((error) => {
return {
hasError: error !== null,
error: error,
};
});
});
expect(result.hasError).toBe(false);
expect(result.error).toBe(null);
});
});