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 = {
description: 'uses a custom external path resolver (asynchronous)',
options: {
resolveExternal: function ( id, importer, options ) {
return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) );
}
plugins: [{
resolveId: function ( id, importer ) {
if ( importer && id[0] !== '.' ) return Promise.resolve( path.resolve( __dirname, 'js_modules', id + '.js' ) );
}
}]
},
exports: function ( exports ) {
assert.ok( exports.success );

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

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

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

@ -3,15 +3,19 @@ var fs = require( 'fs' );
module.exports = {
description: 'uses custom loaders, falling back to default',
options: {
load: [
function ( id ) {
if ( /foo\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 );
plugins: [
{
load: function ( id ) {
if ( /foo\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 1 );
}
}
},
function ( id ) {
if ( /bar\.js/.test( id ) ) {
return fs.readFileSync( id, 'utf-8' ).replace( '@', 2 );
{
load: function ( id ) {
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 = {
description: 'uses a custom path resolver (asynchronous)',
options: {
resolveId: function ( importee, importer ) {
var Promise = require( 'sander' ).Promise;
var resolved;
plugins: [{
resolveId: function ( importee, importer ) {
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' ) {
resolved = path.resolve( __dirname, 'bar.js' );
} else {
resolved = false;
}
if ( importee === 'foo' ) {
resolved = path.resolve( __dirname, 'bar.js' );
} else {
resolved = false;
}
return Promise.resolve( resolved );
}
return Promise.resolve( resolved );
}
}]
},
exports: function ( exports ) {
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',
//solo: true,
options: {
resolveId: function ( importee, importer ) {
if ( importer === undefined ) {
return '@' + path.relative( __dirname, importee );
}
plugins: [{
resolveId: function ( importee, importer ) {
if ( importer === undefined ) {
return '@' + path.relative( __dirname, importee );
}
if ( importer[0] === '@' ) {
return path.resolve( __dirname, importee ) + '.js';
}
},
load: function ( moduleId ) {
if ( moduleId[0] === '@' ) {
return cachedModules[ moduleId ];
}
if ( importer[0] === '@' ) {
return path.resolve( __dirname, importee ) + '.js';
}
},
load: function ( moduleId ) {
if ( moduleId[0] === '@' ) {
return cachedModules[ moduleId ];
}
return fs.readFileSync( moduleId, 'utf-8' );
}
return fs.readFileSync( moduleId, 'utf-8' );
}
}]
},
exports: function ( exports ) {
assert.equal( exports, 42 );

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

@ -3,17 +3,21 @@ var assert = require( 'assert' );
module.exports = {
description: 'resolver error is not caught',
options: {
resolveId: [
function () {
throw new Error( 'nope' );
plugins: [
{
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 ) {
assert.equal( err.message, 'nope' );

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

@ -4,18 +4,22 @@ var assert = require( 'assert' );
module.exports = {
description: 'uses custom path resolvers (plural)',
options: {
resolveId: [
function ( importee ) {
if ( importee[0] === '@' )
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' );
plugins: [
{
resolveId: function ( importee ) {
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 ) {
assert.strictEqual( exports.res, 0 );

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

@ -4,12 +4,14 @@ var assert = require( 'assert' );
module.exports = {
description: 'uses a custom path resolver (synchronous)',
options: {
resolveId: function ( importee, importer ) {
if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee;
if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' );
plugins: [{
resolveId: function ( importee, importer ) {
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 ) {
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 = {
description: 'does not hang on missing module (#53)',
error: function ( error ) {
assert.ok( /Could not find package unlessYouCreatedThisFileForSomeReason/.test( error.message ) );
options: {
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 = {
description: 'uses supplied AST',
options: {
resolveId: function ( importee, importer ) {
if ( !importer ) return 'main';
return importee;
},
load: function ( id ) {
if ( id === 'bar' ) {
throw new Error( 'loaded incorrect module' );
}
plugins: [{
resolveId: function ( importee, importer ) {
if ( !importer ) return 'main';
return importee;
},
load: function ( id ) {
if ( id === 'bar' ) {
throw new Error( 'loaded incorrect module' );
}
return modules[ id ];
}
return modules[ id ];
}
}]
}
};

Loading…
Cancel
Save