1- /** @jest -environment setup-polly-jest/jest-environment-node */
2-
31// Needed to undo automock from actor-http-native, cleaner workarounds do not appear to be working.
42import 'jest-rdf' ;
53import '@incremunica/jest' ;
@@ -10,12 +8,12 @@ import type { BindingsFactory } from '@comunica/utils-bindings-factory';
108import { KeysBindings } from '@incremunica/context-entries' ;
119import { createTestBindingsFactory , partialArrayifyAsyncIterator } from '@incremunica/dev-tools' ;
1210import { StreamingStore } from '@incremunica/streaming-store' ;
13- import type { Quad } from '@incremunica/types' ;
11+ import type { ContextQuerySourceStream , Quad } from '@incremunica/types' ;
1412import { ArrayIterator } from 'asynciterator' ;
1513import { DataFactory } from 'rdf-data-factory' ;
1614import { PassThrough } from 'readable-stream' ;
1715import { QueryEngine , QueryEngineFactory } from '../lib' ;
18- import { usePolly } from './util' ;
16+ import { fetch as cachedFetch } from './util' ;
1917
2018if ( ! globalThis . window ) {
2119 jest . unmock ( 'follow-redirects' ) ;
@@ -25,7 +23,7 @@ const quad = require('rdf-quad');
2523
2624const DF = new DataFactory ( ) ;
2725
28- describe ( 'System test: QuerySparql (without polly )' , ( ) => {
26+ describe ( 'System test: QuerySparql (without external network )' , ( ) => {
2927 let BF : BindingsFactory ;
3028 let engine : QueryEngine ;
3129
@@ -310,7 +308,6 @@ describe('System test: QuerySparql (without polly)', () => {
310308 ?s ?p ?o.
311309 }` , {
312310 sources : [ 'http://localhost:8787' ] ,
313- pollingPeriod : 1000 ,
314311 } ) ;
315312
316313 await expect ( new Promise < Bindings > ( resolve => bindingStream . once ( 'data' , ( bindings ) => {
@@ -333,17 +330,16 @@ describe('System test: QuerySparql (without polly)', () => {
333330 sources : [
334331 'http://localhost:8787' ,
335332 ] ,
336- pollingPeriod : 100 ,
337333 deferredEvaluationTrigger,
338334 } ) ;
339335
340- await expect ( new Promise < Bindings > ( resolve => bindingStream . once ( 'data' , ( bindings ) => {
341- resolve ( bindings ) ;
342- } ) ) ) . resolves . toEqualBindings ( BF . bindings ( [
343- [ DF . variable ( 's ' ) , DF . namedNode ( 'http://localhost:8787/s1 ' ) ] ,
344- [ DF . variable ( 'p ' ) , DF . namedNode ( 'http://localhost:8787/p1 ' ) ] ,
345- [ DF . variable ( 'o' ) , DF . namedNode ( 'http://localhost:8787/o1' ) ] ,
346- ] ) . setContextEntry ( KeysBindings . isAddition , true ) ) ;
336+ await expect ( partialArrayifyAsyncIterator ( bindingStream , 1 ) ) . resolves . toEqualBindingsArray ( [
337+ BF . bindings ( [
338+ [ DF . variable ( 's' ) , DF . namedNode ( 'http://localhost:8787/s1' ) ] ,
339+ [ DF . variable ( 'p ' ) , DF . namedNode ( 'http://localhost:8787/p1 ' ) ] ,
340+ [ DF . variable ( 'o ' ) , DF . namedNode ( 'http://localhost:8787/o1 ' ) ] ,
341+ ] ) . setContextEntry ( KeysBindings . isAddition , true ) ,
342+ ] ) ;
347343
348344 fetchData . dataString = '<http://localhost:8787/s3> <http://localhost:8787/p3> <http://localhost:8787/o3> .' ;
349345 fetchData . etag = '1' ;
@@ -355,13 +351,13 @@ describe('System test: QuerySparql (without polly)', () => {
355351 } , 500 ) ;
356352 setTimeout ( ( ) => deferredEvaluationTrigger . emit ( 'update' ) , 1000 ) ;
357353
358- await expect ( new Promise < Bindings > ( resolve => bindingStream . once ( 'data' , ( bindings ) => {
359- resolve ( bindings ) ;
360- } ) ) ) . resolves . toEqualBindings ( BF . bindings ( [
361- [ DF . variable ( 's ' ) , DF . namedNode ( 'http://localhost:8787/s2 ' ) ] ,
362- [ DF . variable ( 'p ' ) , DF . namedNode ( 'http://localhost:8787/p2 ' ) ] ,
363- [ DF . variable ( 'o' ) , DF . namedNode ( 'http://localhost:8787/o2' ) ] ,
364- ] ) . setContextEntry ( KeysBindings . isAddition , true ) ) ;
354+ await expect ( partialArrayifyAsyncIterator ( bindingStream , 1 ) ) . resolves . toEqualBindingsArray ( [
355+ BF . bindings ( [
356+ [ DF . variable ( 's' ) , DF . namedNode ( 'http://localhost:8787/s2' ) ] ,
357+ [ DF . variable ( 'p ' ) , DF . namedNode ( 'http://localhost:8787/p2 ' ) ] ,
358+ [ DF . variable ( 'o ' ) , DF . namedNode ( 'http://localhost:8787/o2 ' ) ] ,
359+ ] ) . setContextEntry ( KeysBindings . isAddition , true ) ,
360+ ] ) ;
365361 } ) ;
366362
367363 it ( 'simple query with a streaming source, addition and deletion' , async ( ) => {
@@ -380,7 +376,7 @@ describe('System test: QuerySparql (without polly)', () => {
380376 ?s ?p ?o.
381377 }` , {
382378 sources : [ streamingStore , sourcesStream ] ,
383- pollingPeriod : 1000 ,
379+ pollingPeriod : 1 ,
384380 } ) ;
385381
386382 await expect ( partialArrayifyAsyncIterator ( bindingStream , 1 ) ) . resolves . toEqualBindingsArray ( [
@@ -451,7 +447,7 @@ describe('System test: QuerySparql (without polly)', () => {
451447 ?s ?p ?o.
452448 }` , {
453449 sources : [ 'http://localhost:8787' ] ,
454- pollingPeriod : 1000 ,
450+ pollingPeriod : 1 ,
455451 } ) ;
456452
457453 await expect ( new Promise < Bindings > ( resolve => bindingStream . once ( 'data' , ( bindings ) => {
@@ -482,7 +478,7 @@ describe('System test: QuerySparql (without polly)', () => {
482478 OPTIONAL { ?s2 <http://localhost:8787/p2> ?o2 . }
483479 }` , {
484480 sources : [ 'http://localhost:8787' ] ,
485- pollingPeriod : 1000 ,
481+ pollingPeriod : 1 ,
486482 } ) ;
487483
488484 await expect ( new Promise < Bindings > ( resolve => bindingStream . once ( 'data' , ( bindings ) => {
@@ -514,12 +510,11 @@ describe('System test: QuerySparql (without polly)', () => {
514510 } ) ;
515511} ) ;
516512
517- describe ( 'System test: QuerySparql (with polly)' , ( ) => {
518- usePolly ( ) ;
519-
513+ describe ( 'System test: QuerySparql (with external network)' , ( ) => {
520514 let bindingStream : BindingsStream ;
521515 let engine : QueryEngine ;
522516 beforeEach ( async ( ) => {
517+ globalThis . fetch = cachedFetch ;
523518 engine = new QueryEngine ( ) ;
524519 await engine . invalidateHttpCache ( ) ;
525520 } ) ;
@@ -534,7 +529,6 @@ describe('System test: QuerySparql (with polly)', () => {
534529 ?s ?p ?o.
535530 }` , {
536531 sources : [ 'https://www.rubensworks.net/' ] ,
537- pollingPeriod : 1000 ,
538532 } ) ;
539533
540534 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 100 ) ) ) . resolves . toHaveLength ( 100 ) ;
@@ -544,14 +538,13 @@ describe('System test: QuerySparql (with polly)', () => {
544538 bindingStream = await engine . queryBindings ( `SELECT * WHERE {
545539 ?s ?p ?o.
546540 }` , {
547- sources : [ new ArrayIterator ( [
541+ sources : [ < ContextQuerySourceStream > new ArrayIterator ( [
548542 'https://www.rubensworks.net/' ,
549543 {
550544 querySource : 'https://www.rubensworks.net/' ,
551545 isAddition : true ,
552546 } ,
553547 ] ) ] ,
554- pollingPeriod : 1000 ,
555548 } ) ;
556549
557550 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 100 ) ) ) . resolves . toHaveLength ( 100 ) ;
@@ -562,7 +555,6 @@ describe('System test: QuerySparql (with polly)', () => {
562555 ?s ?p ?o.
563556 }` ;
564557 const context : QueryStringContext = {
565- pollingPeriod : 1000 ,
566558 sources : [ 'https://www.rubensworks.net/' ] ,
567559 } ;
568560
@@ -579,14 +571,14 @@ describe('System test: QuerySparql (with polly)', () => {
579571 }` ;
580572 const context : QueryStringContext = {
581573 sources : [ 'https://www.rubensworks.net/' ] ,
582- pollingPeriod : 1000 ,
574+ pollingPeriod : 1 ,
583575 } ;
584576
585577 bindingStream = await engine . queryBindings ( query , context ) ;
586578 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 100 ) ) ) . resolves . toHaveLength ( 100 ) ;
587579 bindingStream . destroy ( ) ;
588580
589- await new Promise < void > ( resolve => setTimeout ( ( ) => resolve ( ) , 1000 ) ) ;
581+ await new Promise < void > ( resolve => setTimeout ( ( ) => resolve ( ) , 2000 ) ) ;
590582
591583 bindingStream = await engine . queryBindings ( query , context ) ;
592584 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 100 ) ) ) . resolves . toHaveLength ( 100 ) ;
@@ -599,7 +591,6 @@ describe('System test: QuerySparql (with polly)', () => {
599591 ?s ?p ?s.
600592 }` , {
601593 sources : [ 'https://www.rubensworks.net/' ] ,
602- pollingPeriod : 1000 ,
603594 } ) ;
604595
605596 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 1 ) ) ) . resolves . toHaveLength ( 1 ) ;
@@ -613,7 +604,6 @@ describe('System test: QuerySparql (with polly)', () => {
613604 ?v0 <http://xmlns.com/foaf/0.1/name> ?name.
614605 }` , {
615606 sources : [ 'https://www.rubensworks.net/' ] ,
616- pollingPeriod : 1000 ,
617607 } ) ;
618608
619609 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 20 ) ) ) . resolves . toHaveLength ( 20 ) ;
@@ -625,7 +615,6 @@ describe('System test: QuerySparql (with polly)', () => {
625615 ?v0 <http://xmlns.com/foaf/0.1/name> ?name.
626616 }` , {
627617 sources : [ 'https://www.rubensworks.net/' ] ,
628- pollingPeriod : 1000 ,
629618 } ) ;
630619
631620 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 20 ) ) ) . resolves . toHaveLength ( 20 ) ;
@@ -640,7 +629,6 @@ describe('System test: QuerySparql (with polly)', () => {
640629 'https://raw.githubusercontent.com/w3c/data-shapes/gh-pages/shacl-compact-syntax/' +
641630 'tests/valid/basic-shape-iri.shaclc' ,
642631 ] ,
643- pollingPeriod : 1000 ,
644632 } ) ;
645633
646634 await expect ( ( partialArrayifyAsyncIterator ( bindingStream , 1 ) ) ) . resolves . toHaveLength ( 1 ) ;
0 commit comments