-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
test.js
907 lines (774 loc) · 22.7 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
require( 'source-map-support' ).install();
require( 'console-group' ).install();
const path = require( 'path' );
const sander = require( 'sander' );
const assert = require( 'assert' );
const { exec } = require( 'child_process' );
const buble = require( 'buble' );
const acorn = require( 'acorn' );
const rollup = require( '../dist/rollup' );
const FUNCTION = path.resolve( __dirname, 'function' );
const FORM = path.resolve( __dirname, 'form' );
const SOURCEMAPS = path.resolve( __dirname, 'sourcemaps' );
const CLI = path.resolve( __dirname, 'cli' );
const PROFILES = [
{ format: 'amd' },
{ format: 'cjs' },
{ format: 'es' },
{ format: 'iife' },
{ format: 'umd' }
];
function extend ( target ) {
[].slice.call( arguments, 1 ).forEach( source => {
source && Object.keys( source ).forEach( key => {
target[ key ] = source[ key ];
});
});
return target;
}
function normaliseOutput ( code ) {
return code.toString().trim().replace( /\r\n/g, '\n' );
}
function loadConfig ( path ) {
try {
return require( path );
} catch ( err ) {
console.error( err.message );
console.error( err.stack );
throw new Error( `Failed to load ${path}. An old test perhaps? You should probably delete the directory` );
}
}
function loader ( modules ) {
return {
resolveId ( id ) {
return id in modules ? id : null;
},
load ( id ) {
return modules[ id ];
}
};
}
function deindent ( str ) {
return str.slice( 1 ).replace( /^\t+/gm, '' ).replace( /\s+$/gm, '' ).trim();
}
function compareWarnings ( actual, expected ) {
assert.deepEqual(
actual.map( warning => {
const clone = Object.assign( {}, warning );
delete clone.toString;
if ( clone.frame ) {
clone.frame = clone.frame.replace( /\s+$/gm, '' );
}
return clone;
}),
expected.map( warning => {
if ( warning.frame ) {
warning.frame = deindent( warning.frame );
}
return warning;
})
);
}
function compareError ( actual, expected ) {
delete actual.stack;
actual = Object.assign( {}, actual, {
message: actual.message
});
if ( actual.frame ) {
actual.frame = actual.frame.replace( /\s+$/gm, '' );
}
if ( expected.frame ) {
expected.frame = deindent( expected.frame );
}
assert.deepEqual( actual, expected );
}
describe( 'rollup', function () {
this.timeout( 10000 );
describe( 'sanity checks', () => {
it( 'exists', () => {
assert.ok( !!rollup );
});
it( 'has a rollup method', () => {
assert.equal( typeof rollup.rollup, 'function' );
});
it( 'fails without options', () => {
return rollup.rollup()
.then( () => {
throw new Error( 'Missing expected error' );
})
.catch( err => {
assert.equal( err.message, 'You must supply an options object to rollup' );
});
});
it( 'fails without options.entry', () => {
return rollup.rollup({})
.then( () => {
throw new Error( 'Missing expected error' );
})
.catch( err => {
assert.equal( err.message, 'You must supply options.entry to rollup' );
});
});
it( 'fails with invalid keys', () => {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( () => {
throw new Error( 'Missing expected error' );
}, err => {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, amd, banner, cache, context, dest, entry, exports, external, footer, format, globals, indent, interop, intro, legacy, moduleContext, moduleName, noConflict, onwarn, outro, paths, plugins, preferConst, pureExternalModules, sourceMap, sourceMapFile, targets, treeshake, useStrict, watch' );
});
});
it( 'treats Literals as leaf nodes, even if first literal encountered is null', () => {
// this test has to be up here, otherwise the bug doesn't have
// an opportunity to present itself
return rollup.rollup({
entry: 'x',
plugins: [ loader({ x: `var a = null; a = 'a string';` }) ]
});
});
it( 'includes a newline at the end of the bundle', () => {
return rollup.rollup({
entry: 'x',
plugins: [ loader({ x: `console.log( 42 );` }) ]
}).then( bundle => {
return bundle.generate({ format: 'iife' });
}).then( ({ code }) => {
assert.ok( code[ code.length - 1 ] === '\n' );
});
});
it( 'warns on missing format option', () => {
const warnings = [];
return rollup.rollup({
entry: 'x',
plugins: [ loader({ x: `console.log( 42 );` }) ],
onwarn: warning => warnings.push( warning )
}).then( bundle => {
bundle.generate();
compareWarnings( warnings, [
{
code: 'MISSING_FORMAT',
message: `No format option was supplied – defaulting to 'es'`,
url: `https://github.com/rollup/rollup/wiki/JavaScript-API#format`
}
]);
});
});
});
describe( 'bundle.write()', () => {
it( 'fails without options or options.dest', () => {
return rollup.rollup({
entry: 'x',
plugins: [{
resolveId: () => { return 'test'; },
load: () => {
return '// empty';
}
}]
}).then( bundle => {
assert.throws( () => {
bundle.write();
}, /must supply options\.dest/ );
assert.throws( () => {
bundle.write({});
}, /must supply options\.dest/ );
});
});
it( 'expects options.moduleName for IIFE and UMD bundles', () => {
let bundle;
return rollup.rollup({
entry: 'x',
plugins: [{
resolveId: () => { return 'test'; },
load: () => {
return 'export var foo = 42;';
}
}]
}).then( rollupInstance => {
bundle = rollupInstance;
return bundle.generate({
format: 'umd'
});
}).catch( err => {
assert.throws( () => {
throw err;
}, /You must supply options\.moduleName for UMD bundles/ );
}).then( () => {
return bundle.generate({
format: 'iife'
});
}).catch( err => {
assert.throws( () => {
throw err;
}, /You must supply options\.moduleName for IIFE bundles/ );
});
});
it( 'warns on es6 format', () => {
let warned;
return rollup.rollup({
entry: 'x',
plugins: [{
resolveId: () => { return 'test'; },
load: () => {
return '// empty';
}
}],
onwarn: msg => {
if ( /The es6 format is deprecated/.test( msg ) ) warned = true;
}
}).then( bundle => {
return bundle.generate({ format: 'es6' });
}).then( () => {
assert.ok( warned );
});
});
});
describe( 'function', () => {
sander.readdirSync( FUNCTION ).sort().forEach( dir => {
if ( dir[0] === '.' ) return; // .DS_Store...
const config = loadConfig( FUNCTION + '/' + dir + '/_config.js' );
( config.skip ? it.skip : config.solo ? it.only : it )( dir, () => {
process.chdir( FUNCTION + '/' + dir );
const warnings = [];
const captureWarning = msg => warnings.push( msg );
const options = extend( {
entry: FUNCTION + '/' + dir + '/main.js',
onwarn: captureWarning
}, config.options );
if ( config.solo ) console.group( dir );
return rollup.rollup( options )
.then( bundle => {
let unintendedError;
if ( config.error ) {
throw new Error( 'Expected an error while rolling up' );
}
let result;
// try to generate output
return Promise.resolve().then( () => {
return bundle.generate( extend( {}, config.bundleOptions, {
format: 'cjs'
}));
}).then( code => {
if ( config.generateError ) {
unintendedError = new Error( 'Expected an error while generating output' );
}
result = code;
}).catch( err => {
if ( config.generateError ) {
compareError( err, config.generateError );
} else {
unintendedError = err;
}
}).then( () => {
if ( unintendedError ) throw unintendedError;
if ( config.error || config.generateError ) return;
let code = result.code;
if ( config.buble ) {
code = buble.transform( code, {
transforms: { modules: false }
}).code;
}
if ( config.code ) config.code( code );
const module = {
exports: {}
};
const context = extend({ require, module, assert, exports: module.exports }, config.context || {} );
const contextKeys = Object.keys( context );
const contextValues = contextKeys.map( key => context[ key ] );
try {
const fn = new Function( contextKeys, code );
fn.apply( {}, contextValues );
if ( config.runtimeError ) {
unintendedError = new Error( 'Expected an error while executing output' );
} else {
if ( config.exports ) config.exports( module.exports );
if ( config.bundle ) config.bundle( bundle );
}
} catch ( err ) {
if ( config.runtimeError ) {
config.runtimeError( err );
} else {
unintendedError = err;
}
}
if ( config.show || unintendedError ) {
console.log( result.code + '\n\n\n' );
}
if ( config.warnings ) {
if ( Array.isArray( config.warnings ) ) {
compareWarnings( warnings, config.warnings );
} else {
config.warnings( warnings );
}
} else if ( warnings.length ) {
throw new Error( `Got unexpected warnings:\n${warnings.join('\n')}` );
}
if ( config.solo ) console.groupEnd();
if ( unintendedError ) throw unintendedError;
});
})
.catch( err => {
if ( config.error ) {
compareError( err, config.error );
} else {
throw err;
}
});
});
});
});
describe( 'form', () => {
sander.readdirSync( FORM ).sort().forEach( dir => {
if ( dir[0] === '.' ) return; // .DS_Store...
const config = loadConfig( FORM + '/' + dir + '/_config.js' );
if ( config.skipIfWindows && process.platform === 'win32' ) return;
if ( !config.options ) {
config.options = {};
}
if ( !( 'indent' in config.options ) ) {
config.options.indent = true;
}
const options = extend( {}, {
entry: FORM + '/' + dir + '/main.js',
onwarn: msg => {
if ( /No name was provided for/.test( msg ) ) return;
if ( /as external dependency/.test( msg ) ) return;
console.error( msg );
}
}, config.options );
( config.skip ? describe.skip : config.solo ? describe.only : describe )( dir, () => {
let promise;
const createBundle = () => ( promise || ( promise = rollup.rollup( options ) ) );
PROFILES.forEach( profile => {
it( 'generates ' + profile.format, () => {
process.chdir( FORM + '/' + dir );
return createBundle().then( bundle => {
const options = extend( {}, config.options, {
dest: FORM + '/' + dir + '/_actual/' + profile.format + '.js',
format: profile.format
});
return bundle.write( options ).then( () => {
const actualCode = normaliseOutput( sander.readFileSync( FORM, dir, '_actual', profile.format + '.js' ) );
let expectedCode;
let actualMap;
let expectedMap;
try {
expectedCode = normaliseOutput( sander.readFileSync( FORM, dir, '_expected', profile.format + '.js' ) );
} catch ( err ) {
expectedCode = 'missing file';
}
try {
actualMap = JSON.parse( sander.readFileSync( FORM, dir, '_actual', profile.format + '.js.map' ).toString() );
actualMap.sourcesContent = actualMap.sourcesContent.map( normaliseOutput );
} catch ( err ) {
assert.equal( err.code, 'ENOENT' );
}
try {
expectedMap = JSON.parse( sander.readFileSync( FORM, dir, '_expected', profile.format + '.js.map' ).toString() );
expectedMap.sourcesContent = expectedMap.sourcesContent.map( normaliseOutput );
} catch ( err ) {
assert.equal( err.code, 'ENOENT' );
}
if ( config.show ) {
console.log( actualCode + '\n\n\n' );
}
assert.equal( actualCode, expectedCode );
assert.deepEqual( actualMap, expectedMap );
});
});
});
});
});
});
});
describe( 'sourcemaps', () => {
sander.readdirSync( SOURCEMAPS ).sort().forEach( dir => {
if ( dir[0] === '.' ) return; // .DS_Store...
describe( dir, () => {
process.chdir( SOURCEMAPS + '/' + dir );
const config = loadConfig( SOURCEMAPS + '/' + dir + '/_config.js' );
const entry = path.resolve( SOURCEMAPS, dir, 'main.js' );
const dest = path.resolve( SOURCEMAPS, dir, '_actual/bundle' );
let warnings;
const options = extend( {}, config.options, {
entry,
onwarn: warning => warnings.push( warning )
});
PROFILES.forEach( profile => {
( config.skip ? it.skip : config.solo ? it.only : it )( 'generates ' + profile.format, () => {
process.chdir( SOURCEMAPS + '/' + dir );
warnings = [];
const testBundle = (bundle) => {
const options = extend( {}, {
format: profile.format,
sourceMap: true,
dest: `${dest}.${profile.format}.js`
}, config.options );
bundle.write( options );
bundle.generate( options ).then( ({ code, map }) => {
if ( config.test ) {
config.test( code, map, profile );
}
if ( config.warnings ) {
compareWarnings( warnings, config.warnings );
} else if ( warnings.length ) {
throw new Error( `Unexpected warnings` );
}
});
};
return rollup.rollup( options ).then(bundle => {
testBundle(bundle);
// cache rebuild does not reemit warnings.
if ( config.warnings ) {
return;
}
// test cache noop rebuild
return rollup.rollup( extend({ cache: bundle }, options) ).then(bundle => {
testBundle(bundle);
});
});
});
});
});
});
});
describe( 'cli', () => {
sander.readdirSync( CLI ).sort().forEach( dir => {
if ( dir[0] === '.' ) return; // .DS_Store...
describe( dir, () => {
const config = loadConfig( CLI + '/' + dir + '/_config.js' );
( config.skip ? it.skip : config.solo ? it.only : it )( dir, done => {
process.chdir( config.cwd || path.resolve( CLI, dir ) );
const command = 'node ' + path.resolve( __dirname, '../bin' ) + path.sep + config.command;
exec( command, {}, ( err, code, stderr ) => {
if ( err ) {
if ( config.error ) {
config.error( err );
return done();
} else {
throw err;
}
}
if ( 'stderr' in config ) {
assert.equal( deindent( config.stderr ), stderr.trim() );
} else if ( stderr ) {
console.error( stderr );
}
let unintendedError;
if ( config.execute ) {
try {
if ( config.buble ) {
code = buble.transform( code, {
transforms: { modules: false }
}).code;
}
const fn = new Function( 'require', 'module', 'exports', 'assert', code );
const module = {
exports: {}
};
fn( require, module, module.exports, assert );
if ( config.error ) {
unintendedError = new Error( 'Expected an error while executing output' );
}
if ( config.exports ) {
config.exports( module.exports );
}
} catch ( err ) {
if ( config.error ) {
config.error( err );
} else {
unintendedError = err;
}
}
if ( config.show || unintendedError ) {
console.log( code + '\n\n\n' );
}
if ( config.solo ) console.groupEnd();
unintendedError ? done( unintendedError ) : done();
}
else if ( config.result ) {
try {
config.result( code );
done();
} catch ( err ) {
done( err );
}
}
else if ( sander.existsSync( '_expected' ) && sander.statSync( '_expected' ).isDirectory() ) {
let error = null;
sander.readdirSync( '_expected' ).forEach( child => {
const expected = sander.readFileSync( path.join( '_expected', child ) ).toString();
const actual = sander.readFileSync( path.join( '_actual', child ) ).toString();
try {
assert.equal( normaliseOutput( actual ), normaliseOutput( expected ) );
} catch ( err ) {
error = err;
}
});
done( error );
}
else {
const expected = sander.readFileSync( '_expected.js' ).toString();
try {
assert.equal( normaliseOutput( code ), normaliseOutput( expected ) );
done();
} catch ( err ) {
done( err );
}
}
});
});
});
});
});
describe( 'incremental', () => {
function executeBundle ( bundle ) {
return bundle.generate({
format: 'cjs'
}).then( cjs => {
const m = new Function( 'module', 'exports', cjs.code );
const module = { exports: {} };
m( module, module.exports );
return module.exports;
});
}
let resolveIdCalls;
let transformCalls;
let modules;
const plugin = {
resolveId: id => {
resolveIdCalls += 1;
return id;
},
load: id => {
return modules[ id ];
},
transform: code => {
transformCalls += 1;
return code;
}
};
beforeEach( () => {
resolveIdCalls = 0;
transformCalls = 0;
modules = {
entry: `import foo from 'foo'; export default foo;`,
foo: `export default 42`,
bar: `export default 21`
};
});
it('does not resolves id and transforms in the second time', () => {
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ]
}).then( bundle => {
assert.equal( resolveIdCalls, 2 );
assert.equal( transformCalls, 2 );
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ],
cache: bundle
});
}).then( bundle => {
assert.equal( resolveIdCalls, 3 ); // +1 for entry point which is resolved every time
assert.equal( transformCalls, 2 );
return executeBundle( bundle );
}).then( result => {
assert.equal( result, 42 );
});
});
it('transforms modified sources', () => {
let cache;
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ]
}).then( bundle => {
assert.equal(transformCalls, 2);
return executeBundle(bundle).then( result => {
assert.equal( result, 42 );
modules.foo = `export default 43`;
cache = bundle;
});
}).then( () => {
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ],
cache
});
}).then( bundle => {
assert.equal( transformCalls, 3 );
return executeBundle( bundle );
}).then( result => {
assert.equal( result, 43 );
});
});
it('resolves id of new imports', () => {
let cache;
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ]
}).then( bundle => {
assert.equal( resolveIdCalls, 2 );
return executeBundle( bundle ).then( result => {
assert.equal( result, 42 );
modules.entry = `import bar from 'bar'; export default bar;`;
cache = bundle;
});
}).then( () => {
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ],
cache
});
}).then( bundle => {
assert.equal( resolveIdCalls, 4 );
return executeBundle( bundle );
}).then( result => {
assert.equal( result, 21 );
});
});
it( 'keeps ASTs between runs', () => {
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ]
}).then( bundle => {
const asts = {};
bundle.modules.forEach( module => {
asts[ module.id ] = module.ast;
});
assert.deepEqual( asts.entry, acorn.parse( modules.entry, { sourceType: 'module' }) );
assert.deepEqual( asts.foo, acorn.parse( modules.foo, { sourceType: 'module' }) );
});
});
it( 'recovers from errors', () => {
modules.entry = `import foo from 'foo'; import bar from 'bar'; export default foo + bar;`;
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ]
}).then( cache => {
modules.foo = `var 42 = nope;`;
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ],
cache
}).catch( err => {
return cache;
});
}).then( cache => {
modules.foo = `export default 42;`;
return rollup.rollup({
entry: 'entry',
plugins: [ plugin ],
cache
}).then( bundle => {
return executeBundle( bundle );
}).then( result => {
assert.equal( result, 63 );
});
});
});
});
describe( 'hooks', () => {
it( 'passes bundle & output object to ongenerate & onwrite hooks', () => {
const dest = path.join( __dirname, 'tmp/bundle.js' );
return rollup.rollup({
entry: 'entry',
plugins: [
loader({ entry: `alert('hello')` }),
{
ongenerate ( bundle, out ) {
out.ongenerate = true;
},
onwrite (bundle, out ) {
assert.equal(out.ongenerate, true);
}
}
]
}).then( bundle => {
return bundle.write({
dest
});
}).then( () => {
return sander.unlink( dest );
});
});
it( 'calls ongenerate hooks in sequence', () => {
const result = [];
return rollup.rollup({
entry: 'entry',
plugins: [
loader({ entry: `alert('hello')` }),
{
ongenerate ( info ) {
result.push({ a: info.format });
}
},
{
ongenerate ( info ) {
result.push({ b: info.format });
}
}
]
})
.then( bundle => bundle.generate({ format: 'cjs' }))
.then( () => {
assert.deepEqual( result, [
{ a: 'cjs' },
{ b: 'cjs' }
]);
});
});
it( 'calls onwrite hooks in sequence', () => {
const result = [];
const dest = path.join( __dirname, 'tmp/bundle.js' );
return rollup.rollup({
entry: 'entry',
plugins: [
loader({ entry: `alert('hello')` }),
{
onwrite ( info ) {
return new Promise( ( fulfil ) => {
result.push({ a: info.dest, format: info.format });
fulfil();
});
}
},
{
onwrite ( info ) {
result.push({ b: info.dest, format: info.format });
}
}
]
}).then( bundle => {
return bundle.write({
dest,
format: 'cjs'
});
}).then( () => {
assert.deepEqual( result, [
{ a: dest, format: 'cjs' },
{ b: dest, format: 'cjs' }
]);
return sander.unlink( dest );
});
});
});
describe( 'misc', () => {
it( 'warns if node builtins are unresolved in a non-CJS, non-ES bundle (#1051)', () => {
const warnings = [];
return rollup.rollup({
entry: 'entry',
plugins: [
loader({ entry: `import { format } from 'util';\nexport default format( 'this is a %s', 'formatted string' );` })
],
onwarn: warning => warnings.push( warning )
})
.then( bundle => bundle.generate({
format: 'iife',
moduleName: 'myBundle'
}))
.then(() => {
const relevantWarnings = warnings.filter( warning => warning.code === 'MISSING_NODE_BUILTINS' );
assert.equal( relevantWarnings.length, 1 );
assert.equal( relevantWarnings[0].message, `Creating a browser bundle that depends on Node.js built-in module ('util'). You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins` );
});
});
});
});