-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: replace 'ava' my 'mocha' and 'should'
as it seems to be less magic, or at least I have a better understanding of it and it make it consistent with the other WikidataJS projects
- Loading branch information
Showing
15 changed files
with
417 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
const test = require('ava') | ||
require('should') | ||
const execa = require('execa') | ||
|
||
test('custom instance', t => { | ||
return execa.shell('./bin/wd label Q123456 --instance https://wikiyou.lala') | ||
.catch(err => { | ||
t.true(err.stderr.match(/getaddrinfo ENOTFOUND wikiyou\.lala/) != null) | ||
describe('general', function () { | ||
this.timeout(10000) | ||
|
||
it('should allow to customize the instance', done => { | ||
execa.shell('./bin/wd label Q123456 --instance https://wikiyou.lala') | ||
.catch(err => { | ||
err.stderr.match(/getaddrinfo ENOTFOUND wikiyou\.lala/).should.be.ok() | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
const test = require('ava') | ||
const should = require('should') | ||
const execa = require('execa') | ||
|
||
test('wd aliases: display help', t => { | ||
return execa.shell('./bin/wd aliases') | ||
.then(res => t.deepEqual(res.stdout.split('Usage:').length, 2)) | ||
}) | ||
describe('wd aliases', function () { | ||
this.timeout(10000) | ||
|
||
test('wd aliases <entity>', t => { | ||
return execa.shell('./bin/wd aliases Q123') | ||
.then(res => t.true(res.stdout.split('Sept').length > 1)) | ||
}) | ||
it('should display help', done => { | ||
execa.shell('./bin/wd aliases') | ||
.then(res => { | ||
res.stdout.split('Usage:').length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('<entity>', done => { | ||
execa.shell('./bin/wd aliases Q123') | ||
.then(res => { | ||
should(res.stdout.split('Sept').length > 1).be.true() | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('wd aliases <entity> should be tolerant on input', t => { | ||
return execa.shell('./bin/wd aliases azfzafzafazQ123fazafazfz') | ||
.then(res => t.true(res.stdout.split('Sept').length > 1)) | ||
it('<entity> should be tolerant on input', done => { | ||
execa.shell('./bin/wd aliases azfzafzafazQ123fazafazfz') | ||
.then(res => { | ||
should(res.stdout.split('Sept').length > 1).be.true() | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
const test = require('ava') | ||
require('should') | ||
const execa = require('execa') | ||
|
||
test('wd claims: display help', t => { | ||
return execa.shell('./bin/wd claims') | ||
.then(res => t.is(res.stdout.split('Usage:').length, 2)) | ||
}) | ||
describe('wd claims', function () { | ||
this.timeout(10000) | ||
|
||
test('wd claims <id>', t => { | ||
return execa.shell('./bin/wd claims Q3521413') | ||
.then(res => t.is(res.stdout.split('film (Q11424)').length, 2)) | ||
}) | ||
it('should display help when requested without argument', done => { | ||
execa.shell('./bin/wd claims') | ||
.then(res => { | ||
res.stdout.split('Usage:').length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('wd claims <id> <property>', t => { | ||
return execa.shell('./bin/wd claims Q3521413 P31') | ||
.then(res => t.is(res.stdout, 'Q11424')) | ||
}) | ||
it('should display all entity claims when passed an entity id', done => { | ||
execa.shell('./bin/wd claims Q3521413') | ||
.then(res => { | ||
res.stdout.split('film (Q11424)').length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('wd claims returns shell-friendly results when possible', t => { | ||
return execa.shell('./bin/wd claims Q90 P625') | ||
.then(res => t.is(res.stdout, '48.856577777778 2.3518277777778')) | ||
}) | ||
it('shoud display property claims when passed and entity id and a property id', done => { | ||
execa.shell('./bin/wd claims Q3521413 P31') | ||
.then(res => { | ||
res.stdout.should.equal('Q11424') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should return shell-friendly results when possible', done => { | ||
execa.shell('./bin/wd claims Q90 P625') | ||
.then(res => { | ||
res.stdout.should.equal('48.856577777778 2.3518277777778') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should accepts options before arguments', done => { | ||
execa.shell('./bin/wd claims -c Q90 P625') | ||
.then(res => { | ||
res.stdout.should.equal('48.856577777778 2.3518277777778') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('wd claims accepts options before', t => { | ||
return execa.shell('./bin/wd claims -c Q90 P625') | ||
.then(res => t.is(res.stdout, '48.856577777778 2.3518277777778')) | ||
it('should filters properties from text', done => { | ||
const coords = '48.856577777778,2.3518277777778' | ||
execa.shell('./bin/wd claims Q90 coord') | ||
.then(res => { | ||
res.stdout.split(coords).length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
const test = require('ava') | ||
require('should') | ||
const execa = require('execa') | ||
|
||
test('wd coord: display help', t => { | ||
return execa.shell('./bin/wd claims') | ||
.then(res => t.is(res.stdout.split('Usage:').length, 2)) | ||
}) | ||
describe('wd coord', function () { | ||
this.timeout(10000) | ||
|
||
it('display help', done => { | ||
execa.shell('./bin/wd claims') | ||
.then(res => { | ||
res.stdout.split('Usage:').length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('wd coord <id>', t => { | ||
return execa.shell('./bin/wd coord Q90') | ||
.then(res => t.is(res.stdout, '48.856577777778 2.3518277777778')) | ||
it('<id>', done => { | ||
execa.shell('./bin/wd coord Q90') | ||
.then(res => { | ||
res.stdout.should.equal('48.856577777778 2.3518277777778') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,94 @@ | ||
const test = require('ava') | ||
const should = require('should') | ||
const execa = require('execa') | ||
|
||
const attributes = [ 'pageid', 'ns', 'title', 'lastrevid', 'modified', 'type', 'id', 'labels', 'descriptions', 'aliases', 'claims', 'sitelinks' ] | ||
|
||
test('wd data: display help', t => { | ||
return execa.shell('./bin/wd data') | ||
.then(res => t.deepEqual(res.stdout.split('Usage:').length, 2)) | ||
}) | ||
describe('wd data', function () { | ||
this.timeout(10000) | ||
|
||
test('wd data <entity>', t => { | ||
return execa.shell('./bin/wd data Q123456') | ||
.then(res => { | ||
t.true(res.stdout.startsWith('{')) | ||
const data = JSON.parse(res.stdout) | ||
const dataAttrs = Object.keys(data) | ||
t.deepEqual(attributes.length, dataAttrs.length) | ||
dataAttrs.forEach(attr => t.true(attributes.indexOf(attr) > -1)) | ||
it('should display help', done => { | ||
execa.shell('./bin/wd data') | ||
.then(res => { | ||
res.stdout.split('Usage:').length.should.equal(2) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
test('wd data should accept several ids', t => { | ||
return execa.shell('./bin/wd data Q123456 Q123') | ||
.then(res => { | ||
t.true(res.stdout.startsWith('[')) | ||
const entities = JSON.parse(res.stdout) | ||
const dataAttrs = Object.keys(entities[0]) | ||
t.deepEqual(attributes.length, dataAttrs.length) | ||
dataAttrs.forEach(attr => t.true(attributes.indexOf(attr) > -1)) | ||
it('<entity>', done => { | ||
execa.shell('./bin/wd data Q123456') | ||
.then(res => { | ||
res.stdout.startsWith('{').should.be.true() | ||
const data = JSON.parse(res.stdout) | ||
const dataAttrs = Object.keys(data) | ||
attributes.length.should.equal(dataAttrs.length) | ||
dataAttrs.forEach(attr => should(attributes.indexOf(attr) > -1).be.true()) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
test('wd data should output entities as ndjson', t => { | ||
return execa.shell('./bin/wd data Q123456 Q1512522') | ||
.then(res => { | ||
t.is(res.stdout.split('\n').length, 4) | ||
it('should accept several ids', done => { | ||
execa.shell('./bin/wd data Q123456 Q123') | ||
.then(res => { | ||
res.stdout.startsWith('[').should.be.true() | ||
const entities = JSON.parse(res.stdout) | ||
const dataAttrs = Object.keys(entities[0]) | ||
attributes.length.should.equal(dataAttrs.length) | ||
dataAttrs.forEach(attr => should(attributes.indexOf(attr) > -1).be.true()) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
test('wd data should simplify entity when requested', t => { | ||
return execa.shell('./bin/wd data Q1512522 --simplify') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout) | ||
t.is(typeof entity.labels.de, 'string') | ||
t.is(typeof entity.descriptions.de, 'string') | ||
t.is(typeof entity.aliases.de[0], 'string') | ||
t.is(typeof entity.claims.P31[0], 'string') | ||
t.is(typeof entity.sitelinks.dewiki, 'string') | ||
it('should output entities as ndjson', done => { | ||
execa.shell('./bin/wd data Q123456 Q1512522') | ||
.then(res => { | ||
res.stdout.split('\n').length.should.equal(4) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
test('wd data should simplify entities when requested', t => { | ||
return execa.shell('./bin/wd data Q1512522 Q123456 --simplify') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout)[0] | ||
t.is(typeof entity.labels.de, 'string') | ||
t.is(typeof entity.descriptions.de, 'string') | ||
t.is(typeof entity.aliases.de[0], 'string') | ||
t.is(typeof entity.claims.P31[0], 'string') | ||
t.is(typeof entity.sitelinks.dewiki, 'string') | ||
it('should simplify entity when requested', done => { | ||
execa.shell('./bin/wd data Q1512522 --simplify') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout) | ||
entity.labels.de.should.be.a.String() | ||
entity.descriptions.de.should.be.a.String() | ||
entity.aliases.de[0].should.be.a.String() | ||
entity.claims.P31[0].should.be.a.String() | ||
entity.sitelinks.dewiki.should.be.a.String() | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should simplify entities when requested', done => { | ||
execa.shell('./bin/wd data Q1512522 Q123456 --simplify') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout)[0] | ||
entity.labels.de.should.be.a.String() | ||
entity.descriptions.de.should.be.a.String() | ||
entity.aliases.de[0].should.be.a.String() | ||
entity.claims.P31[0].should.be.a.String() | ||
entity.sitelinks.dewiki.should.be.a.String() | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
test('wd data should return only the desired props when requested', t => { | ||
return execa.shell('./bin/wd data Q1512522 --props labels,aliases') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout) | ||
t.is(typeof entity.labels, 'object') | ||
t.is(typeof entity.descriptions, 'undefined') | ||
t.is(typeof entity.aliases, 'object') | ||
t.is(typeof entity.claims, 'undefined') | ||
t.is(typeof entity.sitelinks, 'undefined') | ||
it('should return only the desired props when requested', done => { | ||
execa.shell('./bin/wd data Q1512522 --props labels,aliases') | ||
.then(res => { | ||
const entity = JSON.parse(res.stdout) | ||
should(entity.labels).be.an.Object() | ||
should(entity.descriptions).not.be.ok() | ||
should(entity.aliases).be.an.Object() | ||
should(entity.descriptions).not.be.ok() | ||
should(entity.sitelinks).not.be.ok() | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) |
Oops, something went wrong.