Browse Source

update tests

better-aggressive
Rich-Harris 9 years ago
parent
commit
7d7317e094
  1. 16
      test/function/export-default-anonymous-function/_config.js
  2. 18
      test/function/transformer-multiple/_config.js
  3. 8
      test/function/transformer-single/_config.js
  4. 30
      test/sourcemaps/transforms/_config.js

16
test/function/export-default-anonymous-function/_config.js

@ -4,12 +4,14 @@ var path = require( 'path' );
module.exports = { module.exports = {
description: 'exports an anonymous function with custom ID resolver', // yeah, this is a real edge case description: 'exports an anonymous function with custom ID resolver', // yeah, this is a real edge case
options: { options: {
resolveId: function ( importee, importer ) { plugins: [{
return path.basename( importee ).replace( /\..+/, '' ); resolveId: function ( importee, importer ) {
}, return path.basename( importee ).replace( /\..+/, '' );
load: function ( id ) { },
console.log( 'id', id ) load: function ( id ) {
return fs.readFileSync( path.join( __dirname, id + '.js' ), 'utf-8' ); console.log( 'id', id )
} return fs.readFileSync( path.join( __dirname, id + '.js' ), 'utf-8' );
}
}]
} }
}; };

18
test/function/transformer-multiple/_config.js

@ -3,15 +3,19 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'accepts multiple transformer functions', description: 'accepts multiple transformer functions',
options: { options: {
transform: [ plugins: [
function ( code, path ) { {
return code.replace( /MAGIC_NUMBER/g, 3 ); transform: function ( code, path ) {
return code.replace( /MAGIC_NUMBER/g, 3 );
}
}, },
function ( code, path ) { {
return code.replace( /\d+/g, function ( match ) { transform: function ( code, path ) {
return 2 * +match; return code.replace( /\d+/g, function ( match ) {
}); return 2 * +match;
});
}
} }
] ]
}, },

8
test/function/transformer-single/_config.js

@ -3,9 +3,11 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'accepts a single transformer function', description: 'accepts a single transformer function',
options: { options: {
transform: function ( code, path ) { plugins: [{
return code.replace( /MAGIC_NUMBER/g, 3 ); transform: function ( code, path ) {
} return code.replace( /MAGIC_NUMBER/g, 3 );
}
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.equal( exports.magicNumber, 3 ); assert.equal( exports.magicNumber, 3 );

30
test/sourcemaps/transforms/_config.js

@ -7,22 +7,26 @@ var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
module.exports = { module.exports = {
description: 'preserves sourcemap chains when transforming', description: 'preserves sourcemap chains when transforming',
options: { options: {
transform: [ plugins: [
function ( source, id ) { {
return babel.transform( source, { transform: function ( source, id ) {
blacklist: [ 'es6.modules' ], return babel.transform( source, {
sourceMap: true blacklist: [ 'es6.modules' ],
}); sourceMap: true
});
}
}, },
function ( source, id ) { {
var s = new MagicString( source ); transform: function ( source, id ) {
s.append( '\nassert.equal( 1 + 1, 2 );\nassert.equal( 2 + 2, 4 );' ); var s = new MagicString( source );
s.append( '\nassert.equal( 1 + 1, 2 );\nassert.equal( 2 + 2, 4 );' );
return { return {
code: s.toString(), code: s.toString(),
map: s.generateMap({ hires: true }) map: s.generateMap({ hires: true })
}; };
}
} }
] ]
}, },

Loading…
Cancel
Save