timpla
Version:
An optimal website development experience for [server-side] web frameworks.
47 lines (42 loc) • 1.64 kB
text/typescript
const mockRename = jest.fn()
const mockSvgStore = jest.fn()
jest.mock('../../gulpfile.ts/internal')
jest.mock('gulp')
jest.mock('gulp-rename', () => mockRename)
jest.mock('gulp-svgstore', () => mockSvgStore)
jest.mock('browser-sync')
const cb = jest.fn()
import * as browserSync from 'browser-sync'
import * as gulp from 'gulp'
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 { svg as svgTask } from '../../gulpfile.ts/tasks/svg'
import { clone } from '../helpers'
describe('svgTask', () => {
it('should correctly pipe assets', () => {
const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
if (!conf.svg) {
return
}
const svg = svgTask(conf)
const spyProjectSrcPath = jest.spyOn(internal, 'projectSrcPath')
const spyProjectDestPath = jest.spyOn(internal, 'projectDestPath')
const spyBrowserSync = jest.spyOn(browserSync, 'stream')
const spyGulpDest = jest.spyOn(gulp, 'dest')
svg(cb)
expect(spyProjectSrcPath).toHaveBeenCalledWith(conf.svg.src, '*.svg')
expect(spyProjectDestPath).toHaveBeenCalledWith(conf.svg.dest)
expect(mockRename).toHaveBeenCalled()
expect(mockSvgStore).toHaveBeenCalled()
expect(spyBrowserSync).toHaveBeenCalled()
expect(spyGulpDest).toHaveBeenCalled()
})
it('should call the gulp cb if the task is disabled', () => {
const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
conf.svg = false
const svg = svgTask(conf)
svg(cb)
expect(cb).toHaveBeenCalled()
})
})