|
| 1 | +import { AbstractCommand } from '../../../src/commands/abstract-command' |
| 2 | +import { Init } from '../../../src/commands/init' |
| 3 | +import * as fs from 'fs' |
| 4 | +import * as inquirer from 'inquirer' |
| 5 | +import * as fse from 'fs-extra' |
| 6 | +import * as path from 'path' |
| 7 | + |
| 8 | +jest.mock('inquirer') |
| 9 | +const mockedInquirer = inquirer as jest.Mocked<typeof inquirer> |
| 10 | + |
| 11 | +describe('Init command test', () => { |
| 12 | + let init: AbstractCommand |
| 13 | + const pathToProjectDir = './test/output/actual/test-project-name' |
| 14 | + const absoluteProcessDir = path.join(process.cwd(), pathToProjectDir) |
| 15 | + |
| 16 | + beforeAll(() => { |
| 17 | + init = new Init() |
| 18 | + }) |
| 19 | + |
| 20 | + afterEach(() => { |
| 21 | + if (fs.existsSync(absoluteProcessDir)) { |
| 22 | + fse.remove(absoluteProcessDir, err => { |
| 23 | + console.log('Could not remove cloned dir. On windows desktops, remove it manually...', err) |
| 24 | + }) |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + it('works if action returns a function', () => { |
| 29 | + const act = init.getAction() |
| 30 | + expect(act).toBeInstanceOf(Function) |
| 31 | + }) |
| 32 | + |
| 33 | + it('works if directory is cloned after applying init', async () => { |
| 34 | + jest.setTimeout(180000) |
| 35 | + mockedInquirer.prompt.mockReturnValue({ seedName: 'graphql-server-typed' }) |
| 36 | + const actFunction = init.getAction() |
| 37 | + await actFunction(pathToProjectDir) |
| 38 | + const projectFolderExists: boolean = fs.lstatSync(absoluteProcessDir).isDirectory() |
| 39 | + const projectNodeModulesExists: boolean = fs |
| 40 | + .lstatSync(path.join(absoluteProcessDir, 'node_modules')) |
| 41 | + .isDirectory() |
| 42 | + expect(projectFolderExists).toBeTruthy() |
| 43 | + expect(projectNodeModulesExists).toBeTruthy() |
| 44 | + }) |
| 45 | +}) |
0 commit comments