-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd9059e
commit 26e6704
Showing
9 changed files
with
80 additions
and
55 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,7 +1,7 @@ | ||
{ | ||
"name": "wtf_wikipedia", | ||
"description": "parse wikiscript into json", | ||
"version": "8.4.0", | ||
"version": "8.5.0", | ||
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)", | ||
"repository": { | ||
"type": "git", | ||
|
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 +1 @@ | ||
module.exports = '8.4.0' | ||
module.exports = '8.5.0' |
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,103 +1,102 @@ | ||
var test = require('tape') | ||
var wtf = require('../lib') | ||
|
||
test('fetch-as-promise', t => { | ||
test('fetch-as-promise', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch('Tony Hawk', 'en', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>' | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
}) | ||
p.then(function(doc) { | ||
p.then(function (doc) { | ||
t.ok(doc.sections().length > 0, 'promise returned document') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
test('fetch-as-callback', t => { | ||
test('fetch-as-callback', (t) => { | ||
t.plan(1) | ||
wtf.fetch('Tony Danza', 'en', function(err, doc) { | ||
wtf.fetch('Tony Danza', 'en', function (err, doc) { | ||
if (err) { | ||
t.throw(err) | ||
} | ||
t.ok(doc.categories().length > 0, 'callback returned document') | ||
}) | ||
}) | ||
|
||
test('fetch-invalid', t => { | ||
test('fetch-invalid', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch('Taylor%20Swift', 'en', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>' | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
}) | ||
p.then(function(doc) { | ||
p.then(function (doc) { | ||
t.ok(doc === null, 'invalid character query returns null') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
test('fetch-missing', t => { | ||
test('fetch-missing', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch('NonExistentPage', 'en', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>' | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
}) | ||
p.then(function(doc) { | ||
p.then(function (doc) { | ||
t.ok(doc === null, 'fetching non-existent page returns null') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
test('fetch-redirect', t => { | ||
test('fetch-redirect', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch('USA', { | ||
lang: 'simple', | ||
follow_redirects: false, | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>' | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
}) | ||
p.then(function(doc) { | ||
p.then(function (doc) { | ||
t.ok(doc.isRedirect(), 'got redirect') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
test('fetch-alternate-wiki', t => { | ||
test('fetch-alternate-wiki', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch(336711, 'en', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
domain: 'www.mixesdb.com', | ||
path: 'db/api.php' | ||
path: 'db/api.php', | ||
}) | ||
p.then(function(doc) { | ||
p.then(function (doc) { | ||
t.ok(doc.sections().length > 0, 'alternate wiki returned document') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
test('fetch-alternate-wiki-with-no-origin', t => { | ||
test('fetch-alternate-wiki-with-no-origin', (t) => { | ||
t.plan(1) | ||
var p = wtf.fetch('Abyssal whip', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
domain: 'oldschool.runescape.wiki', | ||
noOrigin: true | ||
noOrigin: true, | ||
}) | ||
p.then(function(doc) { | ||
console.log(doc) | ||
p.then(function (doc) { | ||
t.ok(doc.sections().length > 0, 'alternate wiki different origin success') | ||
}) | ||
p.catch(function(e) { | ||
p.catch(function (e) { | ||
t.throw(e) | ||
}) | ||
}) | ||
|
||
//uncomment for testing on node>6 | ||
test('ambiguous-pageids', async function(t) { | ||
test('ambiguous-pageids', async function (t) { | ||
var doc = await wtf.fetch(1984, 'en') | ||
t.equal(doc.title(), 'Arab world', 'input as pageid') | ||
|
||
|
@@ -116,23 +115,23 @@ test('ambiguous-pageids', async function(t) { | |
t.end() | ||
}) | ||
|
||
test('intensive', t => { | ||
test('intensive', (t) => { | ||
/* fires a bunch of requests in parallel - this should be enough to get blocked by wikipedia if the user agent is not set correctly */ | ||
var pages = ['Mouse', 'Rat', 'Porcupine', 'Chipmunk', 'Vole', 'Chinchilla', 'Gopher', 'Capybara', 'Beaver', 'Hamster'] | ||
t.plan(pages.length) | ||
var promises = pages.map(page => | ||
var promises = pages.map((page) => | ||
wtf.fetch(page, 'en', { | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>' | ||
'Api-User-Agent': 'wtf_wikipedia test script - <[email protected]>', | ||
}) | ||
) | ||
Promise.all(promises) | ||
.then(results => { | ||
results.forEach(result => { | ||
.then((results) => { | ||
results.forEach((result) => { | ||
t.ok(result.title(), 'got a page') | ||
}) | ||
t.end() | ||
}) | ||
.catch(e => { | ||
.catch((e) => { | ||
t.error(e, e) | ||
}) | ||
}) |