@@ -7,6 +7,7 @@ import * as auth from '../src/authutil';
7
7
import * as cacheUtils from '../src/cache-utils' ;
8
8
9
9
let rcFile : string ;
10
+ let pkgJson : string ;
10
11
11
12
describe ( 'authutil tests' , ( ) => {
12
13
const _runnerDir = path . join ( __dirname , 'runner' ) ;
@@ -25,10 +26,12 @@ describe('authutil tests', () => {
25
26
process . env [ 'GITHUB_REPOSITORY' ] = 'OwnerName/repo' ;
26
27
process . env [ 'RUNNER_TEMP' ] = tempDir ;
27
28
rcFile = path . join ( tempDir , '.npmrc' ) ;
29
+ pkgJson = path . join ( tempDir , 'package.json' ) ;
28
30
} , 100000 ) ;
29
31
30
32
beforeEach ( async ( ) => {
31
33
await io . rmRF ( rcFile ) ;
34
+ await io . rmRF ( pkgJson ) ;
32
35
// if (fs.existsSync(rcFile)) {
33
36
// fs.unlinkSync(rcFile);
34
37
// }
@@ -113,6 +116,15 @@ describe('authutil tests', () => {
113
116
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
114
117
} ) ;
115
118
119
+ it ( 'Automatically configures npm scope from package.json' , async ( ) => {
120
+ process . env [ 'INPUT_SCOPE' ] = '' ;
121
+ fs . writeFileSync ( pkgJson , '{"name":"@myscope/mypackage"}' ) ;
122
+ await auth . configAuthentication ( 'https://registry.npmjs.org' , '' ) ;
123
+
124
+ const rc = readRcFile ( rcFile ) ;
125
+ expect ( rc [ '@myscope:registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
126
+ } ) ;
127
+
116
128
it ( 'Sets up npmrc for always-auth true' , async ( ) => {
117
129
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
118
130
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
0 commit comments