Skip to content

Commit

Permalink
feat(test): add tests
Browse files Browse the repository at this point in the history
adds tests
  • Loading branch information
jimthedev committed Sep 6, 2016
1 parent 19d89ec commit f6bce7c
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_js:
- '0.12'
before_install:
- npm i -g npm@^2.0.0
- npm i --save-dev graphql
before_script:
- npm prune
after_success:
Expand Down
60 changes: 46 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,54 @@ npm install --save gra
```
var g = require('gra');
g.int
g.id
g.float
g.str
g.bool
g.obj
g.list
g.interface
g.union
g.enum
g.input
g.nonNull
g.scalar
// Micro syntax
g.id // ==> GraphQLID,
g.i // ==> GraphQLInt,
g.f // ==> GraphQLFloat,
g.s // ==> GraphQLString,
g.b // ==> GraphQLBoolean,
g.o // ==> GraphQLObjectType,
g.l // ==> GraphQLList,
g.u // ==> GraphQLUnionType,
g.e // ==> GraphQLEnumType,
g.in // ==> GraphQLInputObjectType,
g.sc // ==> GraphQLScalarType,
g.if // ==> GraphQLInterfaceType,
g.nn // ==> GraphQLNonNull,
// Short syntax
g.ident // ==> GraphQLID,
g.int // ==> GraphQLInt,
g.float // ==> GraphQLFloat,
g.str // ==> GraphQLString,
g.bool // ==> GraphQLBoolean,
g.obj // ==> GraphQLObjectType,
g.list // ==> GraphQLList,
g.union // ==> GraphQLUnionType,
g.enum // ==> GraphQLEnumType,
g.input // ==> GraphQLInputObjectType,
g.scal // ==> GraphQLScalarType,
g.inter // ==> GraphQLInterfaceType,
g.non // ==> GraphQLNonNull,
// Medium syntax
g.identifier // ==> GraphQLID,
g.integer // ==> GraphQLInt,
g.string // ==> GraphQLString,
g.boolean // ==> GraphQLBoolean,
g.object // ==> GraphQLObjectType,
g.list // ==> GraphQLList,
g.union // ==> GraphQLUnionType,
g.enum // ==> GraphQLEnumType,
g.inputObject // ==> GraphQLInputObjectType,
g.scalar // ==> GraphQLScalarType,
g.interface // ==> GraphQLInterfaceType,
g.nonNull // ==> GraphQLNonNull,
```
So, using `g.i` or `g.int` or `g.integer` is the same as using `GraphQLInt`.

`g.int` is the same as using `GraphQLInt`
You can mix and match micro, sort, and medium syntax. They are all provided in various forms for convenience.

