Skip to content

Commit

Permalink
cloning test project
Browse files Browse the repository at this point in the history
  • Loading branch information
denodaeus committed Mar 6, 2017
0 parents commit 138f926
Show file tree
Hide file tree
Showing 26 changed files with 608 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json}]
charset = utf-8
indent_style = space
indent_size = 2

[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

[*.go]
charset = utf-8
indent_style = tab
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.idea
.DS_Store

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

*~
\#*\#
.\#*

# Ignore dirs
/build/
/deploy/
/logs/
/reports/
/.gauge/

# Screenshot
screenshot-test.png
10 changes: 10 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"disallowMixedSpacesAndTabs": true,
"disallowSpaceBeforeComma": true,
"requireCapitalizedConstructors": true,
"requireSemicolons": true,
"requireSpacesInForStatement": true,
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": { "mark": "\"", "escape": true }
}
47 changes: 47 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"bitwise": false,
"camelcase": false,
"curly": true,
"eqeqeq": false,
"es3": false,
"forin": false,
"freeze": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": false,
"plusplus": false,
"quotmark": "double",
"undef": true,
"unused": true,
"trailing": true,
"asi": false,
"boss": true,
"debug": false,
"eqnull": true,
"evil": false,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"multistr": false,
"maxcomplexity": 10,
"mocha": true,
"notypeof": false,
"predef" : [ "gaugejs", "gauge"],
"proto": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": false,
"browser": false,
"devel": true,
"node": true
}
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Demo of testing Swagger Web API with Gauge JS

This demo tests a dummy NodeJS-based Web API written with Swagger with [Gauge][_gauge], using the [JavaScript][_gaugejs] language runner.

## Setting up

* Install [Gauge][_gauge].
* Install [NodeJS][_node].
* Install Swagger: `$ sudo npm install -g swagger`
* Install [Gauge JS][_gaugejs] runner: `$ gauge --install js`
* In the project root directory, run: `$ npm install`

## Running Gauge tests

* `$ npm start`: Start the Swagger API server.
* `$ npm test`: While the server is running, run Gauge tests (in another terminal).

## Project layout

- API Server: [`./server/`](server)
- Gauge specifications: [`./specs/`](specs)
- Test implementations: [`./tests/`](tests)

[_gauge]: http://getgauge.io
[_gaugejs]: https://github.com/getgauge-contrib/gauge-js
[_node]: https://nodejs.org
16 changes: 16 additions & 0 deletions env/default/default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# default.properties
# properties set here will be available to the test execution as environment variables

# sample_key = sample_value

#The path to the gauge reports directory. Should be either relative to the project directory or an absolute path
gauge_reports_dir = reports

#Set as false if gauge reports should not be overwritten on each execution. A new time-stamped directory will be created on each execution.
overwrite_reports = true

# Set to false to disable screenshots on failure in reports.
screenshot_on_failure = false

# The path to the gauge logs directory. Should be either relative to the project directory or an absolute path
logs_directory = logs
7 changes: 7 additions & 0 deletions env/default/js.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#js.properties
#settings related to gauge-js.

test_timeout = 10000

# Change this to true to enable debugging support
DEBUG = false
1 change: 1 addition & 0 deletions env/default/swagger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_BASE = http://localhost:10010/
6 changes: 6 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Language": "js",
"Plugins": [
"html-report"
]
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "gauge-js-swagger-demo",
"version": "0.1.0",
"description": "Demo of testing Swagger API with Gauge in JavaScript",
"scripts": {
"setup": "cd server && npm install",
"start": "npm run setup && swagger project start server",
"test": "gauge specs/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/getgauge/gauge-js-swagger-demo.git"
},
"keywords": [
"getgauge",
"swagger",
"api",
"testing",
"demo"
],
"author": "Kaustav Das Modak <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/getgauge/gauge-js-swagger-demo/issues"
},
"homepage": "https://github.com/getgauge/gauge-js-swagger-demo#readme",
"dependencies": {
"request": "^2.72.0"
}
}
34 changes: 34 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# IDE files
.idea

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Users Environment Variables
.lock-wscript

# Runtime configuration for swagger app
config/runtime.yaml
1 change: 1 addition & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# API Server for Gauge Swagger demo
1 change: 1 addition & 0 deletions server/api/controllers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place your controllers in this directory.
22 changes: 22 additions & 0 deletions server/api/controllers/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// GET messages
var get = function (req, res) {
console.log("Sending message list", db.msgs);
res.json(db.msgs);
};

// POST messages
var post = function (req, res) {
var msg = req.swagger.params.msg.value || "";
db.msgs.push(msg);
console.log("Inserting message", msg);
res.json("Ok");
};

// DELETE messages
var clear = function (req, res) {
console.log("Clearing messages");
db.msgs = [];
res.json("Ok");
};

module.exports = { get: get, post: post, delete: clear };
1 change: 1 addition & 0 deletions server/api/helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place helper files in this directory.
1 change: 1 addition & 0 deletions server/api/mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place controllers for mock mode in this directory.
71 changes: 71 additions & 0 deletions server/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
swagger: "2.0"
info:
version: "0.0.1"
title: Gauge Swagger Demo Server
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json

paths:
/messages:
x-swagger-router-controller: messages
get:
description: Get a list of messages sent so far
produces:
- application/json
responses:
'200':
$ref: '#/responses/MessageList'
post:
description: Write a new message
consumes:
- application/json
produces:
- application/json
parameters:
- name: msg
in: body
required: true
schema:
type: string
responses:
'200':
$ref: '#/responses/Success'
delete:
description: Clear existing messages
produces:
- application/json
responses:
'200':
$ref: '#/responses/Success'

definitions:
Msg:
title: Message
description: A single message
type: string

responses:
Success:
description: Response sent on a success.
schema:
type: string
MessageList:
description: Response containing list of messages.
schema:
description: Message list
type: array
items:
$ref: '#/definitions/Msg'
23 changes: 23 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

var SwaggerExpress = require('swagger-express-mw');
var app = require('express')();
module.exports = app; // for testing

var config = {
appRoot: __dirname // required config
};

global.db = {
msgs: []
};

SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }

// install middleware
swaggerExpress.register(app);

var port = process.env.PORT || 10010;
app.listen(port);
});
1 change: 1 addition & 0 deletions server/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place configuration files in this directory.
Loading

0 comments on commit 138f926

Please sign in to comment.