Skip to content
This repository was archived by the owner on May 10, 2018. It is now read-only.

Commit 8f1e5ad

Browse files
committed
test: added tests
1 parent ce85963 commit 8f1e5ad

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { Generator } from './types'
77
export { Generator } from './types'
88

99
export function generateCode(schema: string, generator: Generator | string): string {
10-
if (typeof generator === 'string'){
10+
if (typeof generator === 'string') {
1111
generator = generators[generator] || require(generator).generator
1212
if (!generator) {
1313
throw new Error(`Generator '${generator}' could not be found. Available generators:
1414
${Object.keys(generators).map(k => `'${k}`).join(', ')}`)
1515
}
16-
}
16+
}
1717

1818
const document: DocumentNode = parse(schema, { noLocation: true })
1919

test/createReport.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ var options = {
55
jsonFile: 'test/report/cucumber_report.json',
66
output: 'test/report/cucumber_report.html',
77
reportSuiteAsScenarios: true,
8-
launchReport: true,
8+
launchReport: false,
99
metadata: {
10-
"App Version":"0.3.2",
11-
"Test Environment": "STAGING",
12-
"Browser": "Chrome 54.0.2840.98",
13-
"Platform": "Windows 10",
14-
"Parallel": "Scenarios",
15-
"Executed": "Remote"
10+
1611
}
1712
};
1813

test/features/graphcool-ts.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: Graphcool Typescript
22

33
Feature for Graphcool Typescript generator
44

5-
Scenario: Scenario name
5+
Scenario: Query type only
66
Given a schema looking like this:
77
"""
88
type Query {
@@ -49,4 +49,10 @@ Feature for Graphcool Typescript generator
4949
posts: (args, info): Promise<Array<String> | null> => super.delegate('query', 'posts', args, {}, info)
5050
}
5151
}
52-
"""
52+
"""
53+
54+
Scenario: Query and Mutation type
55+
Given the schema from 'test/testfiles/input/query-mutation.graphql'
56+
And I pick generator 'graphcool-ts'
57+
When I run the generator
58+
Then I expect the output to match 'test/testfiles/output/query-mutation.ts'

test/step_definitions/graphcool-ts.steps.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as path from 'path'
1+
import * as fs from 'fs';
2+
import * as path from 'path';
23
import { defineSupportCode, TableDefinition, World } from 'cucumber'
34
import { generateCode } from '../../src'
45

@@ -7,18 +8,28 @@ defineSupportCode(function({ Given, When, Then }) {
78
this.schema = schema
89
})
910

11+
Given(/^the schema from '(.*)'$/, function(filename) {
12+
this.schema = fs.readFileSync(filename, 'utf-8')
13+
})
14+
1015
Given('I pick generator {string}', function(generator) {
1116
this.generator = generator
1217
})
1318

1419
When('I run the generator', function() {
1520
this.result = generateCode(this.schema, this.generator)
16-
this.attach(this.result, 'application/typescript');
1721
})
1822

1923
Then('I expect the output to be:', function(output) {
2024
console.assert(normalizeText(this.result) == normalizeText(output), output)
2125
})
26+
27+
Then(/^I expect the output to match '(.*)'$/, function(filename) {
28+
const output = fs.readFileSync(filename, 'utf-8')
29+
console.log(output)
30+
console.log(this.result)
31+
console.assert(normalizeText(this.result) == normalizeText(output), output)
32+
})
2233
})
2334

2435
function normalizeText(text) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type Query {
2+
posts: [String]
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Graphcool as BaseGraphcool, BaseGraphcoolOptions } from 'graphcool-binding'
2+
import { GraphQLResolveInfo } from 'graphql'
3+
4+
const typeDefs = `
5+
type Query {
6+
posts: [String]
7+
}`
8+
9+
/*
10+
The `Boolean` scalar type represents `true` or `false`.
11+
*/
12+
export type Boolean = boolean
13+
14+
/*
15+
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
16+
*/
17+
export type String = string
18+
19+
export interface Schema {
20+
query: Query
21+
}
22+
23+
export type Query = {
24+
posts: (args: {}, info?: GraphQLResolveInfo | string) => Promise<Array<String> | null>
25+
}
26+
27+
export class Graphcool extends BaseGraphcool {
28+
29+
constructor({ endpoint, secret, fragmentReplacements, debug }: BaseGraphcoolOptions) {
30+
super({ typeDefs, endpoint, secret, fragmentReplacements, debug });
31+
}
32+
33+
query: Query = {
34+
posts: (args, info): Promise<Array<String> | null> => super.delegate('query', 'posts', args, {}, info)
35+
}
36+
}

0 commit comments

Comments
 (0)