-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(publish): Publish command uses publishConfig.access in package.json #5290
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd2a51c
feat(publish): Publish command uses publishConfig.access in package.json
rally25rs ba01ae4
WIP: CI test failure debugging
rally25rs 2006898
WIP: CI test failure debugging
rally25rs 0efb23f
WIP: CI test failure debugging
rally25rs c0b644e
fix CI errors by mocking npm password prompt
rally25rs f29e235
use jest expect().toBeCalledWith() for publish command tests
rally25rs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,71 @@ | ||
/* @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 => { | ||
const requestCallParams = config.registries.npm.request.mock.calls[0][1]; | ||
expect(requestCallParams.body.access).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should accept `--access restricted` argument', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'restricted'}, 'minimal', config => { | ||
const requestCallParams = config.registries.npm.request.mock.calls[0][1]; | ||
expect(requestCallParams.body.access).toEqual('restricted'); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should accept `--access public` argument', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'public'}, 'minimal', config => { | ||
const requestCallParams = config.registries.npm.request.mock.calls[0][1]; | ||
expect(requestCallParams.body.access).toEqual('public'); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should use publishConfig.access in package manifest', () => { | ||
return runPublish([], {newVersion: '0.0.1'}, 'public', config => { | ||
const requestCallParams = config.registries.npm.request.mock.calls[0][1]; | ||
expect(requestCallParams.body.access).toEqual('public'); | ||
}); | ||
}); | ||
|
||
test.concurrent('publish should allow `--access` to override publishConfig.access', () => { | ||
return runPublish([], {newVersion: '0.0.1', access: 'restricted'}, 'public', config => { | ||
const requestCallParams = config.registries.npm.request.mock.calls[0][1]; | ||
expect(requestCallParams.body.access).toEqual('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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it more readable to use
toBeCalledWith
rather than reaching into the mock objectsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if there was a way to do that and only specify the parameter that I care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or rather, the 2nd parameter is an object with a bunch of properties but I'm realy only testing 1 of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems I had to nest a couple
expect.objectContaining()
calls, but I cleaned it up (or made it longer and more nested, depending on your point of view 😄 )