Browse Source

test for bad export types

better-aggressive
Rich Harris 9 years ago
parent
commit
1034d0b6fe
  1. 11
      test/function/export-type-mismatch-b/_config.js
  2. 1
      test/function/export-type-mismatch-b/main.js
  3. 11
      test/function/export-type-mismatch-c/_config.js
  4. 1
      test/function/export-type-mismatch-c/main.js
  5. 11
      test/function/export-type-mismatch/_config.js
  6. 1
      test/function/export-type-mismatch/main.js
  7. 71
      test/test.js

11
test/function/export-type-mismatch-b/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'export type must be auto, default, named or none',
bundleOptions: {
exports: 'blah'
},
generateError: function ( err ) {
assert.ok( /options\.exports must be 'default', 'named', 'none', 'auto', or left unspecified/.test( err.message ) );
}
};

1
test/function/export-type-mismatch-b/main.js

@ -0,0 +1 @@
export default 42;

11
test/function/export-type-mismatch-c/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'cannot have named exports if explicit export type is default',
bundleOptions: {
exports: 'none'
},
generateError: function ( err ) {
assert.ok( /'none' was specified for options\.exports/.test( err.message ) );
}
};

1
test/function/export-type-mismatch-c/main.js

@ -0,0 +1 @@
export default 42;

11
test/function/export-type-mismatch/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'cannot have named exports if explicit export type is default',
bundleOptions: {
exports: 'default'
},
generateError: function ( err ) {
assert.ok( /'default' was specified for options\.exports/.test( err.message ) );
}
};

1
test/function/export-type-mismatch/main.js

@ -0,0 +1 @@
export var foo = 42;

71
test/test.js

@ -110,64 +110,57 @@ describe( 'rollup', function () {
format: 'cjs' format: 'cjs'
})); }));
if ( config.error ) { if ( config.generateError ) {
unintendedError = new Error( 'Expected an error while generating output' ); unintendedError = new Error( 'Expected an error while generating output' );
} }
} catch ( err ) { } catch ( err ) {
if ( config.error ) { if ( config.generateError ) {
config.error( err ); config.generateError( err );
} else { } else {
unintendedError = err; unintendedError = err;
} }
} }
if ( unintendedError ) throw unintendedError; if ( unintendedError ) throw unintendedError;
if ( config.error || config.generateError ) return;
var code; var code;
try { if ( config.babel ) {
if ( config.babel ) { code = babel.transform( result.code, {
code = babel.transform( result.code, { blacklist: [ 'es6.modules' ],
blacklist: [ 'es6.modules' ], loose: [ 'es6.classes' ]
loose: [ 'es6.classes' ] }).code;
}).code; } else {
} else { code = result.code;
code = result.code; }
}
var module = { var module = {
exports: {} exports: {}
}; };
var context = extend({ var context = extend({
require: require, require: require,
module: module, module: module,
exports: module.exports, exports: module.exports,
assert: assert assert: assert
}, config.context || {} ); }, config.context || {} );
var contextKeys = Object.keys( context ); var contextKeys = Object.keys( context );
var contextValues = contextKeys.map( function ( key ) { var contextValues = contextKeys.map( function ( key ) {
return context[ key ]; return context[ key ];
}); });
var fn = new Function( contextKeys, code ); var fn = new Function( contextKeys, code );
fn.apply( {}, contextValues ); fn.apply( {}, contextValues );
if ( config.error ) { if ( config.error ) {
unintendedError = new Error( 'Expected an error while executing output' ); unintendedError = new Error( 'Expected an error while executing output' );
}
if ( config.exports ) config.exports( module.exports );
if ( config.bundle ) config.bundle( bundle );
} catch ( err ) {
if ( config.error ) {
config.error( err );
} else {
unintendedError = err;
}
} }
if ( config.exports ) config.exports( module.exports );
if ( config.bundle ) config.bundle( bundle );
if ( config.show || unintendedError ) { if ( config.show || unintendedError ) {
console.log( code + '\n\n\n' ); console.log( code + '\n\n\n' );
} }

Loading…
Cancel
Save