Browse Source

easier way to expect warnings in tests

gh-669
Rich Harris 9 years ago
parent
commit
49154f2e2d
  1. 7
      test/function/confused-default-identifier/_config.js
  2. 5
      test/function/custom-path-resolver-async/_config.js
  3. 5
      test/function/custom-path-resolver-sync/_config.js
  4. 12
      test/test.js

7
test/function/confused-default-identifier/_config.js

@ -1,5 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'Rollup should not get confused and allow "default" as an identifier name'
description: 'Rollup should not get confused and allow "default" as an identifier name',
warnings: function ( warnings ) {
// ignore pending gh-587
}
};
// https://github.com/rollup/rollup/issues/215

5
test/function/custom-path-resolver-async/_config.js

@ -21,6 +21,11 @@ module.exports = {
}
}]
},
warnings: function ( warnings ) {
assert.deepEqual( warnings, [
"Treating 'path' as external dependency"
]);
},
exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) );
}

5
test/function/custom-path-resolver-sync/_config.js

@ -13,6 +13,11 @@ module.exports = {
}
}]
},
warnings: function ( warnings ) {
assert.deepEqual( warnings, [
"Treating 'path' as external dependency"
]);
},
exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) );
}

12
test/test.js

@ -133,8 +133,12 @@ describe( 'rollup', function () {
var config = loadConfig( FUNCTION + '/' + dir + '/_config.js' );
( config.skip ? it.skip : config.solo ? it.only : it )( dir, function () {
var warnings = [];
var captureWarning = msg => warnings.push( msg );
var options = extend( {
entry: FUNCTION + '/' + dir + '/main.js'
entry: FUNCTION + '/' + dir + '/main.js',
onwarn: captureWarning
}, config.options );
if ( config.solo ) console.group( dir );
@ -215,6 +219,12 @@ describe( 'rollup', function () {
}
}
if ( config.warnings ) {
config.warnings( warnings );
} else if ( warnings.length ) {
throw new Error( `Got unexpected warnings:\n${warnings.join('\n')}` );
}
if ( config.show || unintendedError ) {
console.log( code + '\n\n\n' );
}

Loading…
Cancel
Save