File tree Expand file tree Collapse file tree 4 files changed +90
-0
lines changed
Expand file tree Collapse file tree 4 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ${LIB_TITLE} WASM Benchmarks
3+ */
4+
5+ import $ { LIB_TITLE } WASM from "../src/lib/index.ts"
6+
7+ Deno . bench ( "${LIB_NAME} initialization" , {
8+ baseline : true
9+ } , async ( ) => {
10+ const lib = new $ { LIB_TITLE } WASM ( )
11+ await lib . initialize ( )
12+ } )
Original file line number Diff line number Diff line change 1+ /**
2+ * @module ${LIB_TITLE} WASM
3+ * TypeScript-first ${LIB_TITLE} library for WebAssembly
4+ */
5+
6+ export default class $ { LIB_TITLE } WASM {
7+ private module : any = null
8+ private initialized = false
9+
10+ async initialize ( ) : Promise < void > {
11+ if ( this . initialized ) return
12+
13+ // Load WASM module
14+ this . module = await this . loadWASM ( )
15+ this . initialized = true
16+ }
17+
18+ private async loadWASM ( ) : Promise < any > {
19+ // Try local build first
20+ const localPaths = [
21+ './../../install/wasm/${LIB_NAME}-main.js' ,
22+ './../../install/wasm/${LIB_NAME}-release.js' ,
23+ ]
24+
25+ for ( const path of localPaths ) {
26+ try {
27+ const modulePath = new URL ( path , import . meta. url ) . href
28+ const mod = await import ( modulePath )
29+ return await mod . default ( )
30+ } catch ( e ) {
31+ continue
32+ }
33+ }
34+
35+ throw new Error ( 'Failed to load ${LIB_NAME}.wasm' )
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * Type definitions for ${LIB_TITLE} WASM
3+ */
4+
5+ export interface $ { LIB_UPPER } Module {
6+ _malloc: ( size : number ) => number
7+ _free: ( ptr : number ) => void
8+ HEAPU8 : Uint8Array
9+ setValue: ( ptr : number , value : number , type : string ) => void
10+ getValue : ( ptr : number , type : string ) => number
11+ }
12+
13+ export class $ { LIB_UPPER } Error extends Error {
14+ constructor ( message : string ) {
15+ super ( message )
16+ this . name = '${LIB_UPPER}Error'
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ import { assert , assertExists } from "@std/assert"
2+
3+ Deno . test ( "Deno runtime features" , ( ) => {
4+ assert ( typeof Deno !== 'undefined' , "Deno runtime should be available" )
5+ assert ( typeof WebAssembly !== 'undefined' , "WebAssembly should be available" )
6+ } )
7+
8+ Deno . test ( "WASM file accessibility" , async ( ) => {
9+ try {
10+ const wasmFile = await Deno . stat ( "./install/wasm/${LIB_NAME}-main.wasm" )
11+ assert ( wasmFile . isFile , "WASM file should exist" )
12+ assert ( wasmFile . size > 0 , "WASM file should not be empty" )
13+ console . log ( `✅ Found WASM file: ${ wasmFile . size } bytes` )
14+ } catch ( error ) {
15+ console . warn ( "⚠️ WASM file not found - run 'deno task build:wasm' first" )
16+ }
17+ } )
18+
19+ Deno . test ( "TypeScript module imports" , async ( ) => {
20+ const { default : Module } = await import ( "../../src/lib/index.ts" )
21+ assertExists ( Module , "Module class should be importable" )
22+ assert ( typeof Module === 'function' , "Module should be a constructor function" )
23+ } )
You can’t perform that action at this time.
0 commit comments