UNPKG

timpla

Version:

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

62 lines (55 loc) 2.21 kB
jest.mock('../../gulpfile.ts/internal') jest.mock('gulp') jest.mock('browser-sync') const cb = jest.fn() jest.mock('autoprefixer') jest.mock('browser-sync') const mockPostCSS = jest.fn() jest.mock('gulp-postcss', () => mockPostCSS) jest.mock('gulp-if') jest.mock('gulp-postcss') const mockSass = jest.fn() jest.mock('gulp-sass', () => mockSass) jest.mock('gulp-sourcemaps', () => ({ init: jest.fn(), write: jest.fn(), })) import * as browserSync from 'browser-sync' import * as gulp from 'gulp' import * as sourcemaps from 'gulp-sourcemaps' 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 { stylesheets as stylesheetsTask } from '../../gulpfile.ts/tasks/stylesheets' import { clone } from '../helpers' describe('stylesheetsTask', () => { it('should correctly pipe assets', () => { const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS) if (!conf.stylesheets) { return } const stylesheets = stylesheetsTask(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') const spySourceMapsWrite = jest.spyOn(sourcemaps, 'write') const spySourceMapsInit = jest.spyOn(sourcemaps, 'init') stylesheets(cb) expect(spyProjectSrcPath).toHaveBeenCalledWith(conf.stylesheets.src, '**/*.{sass,scss,css}') expect(spyProjectDestPath).toHaveBeenCalledWith(conf.stylesheets.dest) expect(mockPostCSS).toHaveBeenCalled() expect(mockSass).toHaveBeenCalled() expect(spySourceMapsWrite).toHaveBeenCalled() expect(spySourceMapsInit).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.stylesheets = false const stylesheets = stylesheetsTask(conf) stylesheets(cb) expect(cb).toHaveBeenCalled() }) })