UNPKG

@interaktiv/dia-scripts

Version:

CLI toolbox with common scripts for most sort of projects at DIA

71 lines (65 loc) 2.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _serializers = require("../__tests__/helpers/serializers"); expect.addSnapshotSerializer(_serializers.unquoteSerializer); expect.addSnapshotSerializer(_serializers.winPathSerializer); jest.mock('chokidar', () => ({ watch: jest.fn(() => ({ on: jest.fn(function () { return this; }), close: jest.fn(function () { return this; }) })) })); const originalExit = process.exit; const originalArgv = process.argv; const originalLog = console.log; const originalInfo = console.info; let execaMock; describe('run deploy', () => { beforeEach(() => { process.exit = jest.fn(); console.log = jest.fn(); console.info = jest.fn(); execaMock = require('execa'); jest.mock('../../utils', () => (0, _extends2.default)({}, jest.requireActual('../../utils'), { resolveBin: jest.fn((modName, { executable = modName } = {}) => executable) })); }); afterEach(() => { process.exit = originalExit; process.argv = originalArgv; console.log = originalLog; console.info = originalInfo; jest.resetModules(); jest.restoreAllMocks(); }); it('should run only once by default', async () => { process.argv = ['node', '../deploy', ...[]]; await require('.'); expect(execaMock).toHaveBeenCalledTimes(1); const [firstCall] = execaMock.mock.calls; const [script, calledArgs] = firstCall; expect([script, ...calledArgs].join(' ')).toMatchSnapshot(); }); describe('with --watch argument', () => { it('should start watching', async () => { process.argv = ['node', '../deploy', ...['--watch']]; await require('.'); expect(require('chokidar').watch).toHaveBeenCalledWith(expect.anything(), expect.any(Object)); }); it('should start watching in custom source dir with --source-dir argument', () => { const sourceDir = '/blah/my/source/dir'; process.argv = ['node', '../deploy', ...['--watch', '--source-dir', sourceDir]]; require('.'); expect(require('chokidar').watch).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ cwd: sourceDir })); }); }); });