Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #95 from apiaryio/pksunkara/drafter-4
Browse files Browse the repository at this point in the history
Update protagonist
  • Loading branch information
pksunkara authored Sep 6, 2018
2 parents 255b1db + 4f57e89 commit cdf1ebe
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
docker:
- image: apiaryio/emcc:1.38.11
steps:
- checkout
- run: apt-get install -y git-core
- checkout
- run: git submodule update --recursive --init
- run: npm install
- run: ./scripts/wrap.js
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# drafter.js Changelog

## 3.0.0-pre.1

This update now uses Drafter 4.0.0-pre.1. Please see [Drafter
4.0.0-pre.1](https://github.com/apiaryio/drafter/releases/tag/v4.0.0-pre.1) for
the list of changes.

- Build done using emscripten 1.38.x

### Breaking

- `parse` returns parse result in both `err` and `result` of the callback function
- `parseSync` doesn't throw error anymore if we get a parse result with error annotations

## 3.0.0-pre.0

This update now uses Drafter 4.0.0-pre.0. Please see [Drafter
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drafter.js",
"version": "3.0.0-pre.0",
"version": "3.0.0-pre.1",
"description": "Pure JS Drafter built with Emscripten",
"main": "lib/drafter.nomem.js",
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions scripts/emcbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ mkdir -p lib

em++ $FLAGS "build/out/$BUILD_TYPE/libdrafterjs.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libdrafter.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsos.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsnowcrash.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsundown.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libmarkdownparser.a" \
Expand All @@ -103,7 +102,6 @@ em++ $FLAGS "build/out/$BUILD_TYPE/libdrafterjs.a" \
em++ $FLAGS --memory-init-file 0 \
"build/out/$BUILD_TYPE/libdrafterjs.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libdrafter.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsos.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsnowcrash.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libsundown.a" \
"$DRAFTER_PATH/build/out/$BUILD_TYPE/libmarkdownparser.a" \
Expand Down
11 changes: 4 additions & 7 deletions src/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ Module['parse'] = function(blueprint, options, callback) {

result = (options && options.json === false) ? output : JSON.parse(output);

if (res) {
if (callback) {
if (callback) {
if (res) {
return callback(result, result);
} else {
return callback(null, result);
}
throw result;
}

if (callback) {
return callback(null, result);
}

return result;
Expand Down
139 changes: 139 additions & 0 deletions test/options-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
var assert = require('chai').assert;
var path = require('path');
var fs = require('fs');
var drafter = require('../lib/drafter.nomem.js');

var fixture_path = path.join(__dirname, '../ext/protagonist/test/fixtures/sample-api.apib');
var expected_err = require('../ext/protagonist/test/fixtures/sample-api-error.json');

describe('Requiring Blueprint name with sourcemaps', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.parse(data, { requireBlueprintName: true, generateSourceMap: true }, function (err, result) {
// if (err) {
// return done(err);
// }

refract_err = result;
done();
});
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});

describe('Requiring Blueprint name without sourcemaps', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.parse(data, { requireBlueprintName: true, generateSourceMap: false }, function (err, result) {
// if (err) {
// return done(err);
// }

refract_err = result;
done();
});
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});

describe('Requiring Blueprint name with sourcemaps using sync', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

refract_err = drafter.parseSync(data, { requireBlueprintName: true, generateSourceMap: true });
done();
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});

describe('Requiring Blueprint name without sourcemaps using sync', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

refract_err = drafter.parseSync(data, { requireBlueprintName: true, generateSourceMap: false });
done();
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});

describe('Requiring Blueprint name with validate', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.validate(data, { requireBlueprintName: true }, function (err, result) {
if (err) {
return done(err);
}

refract_err = result;
done();
});
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});

describe('Requiring Blueprint name with validate sync', function () {
var refract_err = null;

before(function (done) {
fs.readFile(fixture_path, 'utf8', function (err, data) {
if (err) {
return done(err);
}

refract_err = drafter.validateSync(data, { requireBlueprintName: true });
done();
});
});

it('conforms to the refract spec', function () {
assert.deepEqual(refract_err, expected_err);
});
});
4 changes: 2 additions & 2 deletions test/parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ describe('Parse fixture', function () {

after(function () {
console.log();
console.log('=========================');
console.log('=================');
console.log('Average JS speed: ' + (jsTime / cppTime).toFixed(1) + ' times slower than C++ (exec) and ' + (jsTime / nodeTime).toFixed(1) + ' times slower than Protagonist');
console.log('=========================');
console.log('=================');
});

fixtures.forEach(function (fixture) {
Expand Down
143 changes: 143 additions & 0 deletions test/validate-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
var assert = require('chai').assert;
var path = require('path');
var fs = require('fs');
var drafter = require('../lib/drafter.nomem.js');

var valid_fixture = path.join(__dirname, '../ext/protagonist/test/fixtures/sample-api.apib');
var warning_fixture = path.join(__dirname, '../ext/protagonist/test/fixtures/invalid-api-warning.apib');
var error_fixture = path.join(__dirname, '../ext/protagonist/test/fixtures/invalid-api-error.apib');

var warning_refract = require('../ext/protagonist/test/fixtures/invalid-api-warning.json');
var error_refract = require('../ext/protagonist/test/fixtures/invalid-api-error.json');

describe('Validate Blueprint with error - Sync', function () {
var parsed = null;

before(function (done) {
fs.readFile(error_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

parsed = drafter.validateSync(data);
done();
});
});

it('Result contains annotations only', function () {
assert.deepEqual(parsed, error_refract);
});
});

describe('Validate Blueprint with warning - Sync', function () {
var parsed = null;

before(function (done) {
fs.readFile(warning_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

parsed = drafter.validateSync(data);
done();
});
});

it('Result contains annotations only', function () {
assert.deepEqual(parsed, warning_refract);
});
});

describe('Validate valid Blueprint - Sync', function () {
var parsed = 1;

before(function (done) {
fs.readFile(valid_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

parsed = drafter.validateSync(data);
done();
});
});

it('will return null', function () {
assert.isNull(parsed);
});
});

describe('Validate Blueprint with error - Async', function () {
var parsed = null;

before(function (done) {
fs.readFile(error_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.validate(data, {}, function (err, result) {
if (err) {
return done(err);
}

parsed = result;
done();
});
});
});

it('Result contains annotations only', function () {
assert.deepEqual(parsed, error_refract);
});
});

describe('Validate Blueprint with warning - Async', function () {
var parsed = null;

before(function (done) {
fs.readFile(warning_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.validate(data, {}, function (err, result) {
if (err) {
return done(err);
}

parsed = result;
done();
});
});
});

it('Result contains annotations only', function () {
assert.deepEqual(parsed, warning_refract);
});
});

describe('Validate valid Blueprint - Async', function () {
var parsed = 1;

before(function (done) {
fs.readFile(valid_fixture, 'utf8', function (err, data) {
if (err) {
return done(err);
}

drafter.validate(data, {}, function (err, result) {
if (err) {
return done(err);
}

parsed = result;
done();
});
});
});

it('will return null', function () {
assert.isNull(parsed);
});
});

0 comments on commit cdf1ebe

Please sign in to comment.