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

Commit 1da897d

Browse files
committed
test: setup testing
1 parent be783f9 commit 1da897d

File tree

8 files changed

+2994
-252
lines changed

8 files changed

+2994
-252
lines changed

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
src
2-
.circleci
32
.travis.yml
43
renovate.json
54
.codeclimate.yml
6-
dist/test.*
5+
test

package.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,46 @@
77
"scripts": {
88
"prepublish": "npm run build",
99
"build": "rm -rf dist && tsc -d",
10+
"test": "nyc cucumber-js --compiler ts:ts-node/register test/features/ -r test/step_definitions/ -f json:test/report/cucumber_report.json",
11+
"posttest": "node test/createReport.js",
1012
"semantic-release": "semantic-release"
1113
},
1214
"keywords": [
1315
"graphql"
1416
],
1517
"author": "Kim Brandwijk <[email protected]>",
1618
"license": "MIT",
19+
"nyc": {
20+
"extension": [
21+
".ts"
22+
],
23+
"require": [
24+
"ts-node/register"
25+
],
26+
"include": [
27+
"src/**/*.ts"
28+
],
29+
"exclude": [
30+
"**/*.d.ts"
31+
],
32+
"reporter": [
33+
"text",
34+
"lcov"
35+
],
36+
"all": true
37+
},
1738
"dependencies": {
39+
"cucumber-html-reporter": "^3.0.4",
1840
"graphql": "0.12.3"
1941
},
2042
"devDependencies": {
43+
"@types/cucumber": "3.1.1",
2144
"@types/node": "8.5.2",
45+
"cucumber": "3.2.0",
46+
"nyc": "11.4.1",
47+
"semantic-release": "11.1.0",
2248
"ts-node": "4.1.0",
23-
"typescript": "2.6.2",
24-
"semantic-release": "11.1.0"
49+
"typescript": "2.6.2"
2550
},
2651
"repository": {
2752
"type": "git",

test/createReport.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var reporter = require('cucumber-html-reporter');
2+
3+
var options = {
4+
theme: 'bootstrap',
5+
jsonFile: 'test/report/cucumber_report.json',
6+
output: 'test/report/cucumber_report.html',
7+
reportSuiteAsScenarios: true,
8+
launchReport: true,
9+
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"
16+
}
17+
};
18+
19+
reporter.generate(options);

test/features/graphcool-ts.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Feature: Graphcool Typescript
2+
3+
Feature for Graphcool Typescript generator
4+
5+
Scenario: Scenario name
6+
Given a schema looking like this:
7+
"""
8+
type Query {
9+
posts: [String]
10+
}
11+
"""
12+
And I pick generator 'graphcool-ts'
13+
When I run the generator
14+
Then I expect the output to be:
15+
"""
16+
import { Graphcool as BaseGraphcool, BaseGraphcoolOptions } from 'graphcool-binding'
17+
import { GraphQLResolveInfo } from 'graphql'
18+
19+
const typeDefs = `
20+
type Query {
21+
posts: [String]
22+
}`
23+
24+
/*
25+
The `Boolean` scalar type represents `true` or `false`.
26+
*/
27+
export type Boolean = boolean
28+
29+
/*
30+
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.
31+
*/
32+
export type String = string
33+
34+
export interface Schema {
35+
query: Query
36+
}
37+
38+
export type Query = {
39+
posts: (args: {}, info?: GraphQLResolveInfo | string) => Promise<Array<String> | null>
40+
}
41+
42+
export class Graphcool extends BaseGraphcool {
43+
44+
constructor({ endpoint, secret, fragmentReplacements, debug }: BaseGraphcoolOptions) {
45+
super({ typeDefs, endpoint, secret, fragmentReplacements, debug });
46+
}
47+
48+
query: Query = {
49+
posts: (args, info): Promise<Array<String> | null> => super.delegate('query', 'posts', args, {}, info)
50+
}
51+
}
52+
"""

test/report/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This folder contains local test reports and needs to exist
2+
*
3+
!.gitignore
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as path from 'path'
2+
import { defineSupportCode, TableDefinition, World } from 'cucumber'
3+
import { generateCode } from '../../src'
4+
5+
defineSupportCode(function({ Given, When, Then }) {
6+
Given('a schema looking like this:', function(schema) {
7+
this.schema = schema
8+
})
9+
10+
Given('I pick generator {string}', function(generator) {
11+
this.generator = generator
12+
})
13+
14+
When('I run the generator', function() {
15+
this.result = generateCode(this.schema, this.generator)
16+
this.attach(this.result, 'application/typescript');
17+
})
18+
19+
Then('I expect the output to be:', function(output) {
20+
console.assert(normalizeText(this.result) == normalizeText(output), output)
21+
})
22+
})
23+
24+
function normalizeText(text) {
25+
return text
26+
.replace(/\033\[[0-9;]*m/g, '')
27+
.replace(/\r\n|\r/g, '\n')
28+
.trim()
29+
.replace(/[ \t]+\n/g, '\n')
30+
.replace(/\d+m\d{2}\.\d{3}s/, '<duration-stat>')
31+
.replace(/\d+(.\d+)?ms/g, '<d>ms')
32+
.replace(/\//g, path.sep)
33+
.replace(/ +/g, ' ')
34+
.split('\n')
35+
.map(line => line.trim())
36+
.join('\n')
37+
}

src/test.ts renamed to test/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { generateCode } from './';
1+
import { generateCode } from '../src';
22
import * as fs from 'fs'
33

4-
import { generators } from './generators'
4+
import { generators } from '../src/generators'
55

66
const schema = `
77
# THIS FILE HAS BEEN AUTO-GENERATED BY THE "GRAPHCOOL DEPLOY" COMMAND AT 2017-12-19T20:44:05.845Z

0 commit comments

Comments
 (0)