jest.mock('chalk')
jest.mock('../../gulpfile.ts/internal')
jest.mock('fs')
jest.mock('gulp')
jest.mock('os')
const cb = jest.fn()

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 { getTaskPathFor, watch as watchTask } from '../../gulpfile.ts/tasks/watch'
import { clone } from '../helpers'

describe('getTaskPathFor', () => {
  it('should return a stream', () => {
    const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
    const result = getTaskPathFor('svg', conf)
    expect(result).toMatchObject(conf.svg)
  })
})
describe('watch', () => {
  it('should watch all specified tasks', () => {
    const conf: IFullTimplaConfig = clone(TIMPLA_DEFAULTS)
    const spyGulpWatch = jest.spyOn(gulp, 'watch')
    const spyProjectSrcPath = jest.spyOn(internal, 'projectSrcPath')
    spyProjectSrcPath.mockImplementation((n: any) => n)
    const watch = watchTask(conf, {
      fonts: 'fonts',
      html: 'html',
      images: 'images',
      staticFiles: 'staticFiles',
      stylesheets: 'stylesheets',
      svg: 'svg',
    })
    watch(cb)
    const taskWatchers = spyGulpWatch.mock.calls

    expect(taskWatchers).toMatchInlineSnapshot(`
      Array [
        Array [
          "fonts/**/*.{woff2,woff,eot,ttf,svg}",
          Object {},
          "fonts",
        ],
        Array [
          "html/**/*",
          Object {},
          "html",
        ],
        Array [
          "images/**/*.{jpg,jpeg,png,svg,gif,webp}",
          Object {},
          "images",
        ],
        Array [
          "static/**/*",
          Object {},
          "staticFiles",
        ],
        Array [
          "stylesheets/**/*.{sass,scss,css}",
          Object {},
          "stylesheets",
        ],
        Array [
          "svg/**/*",
          Object {},
          "svg",
        ],
      ]
    `)
  })
})
