braid-text 0.2.79 → 0.2.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/package.json +1 -1
- package/test/tests.js +41 -0
package/index.js
CHANGED
package/package.json
CHANGED
package/test/tests.js
CHANGED
|
@@ -1981,6 +1981,47 @@ runTest(
|
|
|
1981
1981
|
'created locally'
|
|
1982
1982
|
)
|
|
1983
1983
|
|
|
1984
|
+
runTest(
|
|
1985
|
+
"test braid_text.sync on_res callback",
|
|
1986
|
+
async () => {
|
|
1987
|
+
var local_key = 'test-local-' + Math.random().toString(36).slice(2)
|
|
1988
|
+
var remote_key = 'test-remote-' + Math.random().toString(36).slice(2)
|
|
1989
|
+
|
|
1990
|
+
// Create the remote resource first
|
|
1991
|
+
var r = await braid_fetch(`/${remote_key}`, {
|
|
1992
|
+
method: 'PUT',
|
|
1993
|
+
body: 'remote content'
|
|
1994
|
+
})
|
|
1995
|
+
if (!r.ok) return 'put failed: ' + r.status
|
|
1996
|
+
|
|
1997
|
+
// Start sync with on_res callback and verify it gets called
|
|
1998
|
+
var r = await braid_fetch(`/eval`, {
|
|
1999
|
+
method: 'PUT',
|
|
2000
|
+
body: `void (async () => {
|
|
2001
|
+
var ac = new AbortController()
|
|
2002
|
+
var got_res = false
|
|
2003
|
+
|
|
2004
|
+
braid_text.sync('/${local_key}', new URL('http://localhost:8889/${remote_key}'), {
|
|
2005
|
+
signal: ac.signal,
|
|
2006
|
+
on_res: (response) => {
|
|
2007
|
+
got_res = response && typeof response.headers !== 'undefined'
|
|
2008
|
+
}
|
|
2009
|
+
})
|
|
2010
|
+
|
|
2011
|
+
// Wait for sync to establish and on_res to be called
|
|
2012
|
+
await new Promise(done => setTimeout(done, 200))
|
|
2013
|
+
|
|
2014
|
+
ac.abort()
|
|
2015
|
+
res.end(got_res ? 'on_res called' : 'on_res not called')
|
|
2016
|
+
})()`
|
|
2017
|
+
})
|
|
2018
|
+
if (!r.ok) return 'eval failed: ' + r.status
|
|
2019
|
+
|
|
2020
|
+
return await r.text()
|
|
2021
|
+
},
|
|
2022
|
+
'on_res called'
|
|
2023
|
+
)
|
|
2024
|
+
|
|
1984
2025
|
runTest(
|
|
1985
2026
|
"test getting a binary update from a subscription",
|
|
1986
2027
|
async () => {
|