@@ -6,6 +6,7 @@ import makeTemp from './_temp.js';
66import * as fs from '../src/util/fs.js' ;
77import * as misc from '../src/util/misc.js' ;
88import * as constants from '../src/constants.js' ;
9+ import { explodeLockfile } from './commands/_helpers.js' ;
910
1011jasmine . DEFAULT_TIMEOUT_INTERVAL = 120000 ;
1112
@@ -153,6 +154,54 @@ test('--mutex network', async () => {
153154 await Promise . all ( promises ) ;
154155} ) ;
155156
157+ describe ( '--registry option' , ( ) => {
158+ test ( '--registry option with npm registry' , async ( ) => {
159+ const cwd = await makeTemp ( ) ;
160+
161+ const registry = 'https://registry.npmjs.org' ;
162+ const packageJsonPath = path . join ( cwd , 'package.json' ) ;
163+ await fs . writeFile ( packageJsonPath , JSON . stringify ( { } ) ) ;
164+
165+ await runYarn ( [ 'add' , 'left-pad' , '--registry' , registry ] , { cwd} ) ;
166+
167+ const packageJson = JSON . parse ( await fs . readFile ( packageJsonPath ) ) ;
168+ const lockfile = explodeLockfile ( await fs . readFile ( path . join ( cwd , 'yarn.lock' ) ) ) ;
169+
170+ expect ( packageJson . dependencies [ 'left-pad' ] ) . toBeDefined ( ) ;
171+ expect ( lockfile ) . toHaveLength ( 3 ) ;
172+ expect ( lockfile [ 2 ] ) . toContain ( registry ) ;
173+ } ) ;
174+
175+ test ( '--registry option with yarn registry' , async ( ) => {
176+ const cwd = await makeTemp ( ) ;
177+
178+ const registry = 'https://registry.yarnpkg.com' ;
179+ const packageJsonPath = path . join ( cwd , 'package.json' ) ;
180+ await fs . writeFile ( packageJsonPath , JSON . stringify ( { } ) ) ;
181+
182+ await runYarn ( [ 'add' , 'is-array' , '--registry' , registry ] , { cwd} ) ;
183+
184+ const packageJson = JSON . parse ( await fs . readFile ( packageJsonPath ) ) ;
185+ const lockfile = explodeLockfile ( await fs . readFile ( path . join ( cwd , 'yarn.lock' ) ) ) ;
186+
187+ expect ( packageJson . dependencies [ 'is-array' ] ) . toBeDefined ( ) ;
188+ expect ( lockfile ) . toHaveLength ( 3 ) ;
189+ expect ( lockfile [ 2 ] ) . toContain ( registry ) ;
190+ } ) ;
191+
192+ test ( '--registry option with non-exiting registry and show an error' , async ( ) => {
193+ const cwd = await makeTemp ( ) ;
194+ const registry = 'https://example-registry-doesnt-exist.com' ;
195+
196+ try {
197+ await runYarn ( [ 'add' , 'is-array' , '--registry' , registry ] , { cwd} ) ;
198+ } catch ( err ) {
199+ const stdoutOutput = err . message ;
200+ expect ( stdoutOutput . toString ( ) ) . toMatch ( / g e t a d d r i n f o E N O T F O U N D e x a m p l e - r e g i s t r y - d o e s n t - e x i s t \. c o m / g) ;
201+ }
202+ } ) ;
203+ } ) ;
204+
156205test ( '--cwd option' , async ( ) => {
157206 const cwd = await makeTemp ( ) ;
158207
0 commit comments