Skip to content

Commit

Permalink
linting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarmicki committed Nov 28, 2017
1 parent c63177c commit d03b86a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"plugins": [
"prettier"
],
"env": {
"jest": true
},
"rules": {
"prettier/prettier": ["error", { "trailingComma": "all", "singleQuote": true }],
"no-underscore-dangle": "off",
Expand Down
1 change: 1 addition & 0 deletions extensions/roc-plugin-repo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function fetchProjects(command) {
return command(invokeHook('get-projects'));
}

// eslint-disable-next-line import/no-unresolved
const jestOptions = require('jest-cli/build/cli/args').options;

Object.keys(jestOptions).forEach(key => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default function(options, context, gitRawCommitsOpts) {
const to = '84fe778a213bea560ca30bb8f085d8d6652eb455';
return conventionalChangelog(options, context, {
...gitRawCommitsOpts,
to
to,
});
}
3 changes: 2 additions & 1 deletion extensions/roc-plugin-repo/src/semver/__mocks__/roc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const executeSync = command => {
if(command.includes('commit-hash-some-directory')) {
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 };
164 changes: 102 additions & 62 deletions extensions/roc-plugin-repo/src/semver/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/first */
jest.mock('conventional-changelog');
jest.mock('roc');

Expand All @@ -7,21 +8,28 @@ import {
getNextVersions,
createVersionsDoesNotMatch,
getMultiScopes,
getAutoScopes
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']);
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');
Expand All @@ -31,15 +39,17 @@ describe('Semver utilities', () => {
describe('to generate Conventional Changelog options', () => {
it('should set correct scope when commit is a revert', done => {
const project = {
path: '/'
path: '/',
};
const isMonorepo = false;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
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'
scope: 'this should be changed',
};

options.transform(commit, () => {
Expand All @@ -50,13 +60,15 @@ describe('Semver utilities', () => {

it('should not make changes to a commit if we are not using monorepo', done => {
const project = {
path: '/'
path: '/',
};
const isMonorepo = false;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
const options = conventionalChangelogOptions('angular', isMonorepo, [])(
project,
);
const commit = {
type: 'release'
type: 'release',
};

options.transform(commit, () => {
Expand All @@ -70,15 +82,17 @@ describe('Semver utilities', () => {
const name = 'roc-plugin-hadron-collider';
const project = {
name,
path: '/'
path: '/',
};
const isMonorepo = true;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
const options = conventionalChangelogOptions('angular', isMonorepo, [])(
project,
);
const commit = {
type: 'release',
scope: name,
notes: []
notes: [],
};

options.transform(commit, () => {
Expand All @@ -91,15 +105,17 @@ describe('Semver utilities', () => {
const name = 'roc-plugin-hadron-collider';
const project = {
name,
path: '/'
path: '/',
};
const isMonorepo = true;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
const options = conventionalChangelogOptions('angular', isMonorepo, [])(
project,
);
const commit = {
type: 'release',
scope: name,
notes: []
notes: [],
};

options.transform(commit, () => {
Expand All @@ -111,15 +127,17 @@ describe('Semver utilities', () => {
it('when the scope affects all projects', done => {
const project = {
name: 'roc-plugin-hadron-collider',
path: '/'
path: '/',
};
const isMonorepo = true;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
const options = conventionalChangelogOptions('angular', isMonorepo, [])(
project,
);
const commit = {
type: 'release',
scope: 'all',
notes: []
notes: [],
};

options.transform(commit, () => {
Expand All @@ -132,18 +150,22 @@ describe('Semver utilities', () => {
const name = 'roc-plugin-hadron-collider';
const project = {
name,
path: '/'
path: '/',
};
const isMonorepo = true;

const options = conventionalChangelogOptions('angular', isMonorepo, [])(project);
const options = conventionalChangelogOptions('angular', isMonorepo, [])(
project,
);
const commit = {
type: 'multi',
scope: 'multi',
notes: [{
title: 'scopes',
text: `roc-plugin-skynet, ${name}`
}]
notes: [
{
title: 'scopes',
text: `roc-plugin-skynet, ${name}`,
},
],
};

options.transform(commit, () => {
Expand All @@ -162,21 +184,23 @@ describe('Semver utilities', () => {
const skynetVersion = '0.1.4';
const status = {
[hadron]: {
newVersion: hadronNewVersion
}
newVersion: hadronNewVersion,
},
};
const projects = [{
const projects = [
{
name: hadron,
packageJSON: {
version: '0.0.0'
}
version: '0.0.0',
},
},
{
name: skynet,
packageJSON: {
version: skynetVersion
}
}];
version: skynetVersion,
},
},
];

const projectsWithNextVersions = getNextVersions(status, projects);

Expand All @@ -190,25 +214,33 @@ describe('Semver utilities', () => {
const ignoreSemver = true;
const name = 'roc-plugin-hadron-collider';
const projectsWithVersions = {
[name]: {}
[name]: {},
};
const dependencies = {};

const versionsDoesNotMatch = createVersionsDoesNotMatch(projectsWithVersions, dependencies, ignoreSemver);
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]: {}
[name]: {},
};
const dependencies = {
[name]: 'latest'
[name]: 'latest',
};

const versionsDoesNotMatch = createVersionsDoesNotMatch(projectsWithVersions, dependencies, ignoreSemver);
const versionsDoesNotMatch = createVersionsDoesNotMatch(
projectsWithVersions,
dependencies,
ignoreSemver,
);
expect(versionsDoesNotMatch(name)).toBe(false);
});

Expand All @@ -217,14 +249,18 @@ describe('Semver utilities', () => {
const name = 'roc-plugin-hadron-collider';
const projectsWithVersions = {
[name]: {
version: '1.2.4'
}
version: '1.2.4',
},
};
const dependencies = {
[name]: '^2.0.0'
[name]: '^2.0.0',
};

const versionsDoesNotMatch = createVersionsDoesNotMatch(projectsWithVersions, dependencies, ignoreSemver);
const versionsDoesNotMatch = createVersionsDoesNotMatch(
projectsWithVersions,
dependencies,
ignoreSemver,
);
expect(versionsDoesNotMatch(name)).toBe(true);
});
});
Expand All @@ -237,9 +273,9 @@ describe('Semver utilities', () => {
notes: [
{
title: 'scopes',
text: 'I should not see that'
}
]
text: 'I should not see that',
},
],
};

expect(getMultiScopes(commit, isMonorepo)).toEqual([]);
Expand All @@ -253,9 +289,9 @@ describe('Semver utilities', () => {
notes: [
{
title: 'scopes',
text
}
]
text,
},
],
};

expect(getMultiScopes(commit, isMonorepo)).toEqual([text]);
Expand All @@ -266,7 +302,7 @@ describe('Semver utilities', () => {
it('should ignore non-monorepo commits', () => {
const isMonorepo = false;
const commit = {
scope: '*'
scope: '*',
};
const projects = [];

Expand All @@ -277,7 +313,7 @@ describe('Semver utilities', () => {
const isMonorepo = true;
const commit = {
hash: 'commit-hash-nothing',
scope: '*'
scope: '*',
};
const projects = [];

Expand All @@ -289,19 +325,23 @@ describe('Semver utilities', () => {
const hadron = 'roc-plugin-hadron-collider';
const commit = {
hash: 'commit-hash-some-directory',
scope: '*'
scope: '*',
};
const projects = [{
name: hadron,
directory: 'some-directory',
folder: 'some-folder'
}, {
name: 'roc-plugin-skynet',
directory: 'other-directory',
folder: 'other-folder'
}];
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 */

0 comments on commit d03b86a

Please sign in to comment.