Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-provided test suite and assert @version correctly when specified (port of #179 to 0.5.x) #180

Open
wants to merge 9 commits into
base: 0.5.x
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,json,jsonld,yaml,yml}]
indent_style = space
indent_size = 2

[*.idl]
indent_style = space
indent_size = 4
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
*.sw[op]
*.sw[nop]
*~
.bower.json
.cdtproject
.classpath
.cproject
.project
*.sublime-project
*.sublime-workspace
.DS_Store
.settings
TAGS
coverage
dist
node_modules
v8.log
51 changes: 21 additions & 30 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
# jsonld ChangeLog

## [Unreleased]
## Unreleased

## [0.4.11] - 2016-04-24
### Changed
- Move `js/jsonld.js` to `lib/jsonld.js`.

### Added
- Add .editorconfig support.

## 0.4.11 - 2016-04-24

### Changed
- Add optimization for finding best CURIE matches.

## [0.4.10] - 2016-04-24
## 0.4.10 - 2016-04-24

### Changed
- Add optimization for compacting keywords.

## [0.4.9] - 2016-04-23
## 0.4.9 - 2016-04-23

### Changed
- Add optimizations for _compactIri.
- Add optimizations for \_compactIri.

## [0.4.8] - 2016-04-14
## 0.4.8 - 2016-04-14

### Fixed
- Revert es6-promise dependency to 2.x to avoid auto-polyfill behavior.

## [0.4.7] - 2016-04-14
## 0.4.7 - 2016-04-14

### Fixed
- Testing document loader.

## [0.4.6] - 2016-03-02
## 0.4.6 - 2016-03-02

### Added
- Add `headers` and `request` option for node doc loader.

### Changed
- Include local tests.

## [0.4.5] - 2016-01-19
## 0.4.5 - 2016-01-19

### Fixed
- N-Quads comments pattern.
- Local tests.

## [0.4.4] - 2016-01-08
## 0.4.4 - 2016-01-08

### Fixed
- Document cache in default node document loader is broken; disable
until HTTP caching is implemented.

## [0.4.3] - 2016-01-05
## 0.4.3 - 2016-01-05

### Fixed
- N-Quads may contain comments.

## [0.4.2] - 2015-10-12
## 0.4.2 - 2015-10-12

### Added
- Add inputFormat and algorithm options to normalize.
Expand All @@ -65,12 +71,12 @@
### Fixed
- Ignore null values in language maps.

## [0.4.1] - 2015-09-12
## 0.4.1 - 2015-09-12

### Changed
- Ignore jsonld-request and pkginfo for browserify.

## [0.4.0] - 2015-09-12
## 0.4.0 - 2015-09-12

### Breaking Changes
- "request" extension moved to [jsonld-request][]. This was done to simplify
Expand All @@ -82,26 +88,11 @@
core JSON-LD processing library and because it uses the [jsonld-request][]
module.

## [0.3.26] - 2015-09-01
## 0.3.26 - 2015-09-01

## Before 0.3.26

- See git history for changes.

[jsonld-cli]: https://github.com/digitalbazaar/jsonld-cli
[jsonld-request]: https://github.com/digitalbazaar/jsonld-request

