UNPKG

@interaktiv/dia-scripts

Version:

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

97 lines (90 loc) 3.19 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _yargsParser = _interopRequireDefault(require("yargs-parser")); var _serializers = require("../__tests__/helpers/serializers"); expect.addSnapshotSerializer(_serializers.unquoteSerializer); expect.addSnapshotSerializer(_serializers.winPathSerializer); const originalExit = process.exit; const originalArgv = process.argv; const originalLog = console.log; const originalInfo = console.info; let execaMock; describe('runDeploy', () => { 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(); }); it.each` title | params ${'calls sfdx CLI with args'} | ${{ args: ['force-app/**/lwc/*.js', '--json'] }} ${'should deploy default package.xml with --package argument'} | ${{ args: ['--package'] }} ${'should use a custom package.xml file with --manifest argument'} | ${{ args: ['--manifest', 'my-manifest/custom-package.xml'] }} ${'should use a custom log level with --loglevel argument'} | ${{ args: ['--loglevel', 'debug'] }} ${'should deploy Apex classes with --apex argument'} | ${{ args: ['--apex'] }} ${'should deploy Aura Bundles with --aura argument'} | ${{ args: ['--aura'] }} ${'should deploy Static Resources with --static argument'} | ${{ args: ['--static'] }} ${'should deploy Lightning Component Bundles with --lwc argument'} | ${{ args: ['--lwc'] }} ${'should call onComplete handler if passed to'} | ${{ args: ['--aura'], onComplete: jest.fn() }} ${'should not pass --watch param'} | ${{ args: ['--watch'] }} `('$title', async ({ params }) => { const { args = [], onComplete } = params; process.argv = ['node', './runDeploy', ...args]; const rawArgv = process.argv.slice(2); const argv = (0, _yargsParser.default)(rawArgv); const { runDeploy, ALLOWED_PARAMS } = require('./runDeploy'); await runDeploy({ argv, onComplete }); if (typeof onComplete === 'function') expect(onComplete).toBeCalledWith(expect.any(Object)); expect(execaMock).toHaveBeenCalledTimes(1); const [firstCall] = execaMock.mock.calls; const [script, calledArgs] = firstCall; expect(calledArgs).toEqual(expect.not.arrayContaining([ALLOWED_PARAMS.map(p => `--${p}`)])); expect([script, ...calledArgs].join(' ')).toMatchSnapshot(); }); });