timpla
Version:
An optimal website development experience for [server-side] web frameworks.
109 lines (101 loc) • 3.02 kB
text/typescript
jest.mock('../../gulpfile.ts/internal')
const mockReplace = jest.fn()
jest.mock('gulp-replace', () => mockReplace)
jest.mock('gulp')
jest.mock('fancy-log')
jest.mock('chalk')
const mockMerge = jest.fn()
jest.mock('merge-stream', () => mockMerge)
const cb = jest.fn()
import * as gulp from 'gulp'
import * as internal from '../../gulpfile.ts/internal'
import { init } from '../../gulpfile.ts/tasks/init'
const spyGulpSrc = jest.spyOn(gulp, 'src')
const spyGulpDest = jest.spyOn(gulp, 'dest')
const spyProjectPath = jest.spyOn(internal, 'projectPath')
const spyProjectSrcPath = jest.spyOn(internal, 'projectSrcPath')
describe('initTask', () => {
it('should copy typescript configs', () => {
const config = init()
spyProjectPath.mockReturnValueOnce('projectPath')
spyProjectSrcPath.mockReturnValueOnce('projectSrcPath')
config(cb)
expect(spyGulpSrc.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
".eslintrc",
".prettierrc",
"babel.config.js",
"tslint.json",
"tsconfig.json",
],
],
Array [
Array [
"src/**/*",
"src/**/.gitkeep",
],
],
Array [
".timplaconfig.js",
],
]
`)
expect(spyGulpDest.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"projectPath",
],
Array [
"projectSrcPath",
],
Array [
"projectPath",
],
]
`)
expect(mockReplace).toHaveBeenCalledWith('./lib/public', 'timpla')
})
it('should copy js configs when init is set to false', () => {
const config = init(false)
spyProjectPath.mockReturnValueOnce('projectPath')
spyProjectSrcPath.mockReturnValueOnce('projectSrcPath')
config(cb)
expect(spyGulpSrc.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
".eslintrc",
".prettierrc",
"init_templates/js/babel.config.js",
],
],
Array [
Array [
"src/**/*",
"src/**/.gitkeep",
"init_templates/js/src/**/*",
"!**/*.ts{,?}*",
],
],
Array [
"init_templates/js/.timplaconfig.js",
],
]
`)
expect(spyGulpDest.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"projectPath",
],
Array [
"projectSrcPath",
],
Array [
"projectPath",
],
]
`)
})
})