Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dbpedia-entity-lookup

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbpedia-entity-lookup - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

babel.config.js

76

package.json
{
"name": "dbpedia-entity-lookup",
"version": "0.5.0",
"version": "0.6.0",
"description": "Find entities (people, places, organizations, titles) in dbpedia.",

@@ -24,39 +24,24 @@ "main": "src/index.js",

"cm": "git-cz",
"precommit": "npm run test && npm run check-coverage",
"browserify": "mkdirp build && browserify test/development.js -o build/development.js --debug -t [ babelify --presets [ es2015 ] ]",
"watch": "mkdirp build && watchify test/development.js -o build/development.js --debug --verbose -t [ babelify --presets [ es2015 ] ]",
"test": "mkdirp .nyc_output && npm run test:electron && npm run generate-coverage",
"test:watch": "cross-env NODE_ENV=test mkdirp build && watchify test/browser.js -o build/development.js --debug --verbose -t [ babelify --presets [ es2015 ] --plugins [ istanbul ] ]",
"test:browser": "cross-env NODE_ENV=test browserify test/browser.js | browser-run -p 2222 | node test/extract-coverage.js | faucet",
"test:electron": "cross-env NODE_ENV=test browserify test/browser.js | browser-run | node test/extract-coverage.js | faucet ",
"test:chrome": "cross-env NODE_ENV=test browserify test/browser.js | browser-run -b chrome | node test/extract-coverage.js | faucet ",
"generate-coverage": "nyc report --reporter=lcov",
"check-coverage": "nyc check-coverage --statements 90 --branches 90 --functions 90 --lines 90",
"report-coverage": "cat ./.nyc_output/coverage.json | codecov",
"browserify": "mkdirp build && browserify test/development.js -o build/development.js --debug",
"watch": "mkdirp build && watchify test/development.js -o build/development.js --debug --verbose",
"test": "jest",
"report-coverage": "cat ./coverage/coverage-final.json | codecov",
"travis-deploy-once": "travis-deploy-once"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-istanbul": "^4.1.6",
"babel-preset-es2015": "6.24.1",
"babelify": "^8.0.0",
"browser-run": "^6.0.0",
"@babel/core": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/runtime-corejs2": "^7.5.5",
"babelify": "^10.0.0",
"browserify": "^16.2.3",
"browserify-istanbul": "^3.0.1",
"codecov": "^3.5.0",
"commitizen": "^3.1.1",
"concat-stream": "^2.0.0",
"cross-env": "5.2.0",
"cz-conventional-changelog": "^2.1.0",
"faucet": "0.0.1",
"fetch-mock": "^5.13.1",
"husky": "^2.1.0",
"jest": "^24.9.0",
"mkdirp": "0.5.1",
"nyc": "^14.1.1",
"semantic-release": "^15.13.12",
"sinon": "^7.3.2",
"tape": "^4.10.2",
"tape-promise": "^4.0.0",
"travis-deploy-once": "^5.0.11",
"watch": "1.0.2",
"watchify": "^3.11.1"

@@ -71,25 +56,24 @@ },

"hooks": {
"pre-commit": "npm run test && npm run check-coverage"
"pre-commit": "npm run test"
}
},
"dependencies": {},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015"
],
"env": {
"test": {
"plugins": [
"istanbul"
]
}
}
}
]
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"./src/index.js"
],
"coverageDirectory": "./coverage",
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 90,
"lines": 90,
"statements": 90
}
},
"testMatch": [
"**/test/**/*.[jt]s?(x)"
]
}
},
"dependencies": {}
}
'use strict';
let dbpedia = require('../src/index.js');
const path = require('path')
const tape = require('tape');
var _test = require('tape-promise').default;
const test = _test(tape) // decorate tape to allow promises
const sinon = require('sinon')
const fetchMock = require('fetch-mock');

@@ -21,26 +17,18 @@

