@@ -6,7 +6,7 @@ const getBlueprintNameOverride = require('../../src/get-default-blueprint-name-o
66const sinon = require ( 'sinon' ) ;
77const path = require ( 'path' ) ;
88const fs = require ( 'fs-extra' ) ;
9- const npm = require ( 'boilerplate-update/src/npm ' ) ;
9+ const pacote = require ( 'pacote ' ) ;
1010
1111const cwd = 'a/made/up/path' ;
1212const packageNameOrPath = '../a-package-name' ;
@@ -16,12 +16,12 @@ const localPackageJsonPath = path.join(path.resolve(cwd, packageNameOrPath), 'pa
1616describe ( getBlueprintNameOverride , function ( ) {
1717 let pathExistsStub ;
1818 let readFileStub ;
19- let jsonStub ;
19+ let manifestStub ;
2020
2121 beforeEach ( function ( ) {
2222 pathExistsStub = sinon . stub ( fs , 'pathExists' ) ;
2323 readFileStub = sinon . stub ( fs , 'readFile' ) ;
24- jsonStub = sinon . stub ( npm , 'json ' ) ;
24+ manifestStub = sinon . stub ( pacote , 'manifest ' ) ;
2525 } ) ;
2626
2727 afterEach ( function ( ) {
@@ -43,7 +43,7 @@ describe(getBlueprintNameOverride, function() {
4343 expect ( defaultBlueprintOverride ) . to . equal ( defaultBlueprint ) ;
4444 } ) ;
4545
46- it ( 'doesn\'t use npm if found locally' , async function ( ) {
46+ it ( 'doesn\'t use NPM if found locally' , async function ( ) {
4747 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( true ) ;
4848
4949 readFileStub . withArgs ( localPackageJsonPath ) . resolves ( JSON . stringify ( {
@@ -55,13 +55,13 @@ describe(getBlueprintNameOverride, function() {
5555
5656 await getBlueprintNameOverride ( packageNameOrPath , cwd ) ;
5757
58- expect ( jsonStub ) . to . not . have . been . called ;
58+ expect ( manifestStub ) . to . not . have . been . called ;
5959 } ) ;
6060
61- it ( 'uses npm if not found locally' , async function ( ) {
61+ it ( 'uses NPM if not found locally' , async function ( ) {
6262 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( false ) ;
6363
64- jsonStub . withArgs ( 'view' , packageNameOrPath ) . resolves ( {
64+ manifestStub . withArgs ( packageNameOrPath ) . resolves ( {
6565 name : packageNameOrPath ,
6666 'ember-addon' : {
6767 defaultBlueprint
@@ -73,10 +73,10 @@ describe(getBlueprintNameOverride, function() {
7373 expect ( defaultBlueprintOverride ) . to . equal ( defaultBlueprint ) ;
7474 } ) ;
7575
76- it ( 'doesn\'t read local file if using npm ' , async function ( ) {
76+ it ( 'doesn\'t read local file if using NPM ' , async function ( ) {
7777 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( false ) ;
7878
79- jsonStub . withArgs ( 'view' , packageNameOrPath ) . resolves ( {
79+ manifestStub . withArgs ( packageNameOrPath ) . resolves ( {
8080 name : packageNameOrPath ,
8181 'ember-addon' : {
8282 defaultBlueprint
@@ -88,7 +88,7 @@ describe(getBlueprintNameOverride, function() {
8888 expect ( readFileStub ) . to . not . have . been . called ;
8989 } ) ;
9090
91- it ( 'Null if ember-addon does not exist in package.json' , async function ( ) {
91+ it ( 'null if ember-addon does not exist in package.json' , async function ( ) {
9292 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( true ) ;
9393
9494 readFileStub . withArgs ( localPackageJsonPath ) . resolves ( JSON . stringify ( {
@@ -100,7 +100,7 @@ describe(getBlueprintNameOverride, function() {
100100 expect ( defaultBlueprintOverride ) . to . be . null ;
101101 } ) ;
102102
103- it ( 'Null if defaultBlueprint does not exist in ember-addon' , async function ( ) {
103+ it ( 'null if defaultBlueprint does not exist in ember-addon' , async function ( ) {
104104 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( true ) ;
105105
106106 readFileStub . withArgs ( localPackageJsonPath ) . resolves ( JSON . stringify ( {
@@ -113,13 +113,31 @@ describe(getBlueprintNameOverride, function() {
113113 expect ( defaultBlueprintOverride ) . to . be . null ;
114114 } ) ;
115115
116- it ( 'Error in spawn returns null' , async function ( ) {
116+ it ( 'missing NPM package returns null' , async function ( ) {
117117 pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( false ) ;
118118
119- jsonStub . withArgs ( 'view' , packageNameOrPath ) . rejects ( ) ;
119+ manifestStub . withArgs ( packageNameOrPath ) . rejects ( {
120+ statusCode : 404
121+ } ) ;
120122
121123 let defaultBlueprintOverride = await getBlueprintNameOverride ( packageNameOrPath , cwd ) ;
122124
123125 expect ( defaultBlueprintOverride ) . to . be . null ;
124126 } ) ;
127+
128+ it ( 'doesn\'t swallow all NPM errors' , async function ( ) {
129+ pathExistsStub . withArgs ( localPackageJsonPath ) . resolves ( false ) ;
130+
131+ let err = {
132+ statusCode : 123
133+ } ;
134+
135+ manifestStub . withArgs ( packageNameOrPath ) . rejects ( {
136+ statusCode : 123
137+ } ) ;
138+
139+ let promise = getBlueprintNameOverride ( packageNameOrPath , cwd ) ;
140+
141+ await expect ( promise ) . to . eventually . be . rejectedWith ( err ) ;
142+ } ) ;
125143} ) ;
0 commit comments