|
| 1 | +/** |
| 2 | + * Test script to verify CommonJS compatibility |
| 3 | + * Run with: node bundler-test/test-cjs-import.cjs |
| 4 | + */ |
| 5 | + |
| 6 | +console.log("Testing CommonJS require() compatibility...\n"); |
| 7 | + |
| 8 | +// Use standard CommonJS require |
| 9 | +let wasmUtxo; |
| 10 | +try { |
| 11 | + wasmUtxo = require("../dist/cjs/index.js"); |
| 12 | +} catch (error) { |
| 13 | + console.error("✗ require() failed:", error.message); |
| 14 | + process.exit(1); |
| 15 | +} |
| 16 | + |
| 17 | +console.log("✓ require() successful from CJS context"); |
| 18 | +console.log("✓ Available exports:", Object.keys(wasmUtxo).join(", ")); |
| 19 | + |
| 20 | +// Test that we can access the main APIs |
| 21 | +if (wasmUtxo.Descriptor) { |
| 22 | + console.log("✓ Descriptor API available"); |
| 23 | +} |
| 24 | +if (wasmUtxo.Psbt) { |
| 25 | + console.log("✓ Psbt API available"); |
| 26 | +} |
| 27 | +if (wasmUtxo.address) { |
| 28 | + console.log("✓ address namespace available"); |
| 29 | +} |
| 30 | +if (wasmUtxo.fixedScriptWallet) { |
| 31 | + console.log("✓ fixedScriptWallet namespace available"); |
| 32 | +} |
| 33 | + |
| 34 | +// Try to use the Descriptor API |
| 35 | +try { |
| 36 | + const descriptor = wasmUtxo.Descriptor.fromString( |
| 37 | + "wpkh(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/0/*)", |
| 38 | + "derivable", |
| 39 | + ); |
| 40 | + console.log("✓ Descriptor.fromString() works"); |
| 41 | + console.log(" Descriptor type:", descriptor.descType()); |
| 42 | +} catch (err) { |
| 43 | + console.log("✗ Descriptor test failed:", err.message); |
| 44 | + process.exit(1); |
| 45 | +} |
| 46 | + |
| 47 | +console.log("\n✅ All CJS compatibility tests passed!"); |
| 48 | +console.log("\nCJS consumers can use standard require() with this package."); |
0 commit comments