Skip to content

Conversation

@DrSensor
Copy link
Owner

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • documentations
  • metadata update

Motivation / Use-Case

future plans

Additional Info

TODO:

  1. Fix smoke-test in rs-jest and rollup-plugin-rust
  2. Use webassembly-loader in those projects

📋 also, copy helper function for writing tests from binaryen-loader
😂 tslint doesn't like json
X can be:
🐣 'buffer' will export wasm code as Buffer class
🐥 'module' or 'async-module' will export wasm code as WebAssembly.Module
🐤 'instance' or 'async-instance' will export wasm code as WebAssembly.Instance
🐔 'async' will "instantiate" wasm code asynchronously

waiting for v17.1 to resolve d.ts issue when bundling
👉 ezolenko/rollup-plugin-typescript2/issues/101 👈
😲 the new ts-jest now make jest configuration really simple
💡 found a shortcut to register all wasm functions into vue methods
⛔️ rust must be compiled in release profile when wasm exported as instance since default profile produce 2MB wasm 😂
🥚 add and modify on.js from binaryen-loader
🐣 since it's javascript, allowJs in tsconfig.json
🐥 however rollup will complain, so need to disable allowJs when bundling
---
🥚 use @webpack-contrib/test-utils to test it as a webpack-loader
🐣 but that dependency not compatible with es6 import
🐥 so tsconfig.json need to transform code as commonjs module {"module": "commonjs"}
🐤 but it cannot produce type declaration so need to disable it {"declaration": true}
🐔 luckily tsconfig.json can be override when bundling, so transform code as esnext module (see rollup.config.js)
🦃 summary, testing will transform code into commonjs module while bundling will generate commonjs module that support esnext import
🦖 so test the bundle result (dist/) rather than the source code (src/)
🦕 and collectCoverageFrom dist/ instead of src/ (see package.json)
🐉 which need to run `npm run build` before testing (see jest.config.js)
---
⌛️ minor change in testing as a library (lib.test.ts)
🚯 bundle the project before running linter in CI (npm run ci:lint)
🆗 ezolenko/rollup-plugin-typescript2/issues/101 now respect declarationDir and produces *.d.ts
incorrect source could be:
🔸 invalid/not-compilable wasm binary
🔸 wasm code over 4KB when using export mode: instance or module

⚠️ Rust v1.29 and nightly produce ~57KB wasm code, smoke-test need to lock on v1.28
👉 https://developers.google.com/web/updates/2018/04/loading-wasm 👈
@DrSensor DrSensor merged commit 145df59 into master Oct 15, 2018
@DrSensor DrSensor deleted the feature/export-mode branch October 15, 2018 00:27
@DrSensor DrSensor added the enhancement New feature or request label Oct 15, 2018
@DrSensor
Copy link
Owner Author

I attach the coverage test here because https://codecov.io can't pick up coverage report which source code are not in github repo. (since I test the bundle result instead of the source code)

$ npm run test:coverage

> webassembly-loader@0.0.0 test:coverage /home/wildan/Projects/OSS/webassembly-loader
> jest --collectCoverageFrom='dist/*.js' --coverage

Determining test suites to run...
src/index.ts → dist/index.js...
created dist/index.js in 3.3s
 PASS  test/lib.test.ts (15.242s)
 PASS  test/loader.test.ts (28.831s)
 PASS  test/negative.test.ts (28.996s)
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |     97.3 |    81.82 |      100 |    96.97 |                   |
 index.js |     97.3 |    81.82 |      100 |    96.97 |               105 |
----------|----------|----------|----------|----------|-------------------|

Test Suites: 3 passed, 3 total
Tests:       39 passed, 39 total
Snapshots:   0 total
Time:        35.705s
Ran all test suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants