From 1e35bac41741af0e4ae70939df50ea80e5958434 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 15 Jun 2015 13:14:26 -0700 Subject: [PATCH] test: add basic test coverage --- .github/workflows/ci.yaml | 12 +++++++ APIBlueprintGenerator.coffee | 13 ++++++-- Cakefile | 6 +--- package.json | 18 +++++++---- test/APIBlueprintGenerator-test.coffee | 44 ++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 test/APIBlueprintGenerator-test.coffee diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..938dc9a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/APIBlueprintGenerator.coffee b/APIBlueprintGenerator.coffee index 63f989b..827b26f 100644 --- a/APIBlueprintGenerator.coffee +++ b/APIBlueprintGenerator.coffee @@ -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 = -> @@ -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 + diff --git a/Cakefile b/Cakefile index b96dd25..f063b8a 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,4 @@ -{spawn} = require 'child_process' +{spawn, exec} = require 'child_process' {ncp} = require 'ncp' mkdirp = require 'mkdirp' fs = require 'fs' @@ -75,10 +75,6 @@ archive = (callback) -> task 'build', -> build() -task 'test', -> - build () -> - # no test to run - task 'install', -> build () -> install() diff --git a/package.json b/package.json index 1a76650..9c29a21 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/APIBlueprintGenerator-test.coffee b/test/APIBlueprintGenerator-test.coffee new file mode 100644 index 0000000..017edd0 --- /dev/null +++ b/test/APIBlueprintGenerator-test.coffee @@ -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 + +""") +