mirror of
https://github.com/ChronosX88/go-gun.git
synced 2024-11-08 20:21:01 +00:00
36 lines
827 B
Go
36 lines
827 B
Go
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
|
|
ctx, cancelFn := newContextWithGunJServer(t)
|
|
defer cancelFn()
|
|
randStr := randString(30)
|
|
ctx.runJSWithGun(`
|
|
gun.get('esgopeta-test').get('TestGunJS').get('some-field').put('` + randStr + `', ack => {
|
|
if (ack.err) {
|
|
console.error(ack.err)
|
|
process.exit(1)
|
|
}
|
|
process.exit(0)
|
|
})
|
|
`)
|
|
out := ctx.runJSWithGun(`
|
|
gun.get('esgopeta-test').get('TestGunJS').get('some-field').once(data => {
|
|
console.log(data)
|
|
process.exit(0)
|
|
})
|
|
`)
|
|
ctx.Require.Equal(randStr, strings.TrimSpace(string(out)))
|
|
}
|