@@ -2,26 +2,51 @@ import assert from 'node:assert/strict';
22import { readFile } from 'node:fs/promises' ;
33import { bundlers , getBundlePath , scenarios } from './scenarios.mjs' ;
44
5+ const modeExpectations = {
6+ context : ( ) => ( {
7+ include : [ / q r a f t R e a c t A P I C l i e n t (?: _ _ | \( ) / ] ,
8+ exclude : [ / q r a f t A P I C l i e n t (?: _ _ | \( ) / ] ,
9+ } ) ,
10+ precreated : ( scenario ) => ( {
11+ include : [ / q r a f t A P I C l i e n t (?: _ _ | \( ) / ] ,
12+ exclude : [ / q r a f t R e a c t A P I C l i e n t (?: _ _ | \( ) / ] ,
13+ } ) ,
14+ mixed : ( ) => ( {
15+ include : [ / q r a f t R e a c t A P I C l i e n t (?: _ _ | \( ) / , / q r a f t A P I C l i e n t (?: _ _ | \( ) / ] ,
16+ exclude : [ ] ,
17+ } ) ,
18+ } ;
19+
20+ const tokenMatches = ( bundle , token ) =>
21+ token instanceof RegExp ? token . test ( bundle ) : bundle . includes ( token ) ;
22+
523for ( const bundler of bundlers ) {
624 for ( const scenario of scenarios ) {
725 const bundlePath = getBundlePath ( bundler , scenario ) ;
826 const bundle = await readFile ( bundlePath , 'utf8' ) ;
27+ const resolvedModeExpectation = modeExpectations [ scenario . mode ] ( scenario ) ;
28+ const includeTokens = [
29+ ...new Set ( [ ...scenario . include , ...resolvedModeExpectation . include ] ) ,
30+ ] ;
31+ const excludeTokens = [
32+ ...new Set ( [ ...scenario . exclude , ...resolvedModeExpectation . exclude ] ) ,
33+ ] ;
934
1035 assert . ok (
1136 bundle . length > 0 ,
1237 `Expected non-empty bundle for ${ bundler } / ${ scenario . name } `
1338 ) ;
1439
15- for ( const token of scenario . include ) {
40+ for ( const token of includeTokens ) {
1641 assert . ok (
17- bundle . includes ( token ) ,
42+ tokenMatches ( bundle , token ) ,
1843 `Expected ${ bundler } / ${ scenario . name } bundle at ${ bundlePath } to include "${ token } "`
1944 ) ;
2045 }
2146
22- for ( const token of scenario . exclude ) {
47+ for ( const token of excludeTokens ) {
2348 assert . ok (
24- ! bundle . includes ( token ) ,
49+ ! tokenMatches ( bundle , token ) ,
2550 `Expected ${ bundler } / ${ scenario . name } bundle at ${ bundlePath } not to include "${ token } "`
2651 ) ;
2752 }
0 commit comments