Skip to content

Commit

Permalink
tests: replace 'ava' my 'mocha' and 'should'
Browse files Browse the repository at this point in the history
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
maxlath committed Dec 16, 2017
1 parent 7a9b37f commit 1096e61
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 207 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"wikidata-cli": "./bin/wikidata-cli"
},
"scripts": {
"test": "ava",
"test": "mocha",
"postinstall": "check-node-version --node '>= 6.4.0'",
"prepublishOnly": "npm run lint && npm test",
"lint": "standard",
Expand Down Expand Up @@ -44,11 +44,21 @@
"wikidata-sdk": "^5.3.1"
},
"devDependencies": {
"ava": "^0.18.2",
"doctoc": "^1.3.0",
"git-hooks": "^1.1.8",
"mocha": "^4.0.1",
"should": "^13.1.3",
"standard": "^9.0.2"
},
"standard": {
"ignore": [
"dist"
],
"globals": [
"it",
"describe"
]
},
"engines": {
"node": ">= 6.4.0"
}
Expand Down
15 changes: 10 additions & 5 deletions test/general.js
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()
})
})
})
40 changes: 28 additions & 12 deletions test/wd-aliases.js
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)
})
})
74 changes: 54 additions & 20 deletions test/wd-claims.js
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)
})
})
28 changes: 20 additions & 8 deletions test/wd-coord.js
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)
})
})
134 changes: 77 additions & 57 deletions test/wd-data.js
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)
})
})
Loading

0 comments on commit 1096e61

Please sign in to comment.