({
// expand, compact, frame, fromRDF, toRDF, normalize, etc
type,
input,
options,
expected,
exception,
eventCounts,
// event array
eventLog,
// partial event array
eventPartialLog,
// event code array
eventCodeLog,
testSafe,
testNotSafe,
verbose
})
| 539 | // test different apis |
| 540 | // use appropriate options |
| 541 | async function _test({ |
| 542 | // expand, compact, frame, fromRDF, toRDF, normalize, etc |
| 543 | type, |
| 544 | input, |
| 545 | options, |
| 546 | expected, |
| 547 | exception, |
| 548 | eventCounts, |
| 549 | // event array |
| 550 | eventLog, |
| 551 | // partial event array |
| 552 | eventPartialLog, |
| 553 | // event code array |
| 554 | eventCodeLog, |
| 555 | testSafe, |
| 556 | testNotSafe, |
| 557 | verbose |
| 558 | }) { |
| 559 | const events = makeEvents(); |
| 560 | const eventHandler = ({event}) => { |
| 561 | trackEvent({events, event}); |
| 562 | }; |
| 563 | |
| 564 | let result; |
| 565 | let error; |
| 566 | const opts = {...options}; |
| 567 | if(eventCounts || eventLog || eventPartialLog || eventCodeLog) { |
| 568 | opts.eventHandler = eventHandler; |
| 569 | } |
| 570 | if(!['expand', 'fromRDF', 'toRDF', 'canonize'].includes(type)) { |
| 571 | throw new Error(`Unknown test type: "${type}"`); |
| 572 | } |
| 573 | try { |
| 574 | if(type === 'expand') { |
| 575 | result = await jsonld.expand(input, opts); |
| 576 | } |
| 577 | if(type === 'fromRDF') { |
| 578 | result = await jsonld.fromRDF(input, opts); |
| 579 | } |
| 580 | if(type === 'toRDF') { |
| 581 | result = await jsonld.toRDF(input, { |
| 582 | // default to n-quads |
| 583 | format: 'application/n-quads', |
| 584 | ...opts |
| 585 | }); |
| 586 | } |
| 587 | if(type === 'canonize') { |
| 588 | result = await jsonld.canonize(input, opts); |
| 589 | } |
| 590 | } catch(e) { |
| 591 | error = e; |
| 592 | } |
| 593 | |
| 594 | if(verbose) { |
| 595 | console.log(JSON.stringify({ |
| 596 | type, |
| 597 | input, |
| 598 | options, |
no test coverage detected