[Unreleased]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.11...HEAD
[0.4.11]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.10...0.4.11
[0.4.10]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.9...0.4.10
[0.4.9]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.8...0.4.9
[0.4.8]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.7...0.4.8
[0.4.7]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.6...0.4.7
[0.4.6]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.5...0.4.6
[0.4.5]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.4...0.4.5
[0.4.4]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.3...0.4.4
[0.4.3]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.2...0.4.3
[0.4.2]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.1...0.4.2
[0.4.1]: https://github.com/digitalbazaar/jsonld.js/compare/0.4.0...0.4.1
[0.4.0]: https://github.com/digitalbazaar/jsonld.js/compare/0.3.26...0.4.0
[0.3.26]: https://github.com/digitalbazaar/jsonld.js/compare/0.3.25...0.3.26
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TESTS = tests/test.js
LOCAL_TESTS = test/*.js
REPORTER = spec
JSONLD_TEST_SUITE=node_modules/json-ld-test-suite

all:

Expand All @@ -13,7 +15,7 @@ test-suite-node:
exit 1; \
fi
@if [ -d $(JSONLD_TEST_SUITE) ]; then \
NODE_ENV=test ./node_modules/.bin/mocha -A -R $(REPORTER) $(TESTS); \
NODE_ENV=test ./node_modules/.bin/mocha -t 30000 -A -R $(REPORTER) $(TESTS); \
else \
echo "Error: tests not found at $(JSONLD_TEST_SUITE)"; \
exit 1; \
Expand Down Expand Up @@ -51,10 +53,17 @@ test-normalization-browser:

test-coverage:
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \
-u exports -R $(REPORTER) $(TESTS)
-t 30000 -u exports -R $(REPORTER) $(TESTS)

test-coverage-lcov:
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha \
--report lcovonly -- -t 30000 -u exports -R $(REPORTER) $(TESTS)

test-coverage-report:
./node_modules/.bin/istanbul report

test-local:
./node_modules/.bin/mocha
./node_modules/.bin/mocha -t 30000 -R $(REPORTER) $(LOCAL_TESTS)

clean:
rm -rf coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bower install jsonld
```js
require.config({
paths: {
jsonld: 'bower_components/jsonld/js/jsonld'
jsonld: 'bower_components/jsonld/lib/jsonld'
}
});
define(['jsonld'], function(jsonld) { ... });
Expand Down
20 changes: 16 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"name": "jsonld",
"version": "0.4.12-dev",
"description": "A JSON-LD Processor and API implementation in JavaScript.",
"keywords": [
"JSON",
"Linked Data",
"JSON-LD",
"RDF",
"Semantic Web",
"jsonld"
],
"authors": [
"Digital Bazaar, Inc."
"Digital Bazaar, Inc. <[email protected]> (http://digitalbazaar.com/)"
],
"license": "BSD",
"main": ["js/jsonld.js"],
"license": "BSD-3-Clause",
"homepage": "http://github.com/digitalbazaar/jsonld.js",
"repository": {
"type": "git",
"url": "http://github.com/digitalbazaar/jsonld.js"
},
"main": ["lib/jsonld.js"],
"dependencies": {
"es6-promise": "^2.0.0"
},
Expand Down
9 changes: 9 additions & 0 deletions js/jsonld.js → lib/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -5731,6 +5731,15 @@ function _createTermDefinition(activeCtx, localCtx, term, defined) {
{code: 'keyword redefinition', context: localCtx, term: term});
}

if(term === '@version') {
if(value !== 1.1) {
throw new JsonLdError(
'Invalid JSON-LD syntax; version must be 1.1 if specified',
'jsonld.SyntaxError',
{code: 'invalid @version value', context: localCtx});
}
}

if(term === '') {
throw new JsonLdError(
'Invalid JSON-LD syntax; a term cannot be an empty string.',
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonld",
"version": "0.4.12-dev",
"version": "0.5.0-dev",
"description": "A JSON-LD Processor and API implementation in JavaScript.",
"homepage": "http://github.com/digitalbazaar/jsonld.js",
"author": {
Expand All @@ -9,10 +9,8 @@
"url": "http://digitalbazaar.com/"
},
"contributors": [
{
"name": "Dave Longley",
"email": "[email protected]"
}
"Dave Longley <[email protected]>",
"David I. Lehn <[email protected]>"
],
"repository": {
"type": "git",
Expand All @@ -23,15 +21,15 @@
"email": "[email protected]"
},
"license": "BSD-3-Clause",
"main": "js/jsonld.js",
"main": "lib/jsonld.js",
"dependencies": {
"es6-promise": "^2.0.0",
"json-ld-test-suite": "^1.0.1",
"pkginfo": "~0.4.0",
"request": "^2.61.0",
"xmldom": "0.1.19"
},
"devDependencies": {
"chai": "^3.4.1",
"commander": "^2.8.0",
"cors": "^2.7.1",
"express": "^4.13.3",
Expand Down Expand Up @@ -59,8 +57,9 @@
"test-browser": "make test-browser",
"test": "make test",
"coverage": "make test-coverage",
"jscs": "jscs js/jsonld.js tests/*.js",
"jshint": "jshint js/jsonld.js tests/*.js"
"coverage-report": "make test-coverage-report",
"jscs": "jscs lib/jsonld.js tests/*.js",
"jshint": "jshint lib/jsonld.js tests/*.js"
},
"browser": {
"crypto": "./browser/ignore.js",
Expand Down
9 changes: 6 additions & 3 deletions test/node-document-loader-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author goofballLogic
*/
var jsonld = require('../js/jsonld');
var jsonld = require('..');
var assert = require('assert');

describe('For the node.js document loader', function() {
Expand All @@ -16,9 +16,12 @@ describe('For the node.js document loader', function() {

describe('When built with no options specified', function() {
var options = {};
it('loading should work', function(callback) {
it('loading should work', function(done) {
jsonld.useDocumentLoader(documentLoaderType);
jsonld.expand('http://schema.org/', callback);
jsonld.expand('http://schema.org/', function(err, expanded) {
assert.ifError(err);
done();
});
});
});

Expand Down
6 changes: 3 additions & 3 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _nodejs = (typeof process !== 'undefined' &&
process.versions && process.versions.node);

if(_nodejs) {
var _jsdir = getEnv().JSDIR || 'js';
var _jsdir = getEnv().JSDIR || 'lib';
var fs = require('fs');
var path = require('path');
var jsonld = require('../' + _jsdir + '/jsonld')();
Expand Down Expand Up @@ -60,11 +60,11 @@ if(_nodejs) {
var fs = require('fs');
var system = require('system');
require('./setImmediate');
var _jsdir = getEnv().JSDIR || 'js';
var _jsdir = getEnv().JSDIR || 'lib';
require('../' + _jsdir + '/jsonld');
jsonld = jsonldjs;
window.Promise = require('es6-promise').Promise;
var assert = require('chai').assert;
var assert = require('assert');
require('mocha/mocha');
require('mocha-phantomjs/lib/mocha-phantomjs/core_extensions');
var program = {};
Expand Down