go-gun/gun/tests/js_test.go

36 lines
827 B
Go
Raw Normal View History

2019-02-20 20:54:46 +00:00
package tests
import (
"strings"
"testing"
)
func TestSimpleJS(t *testing.T) {
ctx, cancelFn := newContext(t)
defer cancelFn()
ctx.Require.Equal("yay 3\n", string(ctx.runJS("console.log('yay', 1 + 2)")))
}
func TestGunJS(t *testing.T) {
// Run the server, put in one call, get in another, then check
2019-02-25 05:14:26 +00:00
ctx, cancelFn := newContextWithGunJServer(t)
2019-02-20 20:54:46 +00:00
defer cancelFn()
randStr := randString(30)
2019-02-22 18:40:02 +00:00
ctx.runJSWithGun(`
2019-02-26 21:59:44 +00:00
gun.get('esgopeta-test').get('TestGunJS').get('some-field').put('` + randStr + `', ack => {
2019-02-20 20:54:46 +00:00
if (ack.err) {
console.error(ack.err)
process.exit(1)
}
process.exit(0)
})
`)
2019-02-22 18:40:02 +00:00
out := ctx.runJSWithGun(`
2019-02-26 21:59:44 +00:00
gun.get('esgopeta-test').get('TestGunJS').get('some-field').once(data => {
2019-02-20 20:54:46 +00:00
console.log(data)
process.exit(0)
})
`)
ctx.Require.Equal(randStr, strings.TrimSpace(string(out)))
}