@interaktiv/dia-scripts
Version:
CLI toolbox with common scripts for most sort of projects at DIA
140 lines (123 loc) • 4.42 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
function getConfigFor(plugins) {
return plugin => {
const pluginDefinition = plugins.map(p => Array.isArray(p) ? p : [p, {}]).find(([pluginName]) => pluginName.includes(plugin));
return pluginDefinition ? pluginDefinition[1] : {};
};
}
describe('release config', () => {
describe('in private package', () => {
beforeAll(() => {
jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), {
pkg: {
private: true
}
}));
});
it('should not publish to npm', () => {
const {
plugins
} = require('./releaserc');
const npmConfig = getConfigFor(plugins)('npm');
expect(npmConfig.npmPublish).toBe(false);
});
});
describe('in non node project', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), {
pkg: {
private: undefined
}
}));
});
it('should not publish to npm in a Salesforce DX project', () => {
const utils = require('../utils');
utils.isSfdxProject = jest.fn();
utils.isSfdxProject.mockReturnValueOnce(true);
const {
plugins
} = require('./releaserc');
const npmConfig = getConfigFor(plugins)('npm');
expect(npmConfig.npmPublish).toBe(false);
});
it('should not publish to npm in a Mobile project', () => {
const utils = require('../utils');
utils.isMobileProject = jest.fn();
utils.isMobileProject.mockReturnValueOnce(true);
const {
plugins
} = require('./releaserc');
const npmConfig = getConfigFor(plugins)('npm');
expect(npmConfig.npmPublish).toBe(false);
});
it('should not publish to npm in a Commerce project', () => {
const utils = require('../utils');
utils.isCommerceProject = jest.fn();
utils.isCommerceProject.mockReturnValueOnce(true);
const {
plugins
} = require('./releaserc');
const npmConfig = getConfigFor(plugins)('npm');
expect(npmConfig.npmPublish).toBe(false);
});
});
describe('hosted in a Bitbucket repo', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), {
ifBitbucketRepo: jest.fn(t => t)
}));
});
it('should use custom `compareUrlFormat`, `pullRequestUrlFormat`, `jiraUrlFormat`', () => {
const {
plugins
} = require('./releaserc');
const releaseNotesGeneratorConfig = getConfigFor(plugins)('release-notes-generator');
expect(releaseNotesGeneratorConfig.writerOpts).toEqual(expect.objectContaining({
compareUrlFormat: expect.any(String),
jiraUrlFormat: expect.any(String),
pullRequestUrlFormat: expect.any(String)
}));
});
});
describe('hosted in a non Bitbucket repo', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), {
ifBitbucketRepo: jest.fn((_t, f) => f)
}));
});
it('should not use custom config properties', () => {
const {
plugins
} = require('./releaserc');
const releaseNotesGeneratorConfig = getConfigFor(plugins)('release-notes-generator');
expect(releaseNotesGeneratorConfig.writerOpts).toEqual(expect.objectContaining({
compareUrlFormat: undefined,
jiraUrlFormat: undefined,
pullRequestUrlFormat: undefined
}));
});
});
describe('if opted out of changelog generation', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('../utils', () => (0, _extends2.default)({}, jest.requireActual('../utils'), {
ifBitbucketRepo: jest.fn((_t, f) => f),
isOptedOut: jest.fn((optOut, t, f) => optOut === 'changelog' ? t : f)
}));
});
afterEach(() => {
jest.resetModules();
});
it('should not include changelog config', () => {
const {
plugins
} = require('./releaserc');
expect(plugins).toEqual(expect.not.arrayContaining(['@semantic-release/changelog']));
});
});
});