UNPKG

timpla

Version:

An optimal website development experience for [server-side] web frameworks.

38 lines (35 loc) 1.37 kB
jest.mock('../../gulpfile.ts/internal') jest.mock('gulp') jest.mock('child_process', () => ({ spawn: jest.fn(), })) jest.mock('fs', () => ({ existsSync: jest.fn().mockReturnValue(true), })) const cb = jest.fn() import * as childProcess from 'child_process' import * as internal from '../../gulpfile.ts/internal' import { TIMPLA_DEFAULTS } from '../../gulpfile.ts/lib/TIMPLA_DEFAULTS' import { IFullTimplaConfig } from '../../gulpfile.ts/lib/TIMPLA_INTERFACES' import { openAnalyzer as openAnalyzerTask } from '../../gulpfile.ts/tasks/openAnalyzer' import { clone } from '../helpers' describe('openAnalyzerTask', () => { it('should correctly pipe assets', () => { const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS) const spySpawn = jest.spyOn(childProcess, 'spawn') const spyDestPath = jest.spyOn(internal, 'projectDestPath') spyDestPath.mockReturnValue('file') const openAnalyzer = openAnalyzerTask(conf) openAnalyzer(cb) expect(spySpawn).toHaveBeenCalledWith('npx', ['webpack-bundle-analyzer', 'file'], { stdio: 'inherit', }) }) it('should call the gulp cb if the task is disabled', () => { const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS) conf.javascripts.webpackBundleAnalyzerOptions = false const openAnalyzer = openAnalyzerTask(conf) openAnalyzer(cb) expect(cb).toHaveBeenCalled() }) })