-
Notifications
You must be signed in to change notification settings - Fork 2
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
test(roc-plugin-repo): Add semver utilities tests #12
Open
kjarmicki
wants to merge
7
commits into
rocjs:master
Choose a base branch
from
kjarmicki:add-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c63177c
test(roc-plugin-repo): Add semver utilities tests
kjarmicki d03b86a
linting stuff
kjarmicki 78ff429
we need complete history before testing
kjarmicki d9febeb
remove unnecessary travis command
kjarmicki ace6c4e
sync with master
kjarmicki 344dc79
Revert "remove unnecessary travis command"
kjarmicki 7d516cb
describe need for unshallow fetch
kjarmicki 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
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ cache: | |
node_js: | ||
- 6.9 | ||
before_script: | ||
- git fetch --unshallow | ||
- npm start bootstrap |
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
10 changes: 10 additions & 0 deletions
10
extensions/roc-plugin-repo/src/semver/__mocks__/conventional-changelog.js
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 @@ | ||
const conventionalChangelog = require.requireActual('conventional-changelog'); | ||
|
||
export default function(options, context, gitRawCommitsOpts) { | ||
// lock down "to" commits to make results predictable | ||
const to = '84fe778a213bea560ca30bb8f085d8d6652eb455'; | ||
return conventionalChangelog(options, context, { | ||
...gitRawCommitsOpts, | ||
to, | ||
}); | ||
} |
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,9 @@ | ||
const executeSync = command => { | ||
if (command.includes('commit-hash-some-directory')) { | ||
return 'some-directory/some-folder/roc-plugin-hadron-collider'; | ||
} | ||
return ''; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { executeSync }; |
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,347 @@ | ||
/* eslint-disable import/first */ | ||
jest.mock('conventional-changelog'); | ||
jest.mock('roc'); | ||
|
||
import { | ||
getLatestCommitsSinceRelease, | ||
conventionalChangelogOptions, | ||
getNextVersions, | ||
createVersionsDoesNotMatch, | ||
getMultiScopes, | ||
getAutoScopes, | ||
} from './utils'; | ||
|
||
describe('Semver utilities', () => { | ||
describe('to get latest commits since release', () => { | ||
it('should return information for current monorepo', async () => { | ||
const projects = []; | ||
const from = ''; | ||
const isMonorepo = true; | ||
|
||
const result = await getLatestCommitsSinceRelease( | ||
'angular', | ||
from, | ||
projects, | ||
isMonorepo, | ||
); | ||
|
||
expect(Object.keys(result).sort()).toEqual([ | ||
'roc-plugin-repo', | ||
'roc-plugin-repo-react', | ||
'roc-plugin-repo-roc', | ||
]); | ||
expect(result['roc-plugin-repo'].release.subject).toBe('0.0.27'); | ||
expect(result['roc-plugin-repo-react'].release.subject).toBe('0.0.5'); | ||
expect(result['roc-plugin-repo-roc'].release.subject).toBe('0.0.1'); | ||
}); | ||
}); | ||
|
||
describe('to generate Conventional Changelog options', () => { | ||
it('should set correct scope when commit is a revert', done => { | ||
const project = { | ||
path: '/', | ||
}; | ||
const isMonorepo = false; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'revert', | ||
subject: "feat(@whole/world): Hey, what's the worst that could happen?", | ||
scope: 'this should be changed', | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit.scope).toBe('@whole/world'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not make changes to a commit if we are not using monorepo', done => { | ||
const project = { | ||
path: '/', | ||
}; | ||
const isMonorepo = false; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'release', | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit).toEqual(commit); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('should remove commit scope if we are using monorepo', () => { | ||
it('when the scope is the same as the project name', done => { | ||
const name = 'roc-plugin-hadron-collider'; | ||
const project = { | ||
name, | ||
path: '/', | ||
}; | ||
const isMonorepo = true; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'release', | ||
scope: name, | ||
notes: [], | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit.scope).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('when the scope is the same as the project name', done => { | ||
const name = 'roc-plugin-hadron-collider'; | ||
const project = { | ||
name, | ||
path: '/', | ||
}; | ||
const isMonorepo = true; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'release', | ||
scope: name, | ||
notes: [], | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit.scope).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('when the scope affects all projects', done => { | ||
const project = { | ||
name: 'roc-plugin-hadron-collider', | ||
path: '/', | ||
}; | ||
const isMonorepo = true; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'release', | ||
scope: 'all', | ||
notes: [], | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit.scope).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('when project is included in a multi scope', done => { | ||
const name = 'roc-plugin-hadron-collider'; | ||
const project = { | ||
name, | ||
path: '/', | ||
}; | ||
const isMonorepo = true; | ||
|
||
const options = conventionalChangelogOptions('angular', isMonorepo, [])( | ||
project, | ||
); | ||
const commit = { | ||
type: 'multi', | ||
scope: 'multi', | ||
notes: [ | ||
{ | ||
title: 'scopes', | ||
text: `roc-plugin-skynet, ${name}`, | ||
}, | ||
], | ||
}; | ||
|
||
options.transform(commit, () => { | ||
expect(commit.scope).toBe(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('to get next versions', () => { | ||
it('should return correct next versions for projects', () => { | ||
const hadron = 'roc-plugin-hadron-collider'; | ||
const hadronNewVersion = '1.2.3'; | ||
const skynet = 'roc-plugin-skynet'; | ||
const skynetVersion = '0.1.4'; | ||
const status = { | ||
[hadron]: { | ||
newVersion: hadronNewVersion, | ||
}, | ||
}; | ||
const projects = [ | ||
{ | ||
name: hadron, | ||
packageJSON: { | ||
version: '0.0.0', | ||
}, | ||
}, | ||
{ | ||
name: skynet, | ||
packageJSON: { | ||
version: skynetVersion, | ||
}, | ||
}, | ||
]; | ||
|
||
const projectsWithNextVersions = getNextVersions(status, projects); | ||
|
||
expect(projectsWithNextVersions[hadron].version).toBe(hadronNewVersion); | ||
expect(projectsWithNextVersions[skynet].version).toBe(skynetVersion); | ||
}); | ||
}); | ||
|
||
describe('to match version numbers', () => { | ||
it('should match when semver is ignored', () => { | ||
const ignoreSemver = true; | ||
const name = 'roc-plugin-hadron-collider'; | ||
const projectsWithVersions = { | ||
[name]: {}, | ||
}; | ||
const dependencies = {}; | ||
|
||
const versionsDoesNotMatch = createVersionsDoesNotMatch( | ||
projectsWithVersions, | ||
dependencies, | ||
ignoreSemver, | ||
); | ||
expect(versionsDoesNotMatch(name)).toBe(false); | ||
}); | ||
|
||
it('should match when dependency is declared as latest', () => { | ||
const ignoreSemver = false; | ||
const name = 'roc-plugin-hadron-collider'; | ||
const projectsWithVersions = { | ||
[name]: {}, | ||
}; | ||
const dependencies = { | ||
[name]: 'latest', | ||
}; | ||
|
||
const versionsDoesNotMatch = createVersionsDoesNotMatch( | ||
projectsWithVersions, | ||
dependencies, | ||
ignoreSemver, | ||
); | ||
expect(versionsDoesNotMatch(name)).toBe(false); | ||
}); | ||
|
||
it('should not match when dependency satisfies semver range', () => { | ||
const ignoreSemver = false; | ||
const name = 'roc-plugin-hadron-collider'; | ||
const projectsWithVersions = { | ||
[name]: { | ||
version: '1.2.4', | ||
}, | ||
}; | ||
const dependencies = { | ||
[name]: '^2.0.0', | ||
}; | ||
|
||
const versionsDoesNotMatch = createVersionsDoesNotMatch( | ||
projectsWithVersions, | ||
dependencies, | ||
ignoreSemver, | ||
); | ||
expect(versionsDoesNotMatch(name)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('to get notes for multi scope commits', () => { | ||
it('should ignore non-monorepo commits', () => { | ||
const isMonorepo = false; | ||
const commit = { | ||
scope: 'multi', | ||
notes: [ | ||
{ | ||
title: 'scopes', | ||
text: 'I should not see that', | ||
}, | ||
], | ||
}; | ||
|
||
expect(getMultiScopes(commit, isMonorepo)).toEqual([]); | ||
}); | ||
|
||
it('should extract text from monorepo commits', () => { | ||
const isMonorepo = true; | ||
const text = 'I should see that'; | ||
const commit = { | ||
scope: 'multi', | ||
notes: [ | ||
{ | ||
title: 'scopes', | ||
text, | ||
}, | ||
], | ||
}; | ||
|
||
expect(getMultiScopes(commit, isMonorepo)).toEqual([text]); | ||
}); | ||
}); | ||
|
||
describe('to get notes from affected files', () => { | ||
it('should ignore non-monorepo commits', () => { | ||
const isMonorepo = false; | ||
const commit = { | ||
scope: '*', | ||
}; | ||
const projects = []; | ||
|
||
expect(getAutoScopes(commit, isMonorepo, projects)).toEqual([]); | ||
}); | ||
|
||
it('should ignore commits that did not affect any files', () => { | ||
const isMonorepo = true; | ||
const commit = { | ||
hash: 'commit-hash-nothing', | ||
scope: '*', | ||
}; | ||
const projects = []; | ||
|
||
expect(getAutoScopes(commit, isMonorepo, projects)).toEqual([]); | ||
}); | ||
|
||
it('should return scope of commits that did affect some files', () => { | ||
const isMonorepo = true; | ||
const hadron = 'roc-plugin-hadron-collider'; | ||
const commit = { | ||
hash: 'commit-hash-some-directory', | ||
scope: '*', | ||
}; | ||
const projects = [ | ||
{ | ||
name: hadron, | ||
directory: 'some-directory', | ||
folder: 'some-folder', | ||
}, | ||
{ | ||
name: 'roc-plugin-skynet', | ||
directory: 'other-directory', | ||
folder: 'other-folder', | ||
}, | ||
]; | ||
|
||
expect(getAutoScopes(commit, isMonorepo, projects)).toEqual([hadron]); | ||
}); | ||
}); | ||
}); | ||
/* eslint-enable import/first */ |
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.
We should not need this anymore after 21997dd was merged.
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.
We may still need it just for tests, the change was done in
generateStatus.js
and tests don't touch that file, so that path remains broken.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.
Ah, maybe it's still needed here then and given that the tests seems to fail now it kinda points to that.