Skip to content

Commit 80c9a21

Browse files
committed
claner
1 parent 662cbee commit 80c9a21

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

packages/typegpu/tests/partialIo.noEval.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ import { describe, expect, vi } from 'vitest';
88
import { it } from 'typegpu-testing-utility';
99
import type { TypedArray } from '../src/shared/utilityTypes.ts';
1010
import type { WriteInstruction } from '../src/data/partialIO.ts';
11+
import { getPatchInstructions } from '../src/data/partialIO.ts';
12+
import * as d from '../src/data/index.ts';
1113

1214
vi.mock('../src/data/compiledIO.ts', () => ({
1315
EVAL_ALLOWED_IN_ENV: false,
1416
getCompiledWriter: () => undefined,
1517
buildWriter: () => '',
1618
}));
1719

18-
// Dynamic imports are required AFTER vi.mock to get the mocked versions.
19-
const { getPatchInstructions } = await import('../src/data/partialIO.ts');
20-
const d = await import('../src/data/index.ts');
21-
2220
function expectInstruction(
23-
instruction: WriteInstruction,
21+
instruction: WriteInstruction | undefined,
2422
{
2523
start,
2624
length,
@@ -31,6 +29,9 @@ function expectInstruction(
3129
expectedData: TypedArray | TypedArray[];
3230
},
3331
): void {
32+
if (!instruction) {
33+
throw new Error('Instruction is undefined');
34+
}
3435
expect(instruction.gpuOffset).toBe(start);
3536
expect(instruction.data.byteLength).toBe(length);
3637

@@ -43,13 +44,12 @@ function expectInstruction(
4344
offset += arr.byteLength;
4445
}
4546

46-
expect(instruction.data).toHaveLength(totalByteLength);
4747
expect(new Uint8Array(instruction.data)).toStrictEqual(mergedExpected);
4848
}
4949

5050
describe('getPatchInstructions (no-eval / typed-binary fallback)', () => {
5151
it('should produce correct instructions for a scalar', () => {
52-
const instructions = getPatchInstructions(d.u32, 3) as [WriteInstruction];
52+
const instructions = getPatchInstructions(d.u32, 3);
5353
expect(instructions).toHaveLength(1);
5454
expectInstruction(instructions[0], {
5555
start: 0,
@@ -69,7 +69,7 @@ describe('getPatchInstructions (no-eval / typed-binary fallback)', () => {
6969
a: 3,
7070
b: d.vec3f(1, 2, 3),
7171
c: { d: 4 },
72-
}) as [WriteInstruction];
72+
});
7373

7474
expect(instructions).toHaveLength(1);
7575
expectInstruction(instructions[0], {
@@ -91,7 +91,7 @@ describe('getPatchInstructions (no-eval / typed-binary fallback)', () => {
9191

9292
const instructions = getPatchInstructions(struct, {
9393
b: { 1: d.vec3f(4, 5, 6) },
94-
}) as [WriteInstruction];
94+
});
9595

9696
expect(instructions).toHaveLength(1);
9797
expectInstruction(instructions[0], {
@@ -108,9 +108,7 @@ describe('getPatchInstructions (no-eval / typed-binary fallback)', () => {
108108
});
109109

110110
// Only patch b, leaving a out — creates a gap after start
111-
const instructions = getPatchInstructions(struct, { b: d.vec3f(1, 2, 3) }) as [
112-
WriteInstruction,
113-
];
111+
const instructions = getPatchInstructions(struct, { b: d.vec3f(1, 2, 3) });
114112

115113
expect(instructions).toHaveLength(1);
116114
expectInstruction(instructions[0], {

0 commit comments

Comments
 (0)