jmd-scripts
Version:
CLI for common scripts for my projects
47 lines (35 loc) • 2.33 kB
JavaScript
;
var utilsMock = _interopRequireWildcard(require("../../utils"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
jest.mock('../../utils', () => _objectSpread({}, require.requireActual('../../utils'), {
isOptedOut: jest.fn((key, t) => t)
}));
afterEach(() => {
jest.resetModules();
});
test('includes format and git add when not opted out', () => {
utilsMock.isOptedOut.mockImplementation((key, t, f) => f);
const config = require('../lintstagedrc');
const jsLinter = getJsLinter(config.linters);
expect(hasFormat(jsLinter)).toBe(true);
expect(hasGitAdd(jsLinter)).toBe(true);
});
test('does not include format and git add when opted out', () => {
utilsMock.isOptedOut.mockImplementation((key, t) => t);
const config = require('../lintstagedrc');
const jsLinter = getJsLinter(config.linters);
expect(hasFormat(jsLinter)).toBe(false);
expect(hasGitAdd(jsLinter)).toBe(false);
});
function hasFormat(linter) {
return linter.some(l => l.includes('format'));
}
function hasGitAdd(linter) {
return linter.includes('git add');
}
function getJsLinter(linters) {
const key = Object.keys(linters).find(k => k.includes('**') && k.includes('js'));
return linters[key];
}