@interaktiv/dia-scripts
Version:
CLI toolbox with common scripts for most sort of projects at DIA
76 lines (70 loc) • 2.59 kB
JavaScript
;
var _serializers = require("../__tests__/helpers/serializers");
expect.addSnapshotSerializer(_serializers.unquoteSerializer);
expect.addSnapshotSerializer(_serializers.winPathSerializer);
expect.addSnapshotSerializer(_serializers.relativePathSerializer);
let originalArgv = process.argv;
let originalExit = process.exit;
let crossSpawnSyncMock;
describe('lint markdown', () => {
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 markdownlint CLI with default args'} | ${{}}
${'does not use built-in config with --config'} | ${{
args: ['--config', './custom-markdownlintrc.js']
}}
${'does not use built-in config with .markdownlintrc file'} | ${{
hasFile: filename => filename === '.markdownlintrc'
}}
${'does not use built-in config with .markdownlint.json file'} | ${{
hasFile: filename => filename === '.markdownlint.json'
}}
${'does not use built-in config with .markdownlint.yaml file'} | ${{
hasFile: filename => filename === '.markdownlint.yaml'
}}
${'does not use built-in config with .markdownlint.yml file'} | ${{
hasFile: filename => filename === '.markdownlint.yml'
}}
${'does not use built-in ignore with --ignore'} | ${{
args: ['--ignore', './my-ignored-file.md']
}}
${'runs on given files, but only md files'} | ${{
args: ['./src/index.js', './package.json', './others/TEST2.markdown', './src/index.css', 'CHANGELOG.md', './src/component.js', 'TEST.mdown', 'README.md']
}}
`('$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/markdown', ...args];
require('./markdown');
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1);
const [firstCall] = crossSpawnSyncMock.mock.calls;
const [script, calledArgs] = firstCall;
expect([script, ...calledArgs].join(' ')).toMatchSnapshot();
});
});