var clock;
// setup server mocks for each type of call
[
{uriBuilderFn: 'getPersonLookupURI', testFixture:resultsFixture},
{uriBuilderFn: 'getPlaceLookupURI', testFixture:resultsFixture},
{uriBuilderFn: 'getOrganizationLookupURI', testFixture:resultsFixture},
{uriBuilderFn: 'getTitleLookupURI', testFixture:resultsFixture},
{uriBuilderFn: 'getRSLookupURI', testFixture:resultsFixture}
].forEach(entityLookup=> {
{ uriBuilderFn: 'getPersonLookupURI', testFixture: resultsFixture },
{ uriBuilderFn: 'getPlaceLookupURI', testFixture: resultsFixture },
{ uriBuilderFn: 'getOrganizationLookupURI', testFixture: resultsFixture },
{ uriBuilderFn: 'getTitleLookupURI', testFixture: resultsFixture },
{ uriBuilderFn: 'getRSLookupURI', testFixture: resultsFixture }
].forEach(entityLookup => {
let uriBuilderFn = dbpedia[entityLookup.uriBuilderFn];
let uriBuilderFn = dbpedia[entityLookup.uriBuilderFn];
fetchMock.get(uriBuilderFn(queryString), entityLookup.testFixture);
fetchMock.get(uriBuilderFn(queryStringWithNoResults), emptyResultFixture);
fetchMock.get(uriBuilderFn(queryStringForTimeout), (url, opts)=> {
// This function that we are in is called by fetchMock, instead of calling fetch itself.
// We use sinon to advance time without having to actually wait the 8 seconds.
clock.tick(8100);
// at this point in time, i.e. after 8 seconds have passed, the wrapper we have around our fetch call should have timed out,
// and returned a rejected promise.
clock.restore();
// return the promise that fetchMock is expecting, to avoid errors
Promise.resolve()
fetchMock.get(uriBuilderFn(queryStringForTimeout), (url, opts) => {
setTimeout(Promise.resolve, 8100);
});

@@ -51,15 +39,4 @@ fetchMock.get(uriBuilderFn(queryStringForError), 500);

// babel-plugin-istanbul adds instrumentation to the browserified/babelified bundle, during babelification.
// When the tests are run on the browserified/babelified bundle, the instrumentation records test coverage and puts it in
// the global scope (which in the browser is 'window'.) So when the tests finish, we get the test coverage output
// from window.__coverage__ , prepend '# coverage', and then append all of it to the TAPE console output (which also has the tape test results).
// We prepend '# coverage' to the coverage information, so we can easily find it later
// when we extract the coverage in the node test/extract-coverage.js command, used in the test scripts in package.json
test.onFinish(()=>{
console.log('# coverage:', JSON.stringify(window.__coverage__))
window.close()
});
// from https://stackoverflow.com/a/35047888
function doObjectsHaveSameKeys(...objects){
function doObjectsHaveSameKeys(...objects) {
const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);

@@ -70,21 +47,19 @@ const union = new Set(allKeys);

test('lookup builders', (assert)=> {
assert.plan(5);
test('lookup builders', () => {
expect.assertions(5);
['getPersonLookupURI', 'getPlaceLookupURI', 'getOrganizationLookupURI', 'getTitleLookupURI', 'getRSLookupURI'].forEach(uriBuilderMethod => {
assert.comment(uriBuilderMethod);
assert.ok(dbpedia[uriBuilderMethod](queryString).includes(queryString), 'should contain the query string');
expect(dbpedia[uriBuilderMethod](queryString).includes(queryString)).toBe(true);
});
});
['findPerson', 'findPlace', 'findOrganization', 'findTitle', 'findRS'].forEach((nameOfLookupFn)=> {
test(nameOfLookupFn, async function(assert){
let thisAssert = assert
// thisAssert.plan(21);
['findPerson', 'findPlace', 'findOrganization', 'findTitle', 'findRS'].forEach((nameOfLookupFn) => {
test(nameOfLookupFn, async () => {
expect.assertions(21);
let lookupFn = dbpedia[nameOfLookupFn];
thisAssert.equal(typeof lookupFn, 'function', 'is a function');
expect(typeof lookupFn).toBe('function');
let results = await lookupFn(queryString);
thisAssert.ok(Array.isArray(results), 'should return an array of results');
thisAssert.ok(results.length <= expectedResultLength, `should return fewer than or equal to ${expectedResultLength} results`);
expect(Array.isArray(results)).toBe(true);
expect(results.length).toBeLessThanOrEqual(expectedResultLength);
results.forEach(singleResult => {
thisAssert.ok(doObjectsHaveSameKeys(singleResult, {
expect(doObjectsHaveSameKeys(singleResult, {
nameType: '',

@@ -98,49 +73,43 @@ id: '',

description: ''
}), 'all results have correct keys')
thisAssert.equal(singleResult.originalQueryString, queryString, 'each result should return the original query string')
})).toBe(true);
expect(singleResult.originalQueryString).toBe(queryString);
})
thisAssert.comment('with a result from dbpedia with no Description');
// with a result from dbpedia with no Description
results = await lookupFn(queryStringForMissingDescriptionInResult);
thisAssert.ok(Array.isArray(results), 'should return an array of results');
thisAssert.ok(doObjectsHaveSameKeys(results[0], {
nameType: '',
id: '',
uri: '',
uriForDisplay: '',
name: '',
repository: '',
originalQueryString: '',
description: ''
}), 'should still have all correct keys')
thisAssert.equal(results[0].description, 'No description available', 'should show missing description message')
expect(Array.isArray(results)).toBe(true);
expect(doObjectsHaveSameKeys(results[0], {
nameType: '',
id: '',
uri: '',
uriForDisplay: '',
name: '',
repository: '',
originalQueryString: '',
description: ''
})).toBe(true);
expect(results[0].description).toBe('No description available');
thisAssert.comment('with no results');
// with no results
results = await lookupFn(queryStringWithNoResults);
thisAssert.ok(Array.isArray(results), 'should return an array');
thisAssert.equal(results.length, 0, `should return an empty array`)
expect(Array.isArray(results)).toBe(true);
expect(results.length).toBe(0);
thisAssert.comment('with a server error');
// with a server error
let shouldBeNullResult = false;
shouldBeNullResult = await lookupFn(queryStringForError).catch(error=>{
thisAssert.true(true, 'an http error should reject the promise');
return false;
shouldBeNullResult = await lookupFn(queryStringForError).catch(error => {
// an http error should reject the promise
expect(true).toBe(true);
return false;
})
thisAssert.comment('a falsey result should be returned')
thisAssert.notOk(shouldBeNullResult, 'should be falsey');
// a falsey result should be returned
expect(shouldBeNullResult).toBeFalsy();
thisAssert.comment('when query times out');
// use sinon to override the clock used for setTimeout
// We manually advance the clock up in the mock
clock = sinon.useFakeTimers({
now: Date.now(),
toFake: ["setTimeout"]
});
// when query times out
try {
await lookupFn(queryStringForTimeout);
await lookupFn(queryStringForTimeout);
} catch (err) {
thisAssert.ok(true, 'the promise should be rejected')
// the promise should be rejected
expect(true).toBe(true);
}
thisAssert.end()
})

@@ -147,0 +116,0 @@ })

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc