@interaktiv/dia-scripts
Version:
CLI toolbox with common scripts for most sort of projects at DIA
63 lines (57 loc) • 1.9 kB
JavaScript
;
var _serializers = require("../__tests__/helpers/serializers");
expect.addSnapshotSerializer(_serializers.unquoteSerializer);
expect.addSnapshotSerializer(_serializers.winPathSerializer);
let originalArgv = process.argv;
let originalExit = process.exit;
let crossSpawnSyncMock;
describe('lint commit-msg', () => {
beforeEach(() => {
({
sync: crossSpawnSyncMock
} = require('cross-spawn'));
originalArgv = process.argv;
originalExit = process.exit;
process.exit = jest.fn();
});
afterEach(() => {
process.exit = originalExit;
process.argv = originalArgv;
jest.resetModules();
});
test.each`
title | params
${'calls commitlint CLI with default args'} | ${{}}
${'does not use built-in config with --config'} | ${{
args: ['--config', './custom-commitlint.js']
}}
${'does not use built-in config with commitlint.config.js file'} | ${{
hasFile: filename => filename === 'commitlint.config.js'
}}
${'does not use built-in config with .commitlintrc.js file'} | ${{
hasFile: filename => filename === '.commitlintrc.js'
}}
`('$title', ({
params = {}
}) => {
const utils = require('../../utils');
const {
args = [],
hasPkgProp = () => false,
hasFile = () => false
} = params; // Before each
Object.assign(utils, {
hasPkgProp,
hasFile,
resolveBin: (modName, {
executable = modName
} = {}) => executable
});
process.argv = ['node', '../../lint/commit-msg', ...args];
require('./commit-msg');
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1);
const [firstCall] = crossSpawnSyncMock.mock.calls;
const [script, calledArgs] = firstCall;
expect([script, ...calledArgs].join(' ')).toMatchSnapshot();
});
});