-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish): Publish command uses publishConfig.access in package.j…
…son (#5290) * feat(publish): Publish command uses publishConfig.access in package.json For npm compatability, `yarn publish` should check `publishConfig.access` in package.json and use it as if the `--access` option was passed. #5279 * WIP: CI test failure debugging * WIP: CI test failure debugging * WIP: CI test failure debugging * fix CI errors by mocking npm password prompt * use jest expect().toBeCalledWith() for publish command tests
- Loading branch information
Showing
5 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* @flow */ | ||
|
||
import Registry from '../../src/registries/base-registry.js'; | ||
import type {RegistryRequestOptions} from '../../src/registries/base-registry.js'; | ||
|
||
export default class NpmRegistry extends Registry { | ||
request(pathname: string, opts?: RegistryRequestOptions = {}, packageName: ?string): Promise<*> { | ||
return new Promise(resolve => resolve()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* @flow */ | ||
|
||
import {run as buildRun} from './_helpers.js'; | ||
import {run as publish} from '../../src/cli/commands/publish.js'; | ||
import {ConsoleReporter} from '../../src/reporters/index.js'; | ||
|
||
const path = require('path'); | ||
|
||
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'publish'); | ||
|
||
const setupMocks = function(config) { | ||
// Mock actual network request so that no package is actually published. | ||
// $FlowFixMe | ||
config.registries.npm.request = jest.fn(); | ||
config.registries.npm.request.mockReturnValue( | ||
new Promise(resolve => { | ||
resolve({status: 200}); | ||
}), | ||
); | ||
|
||
// Mock the npm login name. Otherwise yarn will prompt for it and break CI. | ||
// $FlowFixMe | ||
config.registries.npm.getAuth = jest.fn(); | ||
config.registries.npm.getAuth.mockReturnValue('test'); | ||
}; | ||
|
||
const runPublish = buildRun.bind( | ||
null, | ||
ConsoleReporter, | ||
fixturesLoc, | ||
async (args, flags, config, reporter, lockfile, getStdout): Promise<string> => { | ||
setupMocks(config); | ||
await publish(config, reporter, flags, args); | ||
return getStdout(); | ||
}, | ||
); | ||
|
||
test.concurrent('publish should default access to undefined', () => { | ||
return runPublish([], {newVersion: '0.0.1'}, 'minimal', config => { | ||
expect(config.registries.npm.request).toBeCalledWith( | ||
expect.any(String), | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
access: undefined, | ||
}), | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should accept `--access restricted` argument', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'restricted'}, 'minimal', config => { | ||
expect(config.registries.npm.request).toBeCalledWith( | ||
expect.any(String), | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
access: 'restricted', | ||
}), | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should accept `--access public` argument', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'public'}, 'minimal', config => { | ||
expect(config.registries.npm.request).toBeCalledWith( | ||
expect.any(String), | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
access: 'public', | ||
}), | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should use publishConfig.access in package manifest', () => { | ||
return runPublish([], {newVersion: '0.0.1'}, 'public', config => { | ||
expect(config.registries.npm.request).toBeCalledWith( | ||
expect.any(String), | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
access: 'public', | ||
}), | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should allow `--access` to override publishConfig.access', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'restricted'}, 'public', config => { | ||
expect(config.registries.npm.request).toBeCalledWith( | ||
expect.any(String), | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
access: 'restricted', | ||
}), | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"version": "0.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "test", | ||
"version": "0.0.0", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters