Permalink
Browse files

Use apidoc-example.

  • Loading branch information...
1 parent 9863ae4 commit 64e9f469f03b519cc57893ac5c96156d6376ba38 @rottmann rottmann committed Dec 18, 2014
Showing with 67 additions and 2,591 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +6 −5 package.json
  4. +59 −37 test/apidoc_test.js
  5. +0 −1,750 test/fixtures/api_data.json
  6. +0 −29 test/fixtures/api_project.json
  7. +0 −29 test/fixtures/example/_grouping.js
  8. +0 −9 test/fixtures/example/_syntax.js
  9. +0 −22 test/fixtures/example/apidoc.json
  10. +0 −26 test/fixtures/example/define.js
  11. +0 −28 test/fixtures/example/error_structure.js
  12. +0 −39 test/fixtures/example/escape.js
  13. +0 −45 test/fixtures/example/example.js
  14. +0 −3 test/fixtures/example/footer.md
  15. +0 −8 test/fixtures/example/group.js
  16. +0 −27 test/fixtures/example/header.js
  17. +0 −3 test/fixtures/example/header.md
  18. +0 −10 test/fixtures/example/header_example.js
  19. +0 −28 test/fixtures/example/header_structure.js
  20. +0 −11 test/fixtures/example/header_title.js
  21. +0 −35 test/fixtures/example/language.coffee
  22. +0 −35 test/fixtures/example/language.erl
  23. +0 −35 test/fixtures/example/language.js
  24. +0 −48 test/fixtures/example/language.pm
  25. +0 −35 test/fixtures/example/language.py
  26. +0 −35 test/fixtures/example/language.rb
  27. +0 −19 test/fixtures/example/markdown.js
  28. +0 −71 test/fixtures/example/param.js
  29. +0 −16 test/fixtures/example/param_example.js
  30. +0 −11 test/fixtures/example/param_title.js
  31. +0 −26 test/fixtures/example/permission.js
  32. +0 −23 test/fixtures/example/sample_request.js
  33. +0 −28 test/fixtures/example/structure.js
  34. +0 −28 test/fixtures/example/success_structure.js
  35. +0 −24 test/fixtures/example/title_and_structure.js
  36. +0 −13 test/template/index.html
View
@@ -1 +1,2 @@
node_modules/
+npm-debug.log
View
@@ -4,3 +4,4 @@ test/
.gitignore
.npmignore
.travis.yml
+npm-debug.log
View
@@ -1,6 +1,6 @@
{
"name": "apidoc-core",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "Core parser library to generate apidoc result following the apidoc-spec",
"author": "Peter Rottmann <rottmann@inveris.de>",
"license": {
@@ -33,13 +33,14 @@
},
"dependencies": {
"lodash": "~2.4.1",
- "semver": "^4.1.0",
+ "semver": "~4.1.0",
"wrench": "~1.5.8"
},
"devDependencies": {
- "jshint": "^2.5.10",
- "marked": "^0.3.2",
- "mocha": "^2.0.1",
+ "apidoc-example": "*",
+ "jshint": "~2.5.10",
+ "marked": "~0.3.2",
+ "mocha": "~2.0.1",
"should": "~4.2.1"
},
"jshintConfig": {
View
@@ -1,45 +1,53 @@
-/*jshint unused:false*/
+/*jshint unused:false, expr:true */
/**
* Test: apiDoc full parse
*/
// node modules
-var should = require('should');
-var fs = require('fs');
-var path = require('path');
-var apidoc = require('../lib/index');
-
+var fs = require('fs');
+var markdown = require('marked');
+var path = require('path');
+var semver = require('semver');
+var should = require('should');
-function log() {
- // can add an emitter here and capture it in the tests with chai-spies
-}
-
-var logger = {
- debug : log,
- verbose: log,
- info : log,
- warn : log,
- error : log,
-};
-
-var marked = {
- gfm : true,
- tables : true,
- breaks : false,
- pedantic : false,
- sanitize : false,
- smartLists : false,
- smartypants: false
-};
+var versions = require('apidoc-example').versions;
-var markdown = require('marked');
-markdown.setOptions(marked);
+// lib modules
+var apidoc = require('../lib/index');
describe('apiDoc full parse', function() {
+ // get latest example for the used apidoc-spec
+ var latestExampleVersion = semver.maxSatisfying(versions, '~' + apidoc.SPECIFICATION_VERSION); // ~0.2.0 = >=0.2.0 <0.3.0
+
+ var exampleBasePath = 'node_modules/apidoc-example/' + latestExampleVersion;
+ var fixturePath = exampleBasePath + '/fixtures';
+
+ function log() {
+ // can add an emitter here and capture it in the tests with chai-spies
+ }
+
+ var logger = {
+ debug : log,
+ verbose: log,
+ info : log,
+ warn : log,
+ error : log,
+ };
+
+ markdown.setOptions({
+ gfm : true,
+ tables : true,
+ breaks : false,
+ pedantic : false,
+ sanitize : false,
+ smartLists : false,
+ smartypants: false
+ });
+
var fixtureFiles = [
- { key: 'data', filename: 'api_data.json' },
+ { key: 'data' , filename: 'api_data.json' },
{ key: 'project', filename: 'api_project.json' }
];
@@ -53,11 +61,18 @@ describe('apiDoc full parse', function() {
done();
});
+ // version found
+ it('should find latest example version', function(done) {
+ should(latestExampleVersion).be.ok;
+ done();
+ });
+
// create
it('should create example in memory', function(done) {
var options = {
- src: /*path.join(__dirname, './fixtures/example/')*/ './test/fixtures/example/'
+ src: exampleBasePath + '/src/'
};
+
var generator = {};
var packageInfos = {
'name': 'test',
@@ -67,11 +82,11 @@ describe('apiDoc full parse', function() {
'sampleUrl': 'https://api.github.com/v1',
'header': {
'title': 'My own header title',
- 'filename': 'header.md'
+ 'content': '<h1 id=\"header-md-file\">Header .md File</h1>\n<p>Content of header.md file.</p>\n'
},
'footer': {
'title': 'My own footer title',
- 'filename': 'footer.md'
+ 'content': '<h1 id=\"footer-md-file\">Footer .md File</h1>\n<p>Content of footer.md file.</p>\n'
},
'order': [
'Error',
@@ -94,11 +109,13 @@ describe('apiDoc full parse', function() {
it('memory should compare to fixtures', function(done) {
var timeRegExp = /\"time\"\:\s\"(.*)\"/g;
var versionRegExp = /\"version\"\:\s\"(.*)\"/g;
+ var filenameRegExp = new RegExp('(?!"filename":\\s")(' + exampleBasePath + '/)', 'g');
+
fixtureFiles.forEach(function(file) {
var key = file.key;
- var name = file.filename;
+ var name = fixturePath + '/' + file.filename;
- var fixtureContent = fs.readFileSync('test/fixtures/' + name, 'utf8');
+ var fixtureContent = fs.readFileSync(name, 'utf8');
var createdContent = api[key];
// creation time remove (never equal)
@@ -109,15 +126,20 @@ describe('apiDoc full parse', function() {
fixtureContent = fixtureContent.replace(versionRegExp, '');
createdContent = createdContent.replace(versionRegExp, '');
+ // remove the base path
+ createdContent = createdContent.replace(filenameRegExp, '');
+
+ // split and compare each line
+ // TODO: compare objects not line by line
var fixtureLines = fixtureContent.split(/\r\n/);
var createdLines = createdContent.split(/\r\n/);
if (fixtureLines.length !== createdLines.length)
- throw new Error('File ./tmp/' + name + ' not equals to test/fixtures/' + name);
+ throw new Error(key + ' not equals to ' + name);
for (var lineNumber = 0; lineNumber < fixtureLines.length; lineNumber += 1) {
if (fixtureLines[lineNumber] !== createdLines[lineNumber])
- throw new Error(key + ' not equals to test/fixtures/' + name + ' in line ' + (lineNumber + 1) +
+ throw new Error(key + ' not equals to ' + name + ' in line ' + (lineNumber + 1) +
'\nfixture: ' + fixtureLines[lineNumber] +
'\ncreated: ' + createdLines[lineNumber]
);
Oops, something went wrong.

0 comments on commit 64e9f46

Please sign in to comment.