napi-rs/test_module/tests.js

28 lines
585 B
JavaScript
Raw Normal View History

2020-02-18 22:09:17 +09:00
const testModule = require(`./target/debug/libtest_module.node`)
2018-04-28 17:26:38 +09:00
function testSpawn() {
console.log('=== Test spawning a future on libuv event loop')
return testModule.testSpawn()
}
function testThrow() {
console.log('=== Test throwing from Rust')
try {
testModule.testThrow()
} catch (e) {
return
}
console.error('Expected function to throw an error')
process.exit(1)
}
2020-02-18 22:09:17 +09:00
const future = testSpawn()
// https://github.com/nodejs/node/issues/29355
setTimeout(() => {
future.then(testThrow).catch((e) => {
console.error(e)
process.exit(1)
})
}, 10)