Browse Source

update tests to reflect proposed 0.20.0 API

better-aggressive
Rich Harris 9 years ago
parent
commit
fb2a7f27bf
  1. 8
      test/function/custom-external-resolver-async/_config.js
  2. 8
      test/function/custom-external-resolver-sync/_config.js
  3. 18
      test/function/custom-loaders/_config.js
  4. 24
      test/function/custom-path-resolver-async/_config.js
  5. 30
      test/function/custom-path-resolver-on-entry/_config.js
  6. 22
      test/function/custom-path-resolver-plural-b/_config.js
  7. 24
      test/function/custom-path-resolver-plural/_config.js
  8. 12
      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. 22
      test/function/uses-supplied-ast/_config.js

8
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 );

8
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 );

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

@ -3,15 +3,19 @@ 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 ) { {
if ( /foo\.js/.test( id ) ) { load: function ( id ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 ); if ( /foo\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 );
}
} }
}, },
function ( id ) { {
if ( /bar\.js/.test( id ) ) { load: function ( id ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 ); if ( /bar\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 );
}
} }
} }
] ]

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

@ -4,20 +4,22 @@ var assert = require( 'assert' );
module.exports = { module.exports = {
description: 'uses a custom path resolver (asynchronous)', description: 'uses a custom path resolver (asynchronous)',
options: { options: {
resolveId: function ( importee, importer ) { plugins: [{
var Promise = require( 'sander' ).Promise; resolveId: function ( importee, importer ) {
var resolved; var Promise = require( 'sander' ).Promise;
var resolved;
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' ) { if ( importee === 'foo' ) {
resolved = path.resolve( __dirname, 'bar.js' ); resolved = path.resolve( __dirname, 'bar.js' );
} else { } else {
resolved = false; resolved = false;
} }
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' ) );

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

@ -10,22 +10,24 @@ module.exports = {
description: 'applies custom resolver to entry point', description: 'applies custom resolver to entry point',
//solo: true, //solo: true,
options: { options: {
resolveId: function ( importee, importer ) { plugins: [{
if ( importer === undefined ) { resolveId: function ( importee, importer ) {
return '@' + path.relative( __dirname, importee ); if ( importer === undefined ) {
} return '@' + path.relative( __dirname, importee );
}
if ( importer[0] === '@' ) { if ( importer[0] === '@' ) {
return path.resolve( __dirname, importee ) + '.js'; return path.resolve( __dirname, importee ) + '.js';
} }
}, },
load: function ( moduleId ) { load: function ( moduleId ) {
if ( moduleId[0] === '@' ) { if ( moduleId[0] === '@' ) {
return cachedModules[ moduleId ]; return cachedModules[ moduleId ];
} }
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 );

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

@ -3,17 +3,21 @@ 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 () { {
throw new Error( 'nope' ); resolveId: function () {
throw new Error( 'nope' );
},
load: function ( id ) {
if ( id === 'main' ) return 'assert.ok( false );'
}
}, },
function ( importee, importer ) { {
return 'main'; resolveId: function ( importee, importer ) {
return 'main';
}
} }
], ]
load: function ( id ) {
if ( id === 'main' ) return 'assert.ok( false );'
}
}, },
error: function ( err ) { error: function ( err ) {
assert.equal( err.message, 'nope' ); assert.equal( err.message, 'nope' );

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

@ -4,18 +4,22 @@ 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 ) { {
if ( importee[0] === '@' ) resolveId: function ( importee ) {
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' ); if ( importee[0] === '@' )
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' );
},
load: function ( id ) {
if ( id === '<empty>' ) return '';
}
}, },
function ( importee ) { {
if ( importee[0] === '!' ) return '<empty>'; resolveId: function ( importee ) {
if ( importee[0] === '!' ) return '<empty>';
}
} }
], ]
load: function ( id ) {
if ( id === '<empty>' ) return '';
}
}, },
exports: function ( exports ) { exports: function ( exports ) {
assert.strictEqual( exports.res, 0 ); assert.strictEqual( exports.res, 0 );

12
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: {
resolveId: function ( importee, importer ) { plugins: [{
if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee; resolveId: function ( importee, importer ) {
if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' ); if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee;
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' ) );

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

@ -19,16 +19,18 @@ var modules = {
module.exports = { module.exports = {
description: 'uses supplied AST', description: 'uses supplied AST',
options: { options: {
resolveId: function ( importee, importer ) { plugins: [{
if ( !importer ) return 'main'; resolveId: function ( importee, importer ) {
return importee; if ( !importer ) return 'main';
}, return importee;
load: function ( id ) { },
if ( id === 'bar' ) { load: function ( id ) {
throw new Error( 'loaded incorrect module' ); if ( id === 'bar' ) {
} throw new Error( 'loaded incorrect module' );
}
return modules[ id ]; return modules[ id ];
} }
}]
} }
}; };

Loading…
Cancel
Save