Each of the above can be used in place of its [more verbose cousin](http://graphql.org/docs/api-reference-type-system/).

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "gra",
"description": "",
"version": "1.0.1",
"description": "a wrapper around GraphQL's type module. It makes the syntax slightly less repetitive.",
"version": "0.0.0-semantic-release",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "mocha test",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
Expand All @@ -19,7 +19,9 @@
},
"homepage": "https://github.com/jimthedev/gra#readme",
"devDependencies": {
"chai": "^3.5.0",
"cz-conventional-changelog": "^1.2.0",
"mocha": "^3.0.2",
"semantic-release": "^4.3.5"
},
"config": {
Expand Down
34 changes: 34 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
var gqlType = require('graphql/type');

var gra = {
i: gqlType.GraphQLInt,
int: gqlType.GraphQLInt,
integer: gqlType.GraphQLInt,

id: gqlType.GraphQLID,
ident: gqlType.GraphQLID,
identifier: gqlType.GraphQLID,

f: gqlType.GraphQLFloat,
float: gqlType.GraphQLFloat,

s: gqlType.GraphQLString,
str: gqlType.GraphQLString,
string: gqlType.GraphQLString,

b: gqlType.GraphQLBoolean,
bool: gqlType.GraphQLBoolean,
boolean: gqlType.GraphQLBoolean,

sc: gqlType.GraphQLScalarType,
scal: gqlType.GraphQLScalarType,
scalar: gqlType.GraphQLScalarType,

o: gqlType.GraphQLObjectType,
obj: gqlType.GraphQLObjectType,
object: gqlType.GraphQLObjectType,

if: gqlType.GraphQLInterfaceType,
inter: gqlType.GraphQLInterfaceType,
interface: gqlType.GraphQLInterfaceType,

u: gqlType.GraphQLUnionType,
union: gqlType.GraphQLUnionType,

e: gqlType.GraphQLEnumType,
enum: gqlType.GraphQLEnumType,

in: gqlType.GraphQLInputObjectType,
input: gqlType.GraphQLInputObjectType,
inputObject: gqlType.GraphQLInputObjectType,

l: gqlType.GraphQLList,
list: gqlType.GraphQLList,

nn: gqlType.GraphQLNonNull,
non: gqlType.GraphQLNonNull,
nonNull: gqlType.GraphQLNonNull,
}

Expand Down
59 changes: 59 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var chai = require('chai');
var expect = chai.expect;

var g = require('./index.js');
var t = require('graphql/type');

describe('gra', function() {
describe('micro', function() {
it('should represent graphql\'s types', function() {
expect(g.id).to.equal(t.GraphQLID);
expect(g.i).to.equal(t.GraphQLInt);
expect(g.f).to.equal(t.GraphQLFloat);
expect(g.s).to.equal(t.GraphQLString);
expect(g.b).to.equal(t.GraphQLBoolean);
expect(g.o).to.equal(t.GraphQLObjectType);
expect(g.l).to.equal(t.GraphQLList);
expect(g.u).to.equal(t.GraphQLUnionType);
expect(g.e).to.equal(t.GraphQLEnumType);
expect(g.in).to.equal(t.GraphQLInputObjectType);
expect(g.sc).to.equal(t.GraphQLScalarType);
expect(g.if).to.equal(t.GraphQLInterfaceType);
expect(g.nn).to.equal(t.GraphQLNonNull);
});
});
describe('small', function() {
it('should represent graphql\'s types', function() {
expect(g.ident).to.equal(t.GraphQLID);
expect(g.int).to.equal(t.GraphQLInt);
expect(g.float).to.equal(t.GraphQLFloat);
expect(g.str).to.equal(t.GraphQLString);
expect(g.bool).to.equal(t.GraphQLBoolean);
expect(g.obj).to.equal(t.GraphQLObjectType);
expect(g.list).to.equal(t.GraphQLList);
expect(g.union).to.equal(t.GraphQLUnionType);
expect(g.enum).to.equal(t.GraphQLEnumType);
expect(g.input).to.equal(t.GraphQLInputObjectType);
expect(g.scal).to.equal(t.GraphQLScalarType);
expect(g.inter).to.equal(t.GraphQLInterfaceType);
expect(g.non).to.equal(t.GraphQLNonNull);
});
});
describe('medium', function() {
it('should represent graphql\'s types', function() {
expect(g.identifier).to.equal(t.GraphQLID);
expect(g.integer).to.equal(t.GraphQLInt);
expect(g.float).to.equal(t.GraphQLFloat);
expect(g.string).to.equal(t.GraphQLString);
expect(g.boolean).to.equal(t.GraphQLBoolean);
expect(g.object).to.equal(t.GraphQLObjectType);
expect(g.list).to.equal(t.GraphQLList);
expect(g.union).to.equal(t.GraphQLUnionType);
expect(g.enum).to.equal(t.GraphQLEnumType);
expect(g.inputObject).to.equal(t.GraphQLInputObjectType);
expect(g.scalar).to.equal(t.GraphQLScalarType);
expect(g.interface).to.equal(t.GraphQLInterfaceType);
expect(g.nonNull).to.equal(t.GraphQLNonNull);
});
});
});
2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./src/**/*.test.js
--recursive

0 comments on commit f6bce7c

Please sign in to comment.