Skip to content

Commit 714233f

Browse files
authored
Merge pull request #1 from tomyitav/test-init-command
Test init command
2 parents b0d71a0 + 6877567 commit 714233f

File tree

8 files changed

+67
-14
lines changed

8 files changed

+67
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ To generate a matching resolver file for type file, execute the command:
3535

3636
```gga r <type-file> <resolver file>```
3737

38-
This will create a matching file. with all Query, Mutation and Subscription
38+
This will create a matching file, with all Query, Mutation and Subscription
3939
definitions.

package-lock.json

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@
104104
"@commitlint/config-conventional": "^7.1.2",
105105
"@types/commander": "^2.12.2",
106106
"@types/cross-spawn": "^6.0.0",
107+
"@types/fs-extra": "^5.0.4",
107108
"@types/inquirer": "0.0.43",
108109
"@types/jest": "^23.3.2",
109110
"@types/node": "^10.11.0",
111+
"@types/rimraf": "^2.0.2",
110112
"colors": "^1.3.2",
111113
"commitizen": "^3.0.0",
112114
"coveralls": "^3.0.2",
@@ -129,18 +131,19 @@
129131
"rollup-plugin-sourcemaps": "^0.4.2",
130132
"rollup-plugin-typescript2": "^0.17.0",
131133
"semantic-release": "^15.12.1",
134+
"travis-deploy-once": "^5.0.9",
132135
"ts-jest": "^23.10.2",
133136
"ts-node": "^7.0.1",
134137
"tslint": "^5.11.0",
135138
"tslint-config-prettier": "^1.15.0",
136139
"tslint-config-standard": "^8.0.1",
137140
"typedoc": "^0.12.0",
138-
"typescript": "^3.0.3",
139-
"travis-deploy-once": "^5.0.9"
141+
"typescript": "^3.0.3"
140142
},
141143
"dependencies": {
142144
"commander": "^2.19.0",
143145
"cross-spawn": "^6.0.5",
146+
"fs-extra": "^7.0.1",
144147
"graphql-json-schema": "^0.1.2",
145148
"inquirer": "^6.2.0"
146149
}

src/commands/resolver/resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
subscriptionSubscribeDefinition,
1616
operationFuntionsSuffix
1717
} from './resolver-constants'
18-
import { fileExist, readFileContent, writeToFile } from '../../utils/file-operations'
18+
import { fileExists, readFileContent, writeToFile } from '../../utils/file-operations'
1919

2020
export class Resolver extends AbstractCommand {
2121
public getName(): string {
@@ -25,7 +25,7 @@ export class Resolver extends AbstractCommand {
2525
public getAction(): (...args: any[]) => void {
2626
return async (pathToType: string, pathToResolver: string) => {
2727
try {
28-
const resolverExists = await fileExist(pathToResolver)
28+
const resolverExists = await fileExists(pathToResolver)
2929
if (resolverExists) {
3030
console.log(
3131
'Resolver file already exists. please select a different path or remove the current file...'

src/gga.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as program from 'commander'
44
import allCommands from './commands/all-commands'
55

6-
program.version('1.2.3').description('Cli tool for bootstrapping production grade GraphQL server')
6+
program.version('1.3.1').description('Cli tool for bootstrapping production grade GraphQL server')
77

88
for (let command of allCommands) {
99
program

src/utils/file-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function writeToFile(pathToFile: string, content: string): Promise<void>
1212
})
1313
}
1414

15-
export function fileExist(pathToFile: string): Promise<boolean> {
15+
export function fileExists(pathToFile: string): Promise<boolean> {
1616
return new Promise(resolve => {
1717
fs.stat(pathToFile, (err, stats) => {
1818
if (err) {

test/commands/init/init.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
})

test/commands/resolver/resolver.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Resolver } from '../../../src/commands/resolver/resolver'
33
import * as fs from 'fs'
44

55
describe('Resolver command test', () => {
6-
// const mockedProcess = process as jest.Mocked<typeof process>
76
let res: AbstractCommand
87
const pathToType = './test/commands/resolver/test-schema.ts'
98
const pathToActualResolver = './test/output/actual/test-resolver.ts'

0 commit comments

Comments
 (0)