1- import multiEntry from '../' ;
21import { ok } from 'assert' ;
32import { rollup } from 'rollup' ;
3+ import multiEntry from '../' ;
44
55function includes ( string , substring ) {
66 if ( string . indexOf ( substring ) === - 1 ) {
@@ -24,79 +24,61 @@ function doesNotInclude(string, substring) {
2424 }
2525}
2626
27- function makeBundle ( entries ) {
28- return rollup ( { input : entries , plugins : [ multiEntry ( ) ] } ) ;
27+ function getCodeFromBundle ( entries ) {
28+ return rollup ( { input : entries , plugins : [ multiEntry ( ) ] } )
29+ . then ( bundle => bundle . generate ( { format : 'cjs' } ) )
30+ . then ( generated =>
31+ generated . output ? generated . output [ 0 ] . code : generated . code
32+ ) ;
2933}
3034
3135describe ( 'rollup-plugin-multi-entry' , ( ) => {
32- it ( 'takes a single file as input' , ( ) => {
33- return makeBundle ( 'test/fixtures/0.js' ) . then ( bundle => {
34- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
35- includes ( code , 'exports.zero = zero;' ) ;
36- } ) ;
37- } ) ;
38- } ) ;
36+ it ( 'takes a single file as input' , ( ) =>
37+ getCodeFromBundle ( 'test/fixtures/0.js' ) . then ( code =>
38+ includes ( code , 'exports.zero = zero;' )
39+ ) ) ;
3940
40- it ( 'takes an array of files as input' , ( ) => {
41- return makeBundle ( [ 'test/fixtures/0.js' , 'test/fixtures/1.js' ] ) . then (
42- bundle => {
43- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
44- includes ( code , 'exports.zero = zero;' ) ;
45- includes ( code , 'exports.one = one;' ) ;
46- } ) ;
41+ it ( 'takes an array of files as input' , ( ) =>
42+ getCodeFromBundle ( [ 'test/fixtures/0.js' , 'test/fixtures/1.js' ] ) . then (
43+ code => {
44+ includes ( code , 'exports.zero = zero;' ) ;
45+ includes ( code , 'exports.one = one;' ) ;
4746 }
48- ) ;
49- } ) ;
47+ ) ) ;
5048
51- it ( 'allows an empty array as input' , ( ) => {
52- return makeBundle ( [ ] ) . then ( bundle => {
53- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
54- doesNotInclude ( code , 'exports' ) ;
55- } ) ;
56- } ) ;
57- } ) ;
49+ it ( 'allows an empty array as input' , ( ) =>
50+ getCodeFromBundle ( [ ] ) . then ( code => doesNotInclude ( code , 'exports' ) ) ) ;
5851
59- it ( 'takes a glob as input' , ( ) => {
60- return makeBundle ( 'test/fixtures/{0,1}.js' ) . then ( bundle => {
61- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
52+ it ( 'takes a glob as input' , ( ) =>
53+ getCodeFromBundle ( 'test/fixtures/{0,1}.js' ) . then ( code => {
54+ includes ( code , 'exports.zero = zero;' ) ;
55+ includes ( code , 'exports.one = one;' ) ;
56+ } ) ) ;
57+
58+ it ( 'takes an array of globs as input' , ( ) =>
59+ getCodeFromBundle ( [ 'test/fixtures/{0,}.js' , 'test/fixtures/{1,}.js' ] ) . then (
60+ code => {
6261 includes ( code , 'exports.zero = zero;' ) ;
6362 includes ( code , 'exports.one = one;' ) ;
64- } ) ;
65- } ) ;
66- } ) ;
67-
68- it ( 'takes an array of globs as input' , ( ) => {
69- return makeBundle ( [ 'test/fixtures/{0,}.js' , 'test/fixtures/{1,}.js' ] ) . then (
70- bundle => {
71- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
72- includes ( code , 'exports.zero = zero;' ) ;
73- includes ( code , 'exports.one = one;' ) ;
74- } ) ;
7563 }
76- ) ;
77- } ) ;
64+ ) ) ;
7865
79- it ( 'takes an {include,exclude} object as input' , ( ) => {
80- return makeBundle ( {
66+ it ( 'takes an {include,exclude} object as input' , ( ) =>
67+ getCodeFromBundle ( {
8168 include : [ 'test/fixtures/*.js' ] ,
8269 exclude : [ 'test/fixtures/1.js' ]
83- } ) . then ( bundle => {
84- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
85- includes ( code , 'exports.zero = zero;' ) ;
86- doesNotInclude ( code , 'exports.one = one;' ) ;
87- } ) ;
88- } ) ;
89- } ) ;
70+ } ) . then ( code => {
71+ includes ( code , 'exports.zero = zero;' ) ;
72+ doesNotInclude ( code , 'exports.one = one;' ) ;
73+ } ) ) ;
9074
91- it ( 'allows to prevent exporting' , ( ) => {
92- return makeBundle ( { include : [ 'test/fixtures/*.js' ] , exports : false } ) . then (
93- bundle => {
94- return bundle . generate ( { format : 'cjs' } ) . then ( ( { code } ) => {
95- includes ( code , `console.log('Hello, 2');` ) ;
96- doesNotInclude ( code , 'zero' ) ;
97- doesNotInclude ( code , 'one' ) ;
98- } ) ;
99- }
100- ) ;
101- } ) ;
75+ it ( 'allows to prevent exporting' , ( ) =>
76+ getCodeFromBundle ( {
77+ include : [ 'test/fixtures/*.js' ] ,
78+ exports : false
79+ } ) . then ( code => {
80+ includes ( code , `console.log('Hello, 2');` ) ;
81+ doesNotInclude ( code , 'zero' ) ;
82+ doesNotInclude ( code , 'one' ) ;
83+ } ) ) ;
10284} ) ;
0 commit comments