|
22 | 22 | const { ripple, page } = await startup() |
23 | 23 | await page.evaluate(d => { $ = ripple.subscribe('foo').map(d => (console.log("d", d), d)) }) |
24 | 24 | ripple('foo', 'bar') |
25 | | - ripple.emit('loaded', 'foo') |
26 | 25 | same('bar', await page.evaluate(d => $)) |
27 | 26 | same(1, keys(ripple.server.ws.sockets[0].subscriptions).length) |
28 | 27 | await page.evaluate(d => Promise.all($.source.emit('stop'))) |
|
245 | 244 | page.close() |
246 | 245 | }) |
247 | 246 |
|
| 247 | + await test('strip server headers', async ({ plan, same }) => { |
| 248 | + plan(2) |
| 249 | + const { ripple, page } = await startup() |
| 250 | + , received = emitterify() |
| 251 | + |
| 252 | + // capture messages |
| 253 | + ripple({ |
| 254 | + name: 'test' |
| 255 | + , body: {} |
| 256 | + , headers: { |
| 257 | + from: d => false |
| 258 | + , loaded: 'loaded' |
| 259 | + , transpile: 'transpile' |
| 260 | + , valid: d => d |
| 261 | + } |
| 262 | + }) |
| 263 | + |
| 264 | + const test = await page.evaluate(async d => { |
| 265 | + await ripple.get('test') |
| 266 | + return { |
| 267 | + headers: Object.keys(ripple.resources.test.headers) |
| 268 | + , valid: typeof ripple.resources.test.headers.valid |
| 269 | + } |
| 270 | + }) |
| 271 | + |
| 272 | + same(test.headers, ['valid', 'content-type'], 'headers stripped') |
| 273 | + same(test.valid, 'function', 'function headers valid') |
| 274 | + |
| 275 | + page.close() |
| 276 | + }) |
| 277 | + |
| 278 | + await test('auto dynamically transpile functions', async ({ plan, same }) => { |
| 279 | + plan(7) |
| 280 | + const { ripple, page } = await startup() |
| 281 | + |
| 282 | + ripple('arrow', d => d) |
| 283 | + |
| 284 | + same(keys(ripple.caches).length, 0, 'empty cache') |
| 285 | + |
| 286 | + const untranspiled = await page.evaluate(async d => ('' + await ripple.get('arrow'))) |
| 287 | + same(keys(ripple.caches), ['arrow'], 'one cache') |
| 288 | + same(ripple.caches.arrow.size, 1, 'one transpilation') |
| 289 | + |
| 290 | + await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko') |
| 291 | + await page.reload() |
| 292 | + |
| 293 | + const transpiled = await page.evaluate(async d => ('' + await ripple.get('arrow'))) |
| 294 | + same(ripple.caches.arrow.size, 2, 'two transpilations') |
| 295 | + same(untranspiled, 'd => d', 'untranspiled') |
| 296 | + same(transpiled, 'function (d) { return d; }', 'transpiled') |
| 297 | + |
| 298 | + ripple('arrow', d => false) |
| 299 | + |
| 300 | + same(keys(ripple.caches).length, 0, 'clear transpilation caches on reload') |
| 301 | + page.close() |
| 302 | + }) |
| 303 | + |
| 304 | + await test('opt in dynamically transpile objects with functions + updates', async ({ plan, same }) => { |
| 305 | + plan(2) |
| 306 | + const { ripple, page } = await startup() |
| 307 | + |
| 308 | + await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko') |
| 309 | + await page.reload() |
| 310 | + ripple('arrow', { foo: d => true }, { transpile: { limit: 1 }}) |
| 311 | + |
| 312 | + const transpiled1 = await page.evaluate(async d => ('' + (await ripple.get('arrow', 'foo')))) |
| 313 | + same(transpiled1, 'function (d) { return true; }', 'transpiled1') |
| 314 | + |
| 315 | + update('foo', d => false)(ripple('arrow')) |
| 316 | + await page.reload() |
| 317 | + |
| 318 | + const transpiled2 = await page.evaluate(async d => ('' + (await ripple.get('arrow', 'foo')))) |
| 319 | + same(transpiled2, 'function (d) { return false; }', 'transpiled2') |
| 320 | + |
| 321 | + page.close() |
| 322 | + }) |
| 323 | + |
248 | 324 | process.exit(0) |
249 | 325 |
|
250 | 326 | async function startup(){ |
|
0 commit comments