more updates
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/fastschema/qjs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"reichard.io/poiesis/internal/functions"
|
||||
)
|
||||
@@ -86,17 +87,14 @@ func TestAsyncFunctionResolution(t *testing.T) {
|
||||
})
|
||||
|
||||
r, err := New(context.Background())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := r.ctx.Eval("test.js", qjs.Code(`(async () => { return await resolveTest({field1: "hello"}); })()`))
|
||||
if err == nil && result != nil {
|
||||
defer result.Free()
|
||||
val, err := result.Await()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test-result", val.String())
|
||||
} else {
|
||||
t.Logf("Skipping async test - error: %v", err)
|
||||
}
|
||||
// Async functions need to be awaited in an async context
|
||||
result, err := r.ctx.Eval("test.js", qjs.Code(`async function run() { return await resolveTest("hello"); }; run()`))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
defer result.Free()
|
||||
assert.Equal(t, "test-result", result.String())
|
||||
}
|
||||
|
||||
func TestAsyncFunctionRejection(t *testing.T) {
|
||||
@@ -105,9 +103,10 @@ func TestAsyncFunctionRejection(t *testing.T) {
|
||||
})
|
||||
|
||||
r, err := New(context.Background())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = r.ctx.Eval("test.js", qjs.Code(`(async () => { return await rejectTest({field1: "hello"}); })()`))
|
||||
// Rejected promises throw when awaited
|
||||
_, err = r.ctx.Eval("test.js", qjs.Code(`async function run() { return await rejectTest("hello"); }; run()`))
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,15 @@ func TestFetch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFetchHTTPBin(t *testing.T) {
|
||||
t.Skip("httpbin.org test is flaky")
|
||||
ctx := context.Background()
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(`{"args":{}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := Fetch(ctx, FetchArgs{Input: "https://httpbin.org/get"})
|
||||
result, err := Fetch(ctx, FetchArgs{Input: server.URL})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, result.OK)
|
||||
|
||||
Reference in New Issue
Block a user