Skip to content

Commit

Permalink
8.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Sep 10, 2020
1 parent cd9059e commit 26e6704
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 55 deletions.
16 changes: 12 additions & 4 deletions builds/wtf_wikipedia-client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* wtf_wikipedia 8.4.0 MIT */
/* wtf_wikipedia 8.5.0 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.wtf = factory());
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.wtf = factory());
}(this, (function () { 'use strict';

var parseUrl = function parseUrl(url) {
Expand Down Expand Up @@ -8731,13 +8731,21 @@

var makeHeaders = function makeHeaders(options) {
var agent = options.userAgent || options['User-Agent'] || options['Api-User-Agent'] || 'User of the wtf_wikipedia library';
var origin;

if (options.noOrigin) {
origin = '';
} else {
origin = options.origin || options.Origin || '*';
}

var opts = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': agent,
'User-Agent': agent,
Origin: '*'
Origin: origin
},
redirect: 'follow'
};
Expand Down Expand Up @@ -8956,7 +8964,7 @@

var category = fetchCategory;

var _version = '8.4.0';
var _version = '8.5.0';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
Expand Down
2 changes: 1 addition & 1 deletion builds/wtf_wikipedia-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/wtf_wikipedia-client.mjs

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions builds/wtf_wikipedia.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* wtf_wikipedia 8.4.0 MIT */
/* wtf_wikipedia 8.5.0 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('https')) :
typeof define === 'function' && define.amd ? define(['https'], factory) :
(global = global || self, global.wtf = factory(global.https));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.wtf = factory(global.https));
}(this, (function (https) { 'use strict';

https = https && Object.prototype.hasOwnProperty.call(https, 'default') ? https['default'] : https;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var https__default = /*#__PURE__*/_interopDefaultLegacy(https);

var parseUrl = function parseUrl(url) {
var parsed = new URL(url); //eslint-disable-line
Expand Down Expand Up @@ -8724,7 +8726,7 @@
var request = function request(url) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Promise(function (resolve, reject) {
https.get(url, opts, function (resp) {
https__default['default'].get(url, opts, function (resp) {
var data = ''; // A chunk of data has been recieved.

resp.on('data', function (chunk) {
Expand All @@ -8749,13 +8751,21 @@

var makeHeaders = function makeHeaders(options) {
var agent = options.userAgent || options['User-Agent'] || options['Api-User-Agent'] || 'User of the wtf_wikipedia library';
var origin;

if (options.noOrigin) {
origin = '';
} else {
origin = options.origin || options.Origin || '*';
}

var opts = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': agent,
'User-Agent': agent,
Origin: '*'
Origin: origin
},
redirect: 'follow'
};
Expand Down Expand Up @@ -8974,7 +8984,7 @@

var category = fetchCategory;

var _version = '8.4.0';
var _version = '8.5.0';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
Expand Down
14 changes: 11 additions & 3 deletions builds/wtf_wikipedia.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* wtf_wikipedia 8.4.0 MIT */
/* wtf_wikipedia 8.5.0 MIT */
import https from 'https';

var parseUrl = function parseUrl(url) {
Expand Down Expand Up @@ -8743,13 +8743,21 @@ var server$1 = request;

var makeHeaders = function makeHeaders(options) {
var agent = options.userAgent || options['User-Agent'] || options['Api-User-Agent'] || 'User of the wtf_wikipedia library';
var origin;

if (options.noOrigin) {
origin = '';
} else {
origin = options.origin || options.Origin || '*';
}

var opts = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Api-User-Agent': agent,
'User-Agent': agent,
Origin: '*'
Origin: origin
},
redirect: 'follow'
};
Expand Down Expand Up @@ -8968,7 +8976,7 @@ var fetchCategory = function fetchCategory(category, lang, options) {

var category = fetchCategory;

var _version = '8.4.0';
var _version = '8.5.0';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
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",
Expand Down
2 changes: 1 addition & 1 deletion src/_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '8.4.0'
module.exports = '8.5.0'
8 changes: 4 additions & 4 deletions tests/fetch/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const test = require('tape')
const wtf = require('../lib')

function delay(time) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
return new Promise(function (resolve) {
setTimeout(function () {
resolve()
}, time)
})
}

test('test-array', async function(t) {
test('test-array', async function (t) {
let arr = [
['Toronto', 'Montreal'],
['R', 'π']
['R', 'π'],
]
for (const a of arr) {
let docs = await wtf.fetch(a)
Expand Down
67 changes: 33 additions & 34 deletions tests/fetch/fetch.test.js
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')

Expand All @@ -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)
})
})

0 comments on commit 26e6704

Please sign in to comment.