Browse Source

update tests to reflect proposed 0.20.0 API

better-aggressive
Rich Harris 9 years ago
parent
commit
fb2a7f27bf
  1. 6
      test/function/custom-external-resolver-async/_config.js
  2. 6
      test/function/custom-external-resolver-sync/_config.js
  3. 10
      test/function/custom-loaders/_config.js
  4. 2
      test/function/custom-path-resolver-async/_config.js
  5. 2
      test/function/custom-path-resolver-on-entry/_config.js
  6. 16
      test/function/custom-path-resolver-plural-b/_config.js
  7. 16
      test/function/custom-path-resolver-plural/_config.js
  8. 2
      test/function/custom-path-resolver-sync/_config.js
  9. 9
      test/function/does-not-hang-on-missing-module/_config.js
  10. 4
      test/function/import-from-external-subdirectory/_config.js
  11. 5
      test/function/import-from-external-subdirectory/main.js
  12. 2
      test/function/uses-supplied-ast/_config.js

6
test/function/custom-external-resolver-async/_config.js

@ -5,9 +5,11 @@ var Promise = require( 'sander' ).Promise;
module.exports = { module.exports = {
description: 'uses a custom external path resolver (asynchronous)', description: 'uses a custom external path resolver (asynchronous)',
options: { options: {
resolveExternal: function ( id, importer, options ) { plugins: [{
return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) ); resolveId: function ( id, importer ) {
if ( importer && id[0] !== '.' ) return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.ok( exports.success ); assert.ok( exports.success );

6
test/function/custom-external-resolver-sync/_config.js

@ -4,9 +4,11 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom external path resolver (synchronous)', description: 'uses a custom external path resolver (synchronous)',
options: { options: {
resolveExternal: function ( id, importer, options ) { plugins: [{
return path.resolve( __dirname, 'js_modules', id + '.js' ); resolveId: function ( id, importer ) {
if ( importer && id[0] !== '.' ) return path.resolve( __dirname, 'js_modules', id + '.js' );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.ok( exports.success ); assert.ok( exports.success );

10
test/function/custom-loaders/_config.js

@ -3,17 +3,21 @@ var fs = require( 'fs' );
module.exports = { module.exports = {
description: 'uses custom loaders, falling back to default', description: 'uses custom loaders, falling back to default',
options: { options: {
load: [ plugins: [
function ( id ) { {
load: function ( id ) {
if ( /foo\.js/.test( id ) ) { if ( /foo\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 ); return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 );
} }
}
}, },
function ( id ) { {
load: function ( id ) {
if ( /bar\.js/.test( id ) ) { if ( /bar\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 ); return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 );
} }
} }
}
] ]
} }
}; };

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

@ -4,6 +4,7 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom path resolver (asynchronous)', description: 'uses a custom path resolver (asynchronous)',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
var Promise = require( 'sander' ).Promise; var Promise = require( 'sander' ).Promise;
var resolved; var resolved;
@ -18,6 +19,7 @@ module.exports = {
return Promise.resolve( resolved ); return Promise.resolve( resolved );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) ); assert.strictEqual( exports.path, require( 'path' ) );

2
test/function/custom-path-resolver-on-entry/_config.js

@ -10,6 +10,7 @@ module.exports = {
description: 'applies custom resolver to entry point', description: 'applies custom resolver to entry point',
//solo: true, //solo: true,
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( importer === undefined ) { if ( importer === undefined ) {
return '@' + path.relative( __dirname, importee ); return '@' + path.relative( __dirname, importee );
@ -26,6 +27,7 @@ module.exports = {
return fs.readFileSync( moduleId, 'utf-8' ); return fs.readFileSync( moduleId, 'utf-8' );
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.equal( exports, 42 ); assert.equal( exports, 42 );

16
test/function/custom-path-resolver-plural-b/_config.js

@ -3,18 +3,22 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'resolver error is not caught', description: 'resolver error is not caught',
options: { options: {
resolveId: [ plugins: [
function () { {
resolveId: function () {
throw new Error( 'nope' ); throw new Error( 'nope' );
}, },
function ( importee, importer ) {
return 'main';
}
],
load: function ( id ) { load: function ( id ) {
if ( id === 'main' ) return 'assert.ok( false );' if ( id === 'main' ) return 'assert.ok( false );'
} }
}, },
{
resolveId: function ( importee, importer ) {
return 'main';
}
}
]
},
error: function ( err ) { error: function ( err ) {
assert.equal( err.message, 'nope' ); assert.equal( err.message, 'nope' );
} }

16
test/function/custom-path-resolver-plural/_config.js

@ -4,19 +4,23 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses custom path resolvers (plural)', description: 'uses custom path resolvers (plural)',
options: { options: {
resolveId: [ plugins: [
function ( importee ) { {
resolveId: function ( importee ) {
if ( importee[0] === '@' ) if ( importee[0] === '@' )
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' ); return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' );
}, },
function ( importee ) {
if ( importee[0] === '!' ) return '<empty>';
}
],
load: function ( id ) { load: function ( id ) {
if ( id === '<empty>' ) return ''; if ( id === '<empty>' ) return '';
} }
}, },
{
resolveId: function ( importee ) {
if ( importee[0] === '!' ) return '<empty>';
}
}
]
},
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.res, 0 ); assert.strictEqual( exports.res, 0 );
} }

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

@ -4,12 +4,14 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom path resolver (synchronous)', description: 'uses a custom path resolver (synchronous)',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee; if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee;
if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' ); if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' );
return false; return false;
} }
}]
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) ); assert.strictEqual( exports.path, require( 'path' ) );

9
test/function/does-not-hang-on-missing-module/_config.js

@ -2,7 +2,12 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'does not hang on missing module (#53)', description: 'does not hang on missing module (#53)',
error: function ( error ) { options: {
assert.ok( /Could not find package unlessYouCreatedThisFileForSomeReason/.test( error.message ) ); onwarn: function ( msg ) {
assert.equal( "Treating 'unlessYouCreatedThisFileForSomeReason' as external dependency", msg );
}
},
runtimeError: function ( error ) {
assert.equal( "Cannot find module 'unlessYouCreatedThisFileForSomeReason'", error.message );
} }
}; };

4
test/function/import-from-external-subdirectory/_config.js

@ -1,4 +0,0 @@
module.exports = {
description: 'default resolver imports from a subdirectory of an external module',
babel: true
};

5
test/function/import-from-external-subdirectory/main.js

@ -1,5 +0,0 @@
// this test is brittle, it relies on this dependency continuing
// to be structured in a certain way
import btoa from 'magic-string/src/utils/btoa';
assert.equal( btoa( 'it works' ), new Buffer( 'it works' ).toString( 'base64' ) );

2
test/function/uses-supplied-ast/_config.js

@ -19,6 +19,7 @@ var modules = {
module.exports = { module.exports = {
description: 'uses supplied AST', description: 'uses supplied AST',
options: { options: {
plugins: [{
resolveId: function ( importee, importer ) { resolveId: function ( importee, importer ) {
if ( !importer ) return 'main'; if ( !importer ) return 'main';
return importee; return importee;
@ -30,5 +31,6 @@ module.exports = {
return modules[ id ]; return modules[ id ];
} }
}]
} }
}; };

Loading…
Cancel
Save