@@ -330,15 +330,14 @@ describe('The PackageAnalyzer', () => {
330
330
331
331
describe ( 'analyze() reads package.json as package metadata -- "browser/module/main" fields analysis' , ( ) => {
332
332
let fsConfig ;
333
- let mockFileNames = [ 'index.js' , 'browser.js' , 'module.js' ] ;
334
- beforeEach ( function __setup__mock_package_json ( ) {
333
+ beforeEach ( function ( ) {
335
334
fsConfig = { } ;
336
- for ( const fileName of mockFileNames ) {
337
- fsConfig [ path . join ( 'node_modules/my-package' , fileName ) ] = 'some-content' ;
338
- } ;
335
+ fsConfig [ path . join ( 'node_modules/my-package' , 'index.js' ) ] = 'some-content' ;
336
+ fsConfig [ path . join ( 'node_modules/my-package' , 'browser.js' ) ] = 'some-content' ;
337
+ fsConfig [ path . join ( 'node_modules/my-package' , 'module.js' ) ] = 'some-content' ;
339
338
fsConfig [ project . paths . root ] = { } ;
340
339
} ) ;
341
-
340
+
342
341
it ( 'respects browser field over module/main' , done => {
343
342
fsConfig [ path . join ( 'node_modules/my-package' , 'package.json' ) ] = '{ "name": "my-package", "main": "index.js", "browser": "browser.js", "module": "module.js" }' ;
344
343
mockfs ( fsConfig ) ;
@@ -369,23 +368,40 @@ describe('The PackageAnalyzer', () => {
369
368
370
369
it ( 'respects "module" field over "main", but ignore module with "aurelia-"' , done => {
371
370
fsConfig [ path . join ( 'node_modules/my-package' , 'package.json' ) ] = '{ "name": "my-package", "main": "index.js", "module": "module.js"}' ;
372
- const aureliaPkg = 'aurelia-binding' ;
373
- for ( const fileName of mockFileNames ) {
374
- fsConfig [ path . join ( `node_modules/${ aureliaPkg } ` , fileName ) ] = 'export const content' ;
375
- }
376
- fsConfig [ path . join ( `node_modules/${ aureliaPkg } ` , 'package.json' ) ] = '"name": "aurelia-binding", "main": "index.js", "module": "module.js"' ;
377
371
378
- sut . analyze ( 'aurelia-binding' )
379
- . then ( description => {
380
- expect ( description . metadata . name ) . toBe ( 'aurelia-binding' ) ;
381
- expect ( description . loaderConfig . path ) . toBe ( `../node_modules/${ aureliaPkg } /index.js` ) ;
382
- expect ( description . loaderConfig . main ) . toBe ( 'main' ) ;
383
- done ( ) ;
384
- } )
372
+ fsConfig [ path . join ( 'node_modules/aurelia-binding' , 'index.js' ) ] = 'some-content' ;
373
+ fsConfig [ path . join ( 'node_modules/aurelia-binding' , 'browser.js' ) ] = 'some-content' ;
374
+ fsConfig [ path . join ( 'node_modules/aurelia-binding' , 'module.js' ) ] = 'some-content' ;
375
+ fsConfig [ path . join ( 'node_modules/aurelia-binding' , 'aurelia-binding.js' ) ] = 'export stuff' ;
376
+ fsConfig [ path . join ( 'node_modules/aurelia-binding' , 'package.json' ) ] = '{ "name": "aurelia-binding", "main": "aurelia-binding.js", "module": "module.js" }' ;
377
+
378
+ fsConfig [ path . join ( 'node_modules/aurelia_binding' , 'index.js' ) ] = 'some-content' ;
379
+ fsConfig [ path . join ( 'node_modules/aurelia_binding' , 'browser.js' ) ] = 'some-content' ;
380
+ fsConfig [ path . join ( 'node_modules/aurelia_binding' , 'module.js' ) ] = 'some-content' ;
381
+ fsConfig [ path . join ( 'node_modules/aurelia_binding' , 'aurelia-binding.js' ) ] = 'export stuff' ;
382
+ fsConfig [ path . join ( 'node_modules/aurelia_binding' , 'package.json' ) ] = '{ "name": "aurelia_binding", "main": "aurelia-binding.js", "module": "module.js" }' ;
383
+ mockfs ( fsConfig ) ;
384
+
385
+ Promise
386
+ . all ( [
387
+ sut . analyze ( 'aurelia-binding' )
388
+ . then ( description => {
389
+ expect ( description . metadata . name ) . toBe ( 'aurelia-binding' ) ;
390
+ expect ( description . loaderConfig . path ) . toBe ( '../node_modules/aurelia-binding' ) ;
391
+ expect ( description . loaderConfig . main ) . toBe ( 'aurelia-binding' ) ;
392
+ } ) ,
393
+ sut . analyze ( 'aurelia_binding' )
394
+ . then ( description => {
395
+ expect ( description . metadata . name ) . toBe ( 'aurelia_binding' ) ;
396
+ expect ( description . loaderConfig . path ) . toBe ( '../node_modules/aurelia_binding' ) ;
397
+ expect ( description . loaderConfig . main ) . toBe ( 'module' ) ;
398
+ } )
399
+ ] )
400
+ . then ( done )
401
+ . catch ( done . fail ) ;
385
402
} ) ;
386
403
} ) ;
387
404
388
-
389
405
it ( 'analyze() supports parent node_modules folder' , done => {
390
406
// setup mock package.json
391
407
const fsConfig = { } ;
0 commit comments