Skip to content

Commit 455ca32

Browse files
committed
fix types
1 parent b2ef943 commit 455ca32

12 files changed

+114
-12
lines changed

test/functional-tests.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Mocha from 'mocha';
2+
3+
import { create, globals } from '../index.js';
4+
5+
Object.assign(globalThis, globals);
6+
globalThis.navigator = { gpu: create([]) };
7+
8+
const mocha = new Mocha({});
9+
10+
mocha.addFile('./test/tests/basic-tests.js');
11+
12+
await mocha.loadFilesAsync();
13+
mocha.run(failures => {
14+
delete globalThis.navigator;
15+
process.exit(failures);
16+
});

test/test.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import Mocha from 'mocha';
1+
import fs from 'node:fs';
2+
import { execute } from '../build/execute.js';
23

3-
import { create, globals } from '../index.js';
4+
const cwd = process.cwd();
45

5-
Object.assign(globalThis, globals);
6-
globalThis.navigator = { gpu: create([]) };
6+
await execute('node', ['test/functional-tests.js']);
77

8-
const mocha = new Mocha({});
8+
const tsTestsDir = 'test/ts-tests';
9+
const tests = fs.readdirSync(tsTestsDir, { withFileTypes: true })
10+
.filter(t => t.isDirectory())
11+
.map(t => `${tsTestsDir}/${t.name}`);
912

10-
mocha.addFile('./test/tests/basic-tests.js');
13+
for (const test of tests) {
14+
console.log('testing:', test);
15+
process.chdir(test);
16+
fs.rmSync('node_modules', { recursive: true, force: true });
17+
await execute('npm', ['i', '--no-package-lock']);
18+
await execute('npm', ['test']);
19+
process.chdir(cwd);
20+
}
1121

12-
await mocha.loadFilesAsync();
13-
mocha.run(failures => {
14-
delete globalThis.navigator;
15-
process.exit(failures);
16-
});

test/ts-tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
index.js

test/ts-tests/ts5.1/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { globals, create } from 'webgpu';
2+
3+
Object.assign(globalThis, globals);
4+
const navigator = { gpu: create([]) };
5+
6+
const adapter = await navigator.gpu.requestAdapter();
7+
if (adapter) {
8+
const device = await adapter.requestDevice();
9+
console.log(device.adapterInfo.description);
10+
device.destroy();
11+
}
12+
13+
await new Promise(r => setTimeout(r, 1000));
14+
15+

test/ts-tests/ts5.1/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "tsc --version && tsc"
5+
},
6+
"dependencies": {
7+
"webgpu": "file:../../..",
8+
"typescript": "~5.1.0"
9+
}
10+
}

test/ts-tests/ts5.1/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["index.ts"]
4+
}

test/ts-tests/ts5.7/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { globals, create } from 'webgpu';
2+
3+
Object.assign(globalThis, globals);
4+
const navigator = { gpu: create([]) };
5+
6+
const adapter = await navigator.gpu.requestAdapter();
7+
if (adapter) {
8+
const device = await adapter.requestDevice();
9+
console.log(device.adapterInfo.description);
10+
device.destroy();
11+
}
12+
13+
await new Promise(r => setTimeout(r, 1000));
14+
15+

test/ts-tests/ts5.7/js-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { globals, create } from 'webgpu';
2+
3+
Object.assign(globalThis, globals);
4+
const navigator = { gpu: create([]) };
5+
6+
const adapter = await navigator.gpu.requestAdapter();
7+
const device = await adapter?.requestDevice();
8+
console.log(device?.adapterInfo.description);
9+
device.destroy();
10+
11+
await new Promise(r => setTimeout(r, 1000));
12+

test/ts-tests/ts5.7/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "tsc --version && tsc"
5+
},
6+
"dependencies": {
7+
"webgpu": "file:../../..",
8+
"typescript": "~5.7.0"
9+
}
10+
}

test/ts-tests/ts5.7/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["index.ts"]
4+
}

test/ts-tests/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"moduleResolution": "NodeNext",
5+
"strict": true,
6+
"target": "ESNext",
7+
"lib": ["DOM", "ESNext"]
8+
}
9+
}

types.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from '@webgpu/types';
1+
import '@webgpu/types';
22
export declare function create(options: string[]): GPU;
33
export declare const globals: Object;

0 commit comments

Comments
 (0)