Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- uses: actions/checkout@v1
- run: npm install
- run: npm test
13 changes: 11 additions & 2 deletions APIBlueprintGenerator.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
require "mustache.js"
if typeof registerCodeGenerator != 'undefined'
require 'mustache.js'
else if typeof module != 'undefined'
Mustache = require('mustache')
readFile = (path) ->
require('fs').readFileSync(path, 'utf-8')

APIBlueprintGenerator = ->

Expand Down Expand Up @@ -98,4 +103,8 @@ APIBlueprintGenerator.identifier = "io.apiary.PawExtensions.APIBlueprintGenerato
APIBlueprintGenerator.title = "API Blueprint Generator"
APIBlueprintGenerator.fileExtension = "md"

registerCodeGenerator APIBlueprintGenerator
if typeof registerCodeGenerator != 'undefined'
registerCodeGenerator APIBlueprintGenerator
else if typeof module != 'undefined'
module.exports = APIBlueprintGenerator

6 changes: 1 addition & 5 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{spawn} = require 'child_process'
{spawn, exec} = require 'child_process'
{ncp} = require 'ncp'
mkdirp = require 'mkdirp'
fs = require 'fs'
Expand Down Expand Up @@ -75,10 +75,6 @@ archive = (callback) ->
task 'build', ->
build()

task 'test', ->
build () ->
# no test to run

task 'install', ->
build () ->
install()
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"name": "Paw-APIBlueprintGenerator",
"version": "1.0.0",
"devDependencies": {
"coffee-script": "latest",
"mkdirp": "~0.5.0",
"ncp": "~1.0.1"
"repository": {
"type": "git",
"url": "git@github.com:apiaryio/Paw-APIBlueprintGenerator.git"
},
"scripts": {
"test": "mocha --require coffee-script/register test/*.coffee"
},
"dependencies": {
"mustache": "~0.8.2"
},
"repository": {
"type": "git",
"url": "git@github.com:apiaryio/Paw-APIBlueprintGenerator.git"
"devDependencies": {
"coffee-script": "latest",
"mkdirp": "~0.5.0",
"ncp": "~1.0.1",
"mocha": "latest"
}
}
44 changes: 44 additions & 0 deletions test/APIBlueprintGenerator-test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
assert = require('assert')
APIBlueprintGenerator = require('../APIBlueprintGenerator.coffee')


# Mock Paw Context
class Context
constructor: (@request) ->

getCurrentRequest: ->
@request


# Mock Paw HTTPExchange
class HTTPExchange
constructor: (@responseStatusCode, @responseHeaders, @responseBody) ->


# Mock Paw Request
class Request
constructor: (@name, @method, @url, @headers, @body, @exchange) ->

getLastExchange: ->
@exchange


describe 'API Blueprint Generator', ->
describe 'when importing an API Blueprint', ->
before ->
@generator = new APIBlueprintGenerator()

it 'renders a GET request with a response', ->
exchange = new HTTPExchange(200, {'Content-Type': 'plain/text'}, 'Hello World')
request = new Request('foo', 'GET', 'https://apiary.io/path', {}, '', exchange)
context = new Context(request)
blueprint = @generator.generate(context)
assert.equal(blueprint, """
# GET /path

+ Response 200 (plain/text)

Hello World

""")