|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import os
|
| 16 | +import shutil |
16 | 17 | import subprocess
|
17 | 18 |
|
18 | 19 | from . import shared
|
19 | 20 | from . import support
|
20 | 21 |
|
21 | 22 |
|
22 |
| -def js_test_wrap(): |
| 23 | +def make_js_test_header(binaryen_js): |
23 | 24 | # common wrapper code for JS tests, waiting for binaryen.js to become ready
|
24 | 25 | # and providing common utility used by all tests:
|
25 | 26 | return '''
|
26 |
| - (async function __in_test_code__() { |
27 |
| - var binaryen = await Binaryen() |
28 |
| - function assert(x) { if (!x) throw Error('Test assertion failed'); } |
29 |
| - %TEST% |
30 |
| - })(); |
31 |
| - ''' |
| 27 | +import Binaryen from "%s"; |
| 28 | +var binaryen = await Binaryen() |
| 29 | +
|
| 30 | +// avoid stdout/stderr ordering issues in some js shells - use just stdout |
| 31 | +console.warn = console.error = console.log; |
| 32 | +
|
| 33 | +function assert(x) { |
| 34 | + if (!x) throw Error('Test assertion failed'); |
| 35 | +} |
| 36 | +''' % binaryen_js |
32 | 37 |
|
33 | 38 |
|
34 | 39 | def make_js_test(input_js_file, binaryen_js):
|
| 40 | + # Copy the binaryen.js file to binaryen.mjs for now since file |
| 41 | + # extensions matter under node. |
| 42 | + # TODO(sbc): Should binaryen build as a `.mjs` file itself? |
| 43 | + shutil.copyfile(binaryen_js, 'binaryen.mjs') |
| 44 | + |
35 | 45 | basename = os.path.basename(input_js_file)
|
36 | 46 | outname = os.path.splitext(basename)[0] + '.mjs'
|
37 | 47 | with open(outname, 'w') as f:
|
38 |
| - # avoid stdout/stderr ordering issues in some js shells - use just stdout |
39 |
| - f.write('console.warn = console.error = console.log;') |
40 |
| - binaryen_js = open(binaryen_js).read() |
41 |
| - f.write(binaryen_js) |
| 48 | + f.write(make_js_test_header('./binaryen.mjs')) |
42 | 49 | test_src = open(input_js_file).read()
|
43 |
| - f.write(js_test_wrap().replace('%TEST%', test_src)) |
| 50 | + f.write(test_src) |
44 | 51 | return outname
|
45 | 52 |
|
46 | 53 |
|
|
0 commit comments