@@ -67,9 +67,107 @@ tape( 'if an environment does not support `WebAssembly`, the function throws an
6767} ) ;
6868
6969tape ( 'the function is a constructor' , opts , function test ( t ) {
70- // TODO: write tests
70+ var wasm ;
71+ var mod ;
7172
73+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
74+ mod = new Module ( wasm , null ) ;
75+
76+ t . strictEqual ( mod instanceof Module , true , 'returns expected value' ) ;
7277 t . end ( ) ;
7378} ) ;
7479
75- // TODO: add tests
80+ tape ( 'the function returns an instance having an `initialize` method which returns a promise' , opts , function test ( t ) {
81+ var wasm ;
82+ var mod ;
83+ var p ;
84+
85+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
86+ mod = new Module ( wasm , null ) ;
87+ p = mod . initialize ( ) ;
88+
89+ t . strictEqual ( typeof p . then , 'function' , 'returns expected value' ) ;
90+ t . end ( ) ;
91+ } ) ;
92+
93+ tape ( 'the function returns an instance having an `initialize` method which returns a promise resolving with the module instance' , opts , function test ( t ) {
94+ var wasm ;
95+ var mod ;
96+
97+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
98+ mod = new Module ( wasm , null ) ;
99+
100+ mod . initialize ( ) . then ( onResolve , onReject ) ;
101+
102+ function onResolve ( result ) {
103+ t . strictEqual ( result , mod , 'resolves expected value' ) ;
104+ t . strictEqual ( typeof result . exports , 'object' , 'returns expected value' ) ;
105+ t . end ( ) ;
106+ }
107+
108+ function onReject ( error ) {
109+ t . fail ( 'should not reject: ' + error . message ) ;
110+ t . end ( ) ;
111+ }
112+ } ) ;
113+
114+ tape ( 'the function returns an instance having an `initializeAsync` method which invokes a callback' , opts , function test ( t ) {
115+ var wasm ;
116+ var mod ;
117+
118+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
119+ mod = new Module ( wasm , null ) ;
120+
121+ mod . initializeAsync ( clbk ) ;
122+
123+ function clbk ( error ) {
124+ if ( error ) {
125+ t . fail ( 'callback received an error: ' + error . message ) ;
126+ } else {
127+ t . pass ( 'callback invoked without error' ) ;
128+ }
129+ t . end ( ) ;
130+ }
131+ } ) ;
132+
133+ tape ( 'the function returns an instance having an `initializeAsync` method which invokes a callback with the module instance' , opts , function test ( t ) {
134+ var wasm ;
135+ var mod ;
136+
137+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
138+ mod = new Module ( wasm , null ) ;
139+
140+ mod . initializeAsync ( clbk ) ;
141+
142+ function clbk ( error , result ) {
143+ if ( error ) {
144+ t . fail ( 'callback received an error: ' + error . message ) ;
145+ t . end ( ) ;
146+ return ;
147+ }
148+ t . strictEqual ( result , mod , 'returns expected value' ) ;
149+ t . strictEqual ( typeof result . exports , 'object' , 'returns expected value' ) ;
150+ t . end ( ) ;
151+ }
152+ } ) ;
153+
154+ tape ( 'the function returns an instance having an `exports` property which is available after initialization' , opts , function test ( t ) {
155+ var wasm ;
156+ var mod ;
157+
158+ wasm = new Uint8Array ( [ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 ] ) ;
159+ mod = new Module ( wasm , null ) ;
160+
161+ mod . initialize ( ) . then ( onResolve , onReject ) ;
162+
163+ function onResolve ( result ) {
164+ var exports = result . exports ;
165+ t . strictEqual ( typeof exports , 'object' , 'returns expected value' ) ;
166+ t . end ( ) ;
167+ }
168+
169+ function onReject ( error ) {
170+ t . fail ( 'should not reject: ' + error . message ) ;
171+ t . end ( ) ;
172+ }
173+ } ) ;
0 commit comments