diff --git a/src/Bundle.js b/src/Bundle.js index 692ab08..d98db39 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -377,6 +377,10 @@ export default class Bundle { } }); + if ( !magicString.toString().trim() && this.entryModule.getExports().length === 0 ) { + this.onwarn( 'Generated an empty bundle' ); + } + timeEnd( 'render modules' ); let intro = [ options.intro ] diff --git a/test/function/assign-namespace-to-var/_config.js b/test/function/assign-namespace-to-var/_config.js index ce0a100..2eb7e9c 100644 --- a/test/function/assign-namespace-to-var/_config.js +++ b/test/function/assign-namespace-to-var/_config.js @@ -1,3 +1,10 @@ +const assert = require( 'assert' ); + module.exports = { - description: 'allows a namespace to be assigned to a variable' + description: 'allows a namespace to be assigned to a variable', + warnings: warnings => { + assert.deepEqual( warnings, [ + 'Generated an empty bundle' + ]); + } }; diff --git a/test/function/consistent-renaming/main.js b/test/function/consistent-renaming/main.js index e4209a5..fd52eba 100644 --- a/test/function/consistent-renaming/main.js +++ b/test/function/consistent-renaming/main.js @@ -1,3 +1,7 @@ import { one as oneRenamed } from './one'; import { two } from './two'; -import { three as threeRenamed } from './three'; \ No newline at end of file +import { three as threeRenamed } from './three'; + +assert.equal( oneRenamed, 1 ); +assert.equal( two, 2 ); +assert.equal( threeRenamed, 3 ); diff --git a/test/function/cycles-pathological-3/_config.js b/test/function/cycles-pathological-3/_config.js deleted file mode 100644 index 155e2f6..0000000 --- a/test/function/cycles-pathological-3/_config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - description: 'resolves more pathological cyclical dependencies gracefully' -}; diff --git a/test/function/cycles-pathological-3/a.js b/test/function/cycles-pathological-3/a.js deleted file mode 100644 index c77b86b..0000000 --- a/test/function/cycles-pathological-3/a.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as x from "./x.a.js"; -x.b(); -x.c(); \ No newline at end of file diff --git a/test/function/cycles-pathological-3/b.js b/test/function/cycles-pathological-3/b.js deleted file mode 100644 index b93201c..0000000 --- a/test/function/cycles-pathological-3/b.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as x from "./x.b.js"; - -export function b() {} \ No newline at end of file diff --git a/test/function/cycles-pathological-3/c.js b/test/function/cycles-pathological-3/c.js deleted file mode 100644 index 60a9826..0000000 --- a/test/function/cycles-pathological-3/c.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as x from "./x.c.js"; - -export function c() {} \ No newline at end of file diff --git a/test/function/cycles-pathological-3/main.js b/test/function/cycles-pathological-3/main.js deleted file mode 100644 index 1580611..0000000 --- a/test/function/cycles-pathological-3/main.js +++ /dev/null @@ -1 +0,0 @@ -import './a.js'; \ No newline at end of file diff --git a/test/function/cycles-pathological-3/x.a.js b/test/function/cycles-pathological-3/x.a.js deleted file mode 100644 index e73df11..0000000 --- a/test/function/cycles-pathological-3/x.a.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./b.js"; -export * from "./c.js"; \ No newline at end of file diff --git a/test/function/cycles-pathological-3/x.b.js b/test/function/cycles-pathological-3/x.b.js deleted file mode 100644 index c3e2ed3..0000000 --- a/test/function/cycles-pathological-3/x.b.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./a.js"; -export * from "./c.js"; \ No newline at end of file diff --git a/test/function/cycles-pathological-3/x.c.js b/test/function/cycles-pathological-3/x.c.js deleted file mode 100644 index 2f49591..0000000 --- a/test/function/cycles-pathological-3/x.c.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./a.js"; -export * from "./b.js"; \ No newline at end of file diff --git a/test/function/empty-exports/_config.js b/test/function/empty-exports/_config.js index 65b2185..8030197 100644 --- a/test/function/empty-exports/_config.js +++ b/test/function/empty-exports/_config.js @@ -1,17 +1,12 @@ -var assert = require( 'assert' ); - -var warned = false; +const assert = require( 'assert' ); +const path = require( 'path' ); module.exports = { description: 'warns on export {}, but does not fail', - options: { - onwarn: function ( msg ) { - warned = true; - assert.ok( /main\.js has an empty export declaration/.test( msg ) ); - } - }, - exports: function ( exports ) { - assert.equal( Object.keys( exports ).length, 0 ); - assert.ok( warned, 'did not warn' ); + warnings: warnings => { + assert.deepEqual( warnings, [ + `Module ${path.resolve( __dirname, 'main.js' )} has an empty export declaration`, + 'Generated an empty bundle' + ]); } }; diff --git a/test/function/handles-multiple-declarations/_config.js b/test/function/handles-multiple-declarations/_config.js deleted file mode 100644 index 94022ee..0000000 --- a/test/function/handles-multiple-declarations/_config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - description: 'handles multiple declaration blocks with multiple declarations (#105)' -}; diff --git a/test/function/handles-multiple-declarations/main.js b/test/function/handles-multiple-declarations/main.js deleted file mode 100644 index a8af4cd..0000000 --- a/test/function/handles-multiple-declarations/main.js +++ /dev/null @@ -1,2 +0,0 @@ -var a, b; -var c, d; diff --git a/test/function/module-tree/_config.js b/test/function/module-tree/_config.js index 553ab2b..9662844 100644 --- a/test/function/module-tree/_config.js +++ b/test/function/module-tree/_config.js @@ -33,5 +33,10 @@ module.exports = { dependencies: [ 'foo.js', 'bar.js' ] } ]); + }, + warnings: warnings => { + assert.deepEqual( warnings, [ + 'Generated an empty bundle' + ]); } }; diff --git a/test/function/warn-on-empty-bundle/_config.js b/test/function/warn-on-empty-bundle/_config.js new file mode 100644 index 0000000..2e599ad --- /dev/null +++ b/test/function/warn-on-empty-bundle/_config.js @@ -0,0 +1,10 @@ +const assert = require( 'assert' ); + +module.exports = { + description: 'warns if empty bundle is generated (#444)', + warnings: warnings => { + assert.deepEqual( warnings, [ + 'Generated an empty bundle' + ]); + } +}; diff --git a/test/function/warn-on-empty-bundle/main.js b/test/function/warn-on-empty-bundle/main.js new file mode 100644 index 0000000..235183b --- /dev/null +++ b/test/function/warn-on-empty-bundle/main.js @@ -0,0 +1,2 @@ +function noop () {} +noop();