Skip to content

Commit c55a161

Browse files
committed
test: added events and callbacks suites
1 parent f56c5ae commit c55a161

File tree

1 file changed

+116
-31
lines changed

1 file changed

+116
-31
lines changed

test/module.test.js

Lines changed: 116 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe(
205205
);
206206

207207
/*
208-
* * Module testing suite
208+
* * Module testing suite - Selectors
209209
*/
210210
describe(
211211
'module-selectors',
@@ -379,7 +379,7 @@ describe(
379379
);
380380

381381
/*
382-
* * Module testing suite
382+
* * Module testing suite - Query parameters
383383
*/
384384
describe(
385385
'module-query-parameters',
@@ -436,7 +436,7 @@ describe(
436436
);
437437

438438
/*
439-
* * Module testing suite
439+
* * Module testing suite - Headers
440440
*/
441441
describe(
442442
'module-headers',
@@ -523,10 +523,10 @@ describe(
523523
);
524524

525525
/*
526-
* * Module testing suite
526+
* * Module testing suite - Events
527527
*/
528528
describe(
529-
'module-deprecations',
529+
'module-events',
530530
() => {
531531

532532
/*
@@ -542,12 +542,19 @@ describe(
542542
pruneHtml: {
543543
enabled: true,
544544
hookGeneratePage: false,
545-
hideErrorsInConsole: true,
546-
headerName: 'deprecated-old-config',
547-
isLighthouse: 'deprecated-old-config',
548-
ignoreBotOrLighthouse: 'deprecated-old-config',
549-
lighthouseUserAgent: 'deprecated-old-config',
550-
selectorToKeep: 'deprecated-old-config',
545+
onBeforePrune( { result } ) {
546+
547+
result.html = '<html><h2>onBeforePruneEvent</h2>[onAfterPrune]</html>';
548+
549+
},
550+
onAfterPrune( { result } ) {
551+
552+
result.html = result.html.replace(
553+
'[onAfterPrune]',
554+
'<h2>onAfterPruneEvent</h2>'
555+
);
556+
557+
},
551558
},
552559
},
553560
}
@@ -556,36 +563,52 @@ describe(
556563
/*
557564
* * Tests
558565
*/
559-
describe(
560-
'v2.0',
561-
() => {
566+
describe(
567+
'callbacks',
568+
() => {
562569

563-
test(
564-
'has-scripts',
565-
async() => {
570+
test(
571+
'on-before-prune',
572+
async() => {
566573

567-
const { length } = await getDomElements(
568-
BASE_URL,
569-
'script:not([type="application/ld+json"]), link[rel="preload"][as="script"]',
570-
BOT_USER_AGENT,
571-
);
574+
const { body } = await getDomElements(
575+
BASE_URL,
576+
'html',
577+
BOT_USER_AGENT,
578+
);
572579

573-
// Test
574-
expect( length ).toBeGreaterThan(
575-
1
576-
);
580+
expect( body ).toContain(
581+
'onBeforePruneEvent'
582+
);
577583

578-
},
579-
);
584+
},
585+
);
580586

581-
}
582-
);
587+
test(
588+
'on-after-prune',
589+
async() => {
590+
591+
const { body } = await getDomElements(
592+
BASE_URL,
593+
'html',
594+
BOT_USER_AGENT,
595+
);
596+
597+
expect( body ).toContain(
598+
'onAfterPruneEvent'
599+
);
600+
601+
},
602+
);
603+
604+
}
605+
);
583606

584607
}
585608
);
586609

587610
/*
588-
* * Module testing suite
611+
* * Module testing suite - Generate
589612
*/
590613
describe(
591614
'module-generate',
@@ -613,3 +636,65 @@ describe(
613636

614637
}
615638
);
639+
640+
/*
641+
* * Module testing suite - Deprecation
642+
*/
643+
describe(
644+
'module-deprecations',
645+
() => {
646+
647+
/*
648+
* * Nuxt setup
649+
*/
650+
setupTest(
651+
{
652+
server: true,
653+
testDir: __dirname,
654+
fixture: '../src',
655+
config: {
656+
dev: false,
657+
pruneHtml: {
658+
enabled: true,
659+
hookGeneratePage: false,
660+
hideErrorsInConsole: true,
661+
headerName: 'deprecated-old-config',
662+
isLighthouse: 'deprecated-old-config',
663+
ignoreBotOrLighthouse: 'deprecated-old-config',
664+
lighthouseUserAgent: 'deprecated-old-config',
665+
selectorToKeep: 'deprecated-old-config',
666+
},
667+
},
668+
}
669+
);
670+
671+
/*
672+
* * Tests
673+
*/
674+
describe(
675+
'v2.0',
676+
() => {
677+
678+
test(
679+
'has-scripts',
680+
async() => {
681+
682+
const { length } = await getDomElements(
683+
BASE_URL,
684+
'script:not([type="application/ld+json"]), link[rel="preload"][as="script"]',
685+
BOT_USER_AGENT,
686+
);
687+
688+
// Test
689+
expect( length ).toBeGreaterThan(
690+
1
691+
);
692+
693+
},
694+
);
695+
696+
}
697+
);
698+
699+
}
700+
);

0 commit comments

Comments
 (0)