-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebgl-shader-errors.test.ts
More file actions
77 lines (66 loc) · 2.17 KB
/
webgl-shader-errors.test.ts
File metadata and controls
77 lines (66 loc) · 2.17 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
71
72
73
74
75
76
77
import assert from 'node:assert/strict'
import { collectShaderDiagnostics, diagnosticsToMessages } from './webgl-shader-errors.ts'
function runTest(name: string, callback: () => void) {
callback()
console.log(`ok ${name}`)
}
type MockShader = {
ok: boolean
log: string | null
}
type MockProgram = {
log: string | null
}
const mockGl = {
COMPILE_STATUS: 1,
getProgramInfoLog(program: unknown) {
return (program as MockProgram).log
},
getShaderInfoLog(shader: unknown) {
return (shader as MockShader).log
},
getShaderParameter(shader: unknown) {
return (shader as MockShader).ok
},
}
runTest('collectShaderDiagnostics returns shader and link logs', () => {
const diagnostics = collectShaderDiagnostics({
gl: mockGl,
program: { log: 'Program Info Log: link failed' },
vertexShader: { ok: false, log: 'VERTEX ERROR: undeclared identifier' },
fragmentShader: { ok: false, log: 'FRAGMENT ERROR: syntax error' },
})
assert.deepEqual(diagnostics, [
{ kind: 'glsl-compile', message: 'VERTEX ERROR: undeclared identifier' },
{ kind: 'glsl-compile', message: 'FRAGMENT ERROR: syntax error' },
{ kind: 'glsl-link', message: 'Program Info Log: link failed' },
])
assert.deepEqual(diagnosticsToMessages(diagnostics), [
'VERTEX ERROR: undeclared identifier',
'FRAGMENT ERROR: syntax error',
'Program Info Log: link failed',
])
})
runTest('collectShaderDiagnostics falls back to a generic compile message', () => {
const diagnostics = collectShaderDiagnostics({
gl: mockGl,
program: { log: null },
vertexShader: { ok: false, log: null },
fragmentShader: { ok: true, log: null },
})
assert.deepEqual(diagnostics, [
{ kind: 'glsl-compile', message: 'GLSL shader compilation failed.' },
])
})
runTest('collectShaderDiagnostics falls back to a generic link message', () => {
const diagnostics = collectShaderDiagnostics({
gl: mockGl,
program: { log: null },
vertexShader: { ok: true, log: null },
fragmentShader: { ok: true, log: null },
})
assert.deepEqual(diagnostics, [
{ kind: 'glsl-link', message: 'GLSL program linking failed.' },
])
})
console.log('webgl-shader-errors tests passed')