|
| 1 | +# Bundler Integration Tests |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This test suite verifies that the built `@hpcc-js/wasm-*` packages can be properly consumed by popular JavaScript bundlers. The tests ensure that WebAssembly modules load correctly and function as expected when bundled with different build tools. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +tests/bundlers/ |
| 11 | +├── src/ |
| 12 | +│ ├── test-utils.js # Shared test functions |
| 13 | +│ ├── webpack-test.js # Webpack entry point |
| 14 | +│ ├── esbuild-test.js # ESBuild entry point |
| 15 | +│ └── rollup-test.js # Rollup entry point |
| 16 | +├── webpack.config.js # Webpack configuration |
| 17 | +├── rollup.config.js # Rollup configuration |
| 18 | +├── vitest.config.js # Vitest test configuration |
| 19 | +├── bundlers.test.js # Main test suite |
| 20 | +├── package.json # Test dependencies |
| 21 | +└── README.md # Documentation |
| 22 | +``` |
| 23 | + |
| 24 | +## Tested Combinations |
| 25 | + |
| 26 | +### Bundlers |
| 27 | +- **Webpack 5** with WebAssembly async support |
| 28 | +- **ESBuild** with Node.js target |
| 29 | +- **Rollup.js** with ES module output |
| 30 | + |
| 31 | +### Packages |
| 32 | +- `@hpcc-js/wasm-base91` - Base91 encoding/decoding |
| 33 | +- `@hpcc-js/wasm-expat` - XML parsing with Expat |
| 34 | +- `@hpcc-js/wasm-graphviz` - Graphviz DOT rendering |
| 35 | +- `@hpcc-js/wasm-duckdb` - DuckDB in-process SQL OLAP database |
| 36 | +- `@hpcc-js/wasm-llama` - Large Language Model inference |
| 37 | +- `@hpcc-js/wasm-zstd` - Zstandard compression |
| 38 | + |
| 39 | +## Running Tests |
| 40 | + |
| 41 | +### From Root Directory |
| 42 | + |
| 43 | +```bash |
| 44 | +# Install all dependencies including bundler test deps |
| 45 | +npm run install-build-deps |
| 46 | + |
| 47 | +# Run all bundler tests via vitest |
| 48 | +npm run test-bundlers |
| 49 | + |
| 50 | +# Run bundler tests via shell script (more verbose) |
| 51 | +npm run test-bundlers-script |
| 52 | + |
| 53 | +# Run specific bundler tests |
| 54 | +npm run test-bundlers-webpack |
| 55 | +npm run test-bundlers-esbuild |
| 56 | +npm run test-bundlers-rollup |
| 57 | + |
| 58 | +# Run all tests (regular + bundler) |
| 59 | +npm run test-all |
| 60 | +``` |
| 61 | + |
| 62 | +### From Bundlers Directory |
| 63 | + |
| 64 | +```bash |
| 65 | +cd tests/bundlers |
| 66 | + |
| 67 | +# Install dependencies |
| 68 | +npm install |
| 69 | + |
| 70 | +# Run vitest integration tests |
| 71 | +npm test |
| 72 | + |
| 73 | +# Run specific bundler manually |
| 74 | +npm run test:webpack |
| 75 | +npm run test:esbuild |
| 76 | +npm run test:rollup |
| 77 | +``` |
| 78 | + |
| 79 | +## Test Process |
| 80 | + |
| 81 | +For each bundler, the test: |
| 82 | + |
| 83 | +1. **Bundles** the test code with the bundler's configuration |
| 84 | +2. **Executes** the bundled output in Node.js |
| 85 | +3. **Verifies** that each WASM package loads successfully |
| 86 | +4. **Tests** core functionality of each package |
| 87 | +5. **Confirms** no runtime errors occur |
| 88 | + |
| 89 | +## What Gets Tested |
| 90 | + |
| 91 | +### Package Loading |
| 92 | +- Correct module resolution |
| 93 | +- WebAssembly module loading |
| 94 | +- Proper initialization sequencing |
| 95 | + |
| 96 | +### Functionality |
| 97 | +- **Base91**: Encode/decode string data |
| 98 | +- **Expat**: Parse XML documents with callbacks |
| 99 | +- **Graphviz**: Render DOT notation to SVG |
| 100 | +- **DuckDB**: Execute SQL queries on in-memory database |
| 101 | +- **Llama**: Load models and verify functionality |
| 102 | +- **Zstd**: Compress/decompress binary data |
| 103 | + |
| 104 | +### Integration Points |
| 105 | +- ES module imports |
| 106 | +- WebAssembly instantiation |
| 107 | +- Async module initialization |
| 108 | +- Cross-package compatibility |
| 109 | + |
| 110 | +## Bundler Configurations |
| 111 | + |
| 112 | +### Webpack |
| 113 | +- WebAssembly async experiments enabled |
| 114 | +- Node.js target for testing |
| 115 | +- Built-in modules externalized |
| 116 | +- WASM files handled as async modules |
| 117 | + |
| 118 | +### ESBuild |
| 119 | +- Node.js platform target |
| 120 | +- Bundle mode enabled |
| 121 | +- External Node.js modules |
| 122 | + |
| 123 | +### Rollup |
| 124 | +- ES module output format |
| 125 | +- Node.js built-ins externalized |
| 126 | +- Module resolution via plugins |
| 127 | + |
| 128 | +## CI Integration |
| 129 | + |
| 130 | +The tests are integrated into the GitHub Actions workflow (`test-pr.yml`) and run on: |
| 131 | +- Ubuntu, macOS (Intel & ARM) |
| 132 | +- Node.js versions 22, 24 |
| 133 | +- Every pull request and push |
| 134 | + |
| 135 | +## Troubleshooting |
| 136 | + |
| 137 | +### Common Issues |
| 138 | + |
| 139 | +**WebAssembly Loading Errors** |
| 140 | +- Ensure WASM files are included in package distributions |
| 141 | +- Check bundler WebAssembly support is configured correctly |
| 142 | + |
| 143 | +**Module Resolution Errors** |
| 144 | +- Verify workspace dependencies are properly linked |
| 145 | +- Check that packages are built before running tests |
| 146 | + |
| 147 | +**Timeout Errors** |
| 148 | +- Bundling operations can be slow; tests have extended timeouts |
| 149 | +- Large WebAssembly modules may need more time to initialize |
| 150 | + |
| 151 | +### Debugging |
| 152 | + |
| 153 | +Enable verbose output: |
| 154 | +```bash |
| 155 | +# Use the shell script for detailed output |
| 156 | +npm run test-bundlers-script |
| 157 | + |
| 158 | +# Or run bundlers individually |
| 159 | +cd tests/bundlers |
| 160 | +npm run test:webpack # etc. |
| 161 | +``` |
| 162 | + |
| 163 | +Check bundled output: |
| 164 | +```bash |
| 165 | +cd tests/bundlers |
| 166 | +npm run build:webpack |
| 167 | +node dist/webpack-test.js |
| 168 | +``` |
| 169 | + |
| 170 | +## Future Enhancements |
| 171 | + |
| 172 | +Potential areas for expansion: |
| 173 | + |
| 174 | +- **More Bundlers**: Parcel, Vite, etc. |
| 175 | +- **Browser Testing**: Test bundled code in browsers |
| 176 | +- **Tree Shaking**: Verify unused code elimination |
| 177 | +- **Code Splitting**: Test dynamic imports and chunks |
| 178 | +- **Different Targets**: Browser, Web Worker, Service Worker |
| 179 | +- **Package Combinations**: Test using multiple packages together |
0 commit comments