Skip to content

Commit

Permalink
Merge cbd0e7d into 74bc8b6
Browse files Browse the repository at this point in the history
  • Loading branch information
jdforrester committed Jun 21, 2018
2 parents 74bc8b6 + cbd0e7d commit 8776d21
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
4 changes: 1 addition & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const phpCharToUpper = require('./mediawiki.Title.phpCharToUpper.js');
* @type {string}
* @const
*/
// We're using String.fromCharCode because the symbol itself is not liked by JSCS
// and String.fromCodePoint() is around only starting from ES6
const UTF_8_REPLACEMENT = String.fromCharCode(0xFFFD);
const UTF_8_REPLACEMENT = "�";

// Polyfill for array.find for node 0.10 support.
function arrayFind(array, predicate) {
Expand Down
2 changes: 0 additions & 2 deletions lib/mediawiki.Title.phpCharToUpper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

// This file can't be parsed by JSDuck due to <https://github.com/tenderlove/rkelly/issues/35>.
// (It is excluded in jsduck.json.)
// ESLint suggests unquoting some object keys, which would render the file unparseable by Opera 12.
/* eslint-disable quote-props */
(function() {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"mocha-eslint": "^4.1.0",
"mocha-jshint": "^2.3.1",
"mocha-lcov-reporter": "^1.3.0",
"preq": "^0.5.6"
}
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends: '../.eslintrc.yml'
globals: {
'describe': false,
'it': false
}
39 changes: 20 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const utils = require('../lib/utils');
const preq = require('preq');

// Run eslint as part of normal testing
require('mocha-eslint')([ 'lib' ]);
// Run jshint as part of normal testing
require('mocha-jshint')();
require('mocha-eslint')([ 'lib', 'test' ]);

const doTest = (formatversion) => {
const siteInfoCache = {};
Expand All @@ -18,13 +16,13 @@ const doTest = (formatversion) => {
}

siteInfoCache[domain] = preq.post({
uri: 'https://' + domain + '/w/api.php',
uri: `https://${domain}/w/api.php`,
body: {
action: 'query',
meta: 'siteinfo',
siprop: 'general|namespaces|namespacealiases|specialpagealiases',
format: 'json',
formatversion: formatversion
formatversion
}
})
.then(res => res.body.query);
Expand Down Expand Up @@ -73,7 +71,7 @@ const doTest = (formatversion) => {
['A ~~~~~ Timestamp', 'title-invalid-magic-tilde'],
// Length
[new Array(258).join('x'), 'title-invalid-too-long'],
['Special:' + new Array(514).join('x'), 'title-invalid-too-long'],
[`Special:${new Array(514).join('x')}`, 'title-invalid-too-long'],
// Namespace prefix without actual title
['Talk:', 'title-invalid-empty'],
['Talk:#', 'title-invalid-empty'],
Expand All @@ -83,15 +81,15 @@ const doTest = (formatversion) => {
invalidTitles.forEach((testCase) => {
let name = testCase[0];
if (name.length > 20) {
name = testCase[0].substr(0, 20) + '...'
name = `${testCase[0].substr(0, 20)}...`;
}

it('should throw ' + testCase[1] + ' error for ' + name, () => {
it(`should throw ${testCase[1]} error for ${name}`, () => {
return getSiteInfo('en.wikipedia.org')
.then(siteInfo => Title.newFromText(testCase[0], siteInfo))
.then(() => {
throw new Error('Error should be thrown');
}, (e) => assert.deepEqual(e.message, testCase[1]));
}, e => assert.deepEqual(e.message, testCase[1]));
});
});

Expand All @@ -114,9 +112,9 @@ const doTest = (formatversion) => {
['A~~'],
[':A'],
// Length is 256 total, but only title part matters
['Category:' + new Array(248).join('x')],
[`Category:${new Array(248).join('x')}`],
// Special pages can have longer titles
['Special:' + new Array(500).join('x')],
[`Special:${new Array(500).join('x')}`],
[new Array(252).join('x')],
[new Array(257).join('x')],
['-'],
Expand All @@ -127,12 +125,12 @@ const doTest = (formatversion) => {
validTitles.forEach((title) => {
let name = title[0];
if (name.length > 20) {
name = title[0].substr(0, 20) + '...'
name = `${title[0].substr(0, 20)}...`;
}

it(name + ' should be valid', function() {
it(`${name} should be valid`, () => {
return getSiteInfo('en.wikipedia.org')
.then(siteInfo => Title.newFromText(title[0], siteInfo))
.then(siteInfo => Title.newFromText(title[0], siteInfo));
});
});
});
Expand All @@ -151,6 +149,7 @@ const doTest = (formatversion) => {
['en.wikipedia.org', 'WP:eger', 'Wikipedia:Eger'],
['en.wikipedia.org', 'X-Men (film series) #Gambit', 'X-Men_(film_series)'],
['en.wikipedia.org', 'Foo _ bar', 'Foo_bar'],
// eslint-disable-next-line max-len
['en.wikipedia.org', 'Foo \u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000 bar', 'Foo_bar'],
['en.wikipedia.org', 'Foo\u200E\u200F\u202A\u202B\u202C\u202D\u202Ebar', 'Foobar'],
// Special handling for `i` first character
Expand Down Expand Up @@ -245,14 +244,16 @@ const doTest = (formatversion) => {
['en.wikipedia.org', 'Special:Lonelypages', 'Special:LonelyPages'],
['en.wikipedia.org', 'Special:lonelypages', 'Special:LonelyPages'],
['en.wikipedia.org', 'Special:OrphanedPages', 'Special:LonelyPages'],
// eslint-disable-next-line max-len
['en.wikipedia.org', 'Special:Contribs/124.106.240.49', 'Special:Contributions/124.106.240.49'],
['es.wikipedia.org', 'Especial:SpecialPages', 'Especial:PáginasEspeciales'],
['es.wikipedia.org', 'Especial:Expandir plantillas', 'Especial:Sustituir_plantillas'],
// eslint-disable-next-line max-len
['es.wikipedia.org', 'Especial:BookSources/9784041047910', 'Especial:FuentesDeLibros/9784041047910'],
];

testCases.forEach((test) => {
it('For ' + test[0] + ' should normalize ' + test[1] + ' to ' + test[2], () => {
it(`For ${test[0]} should normalize ${test[1]} to ${test[2]}`, () => {
return getSiteInfo(test[0])
.then(siteInfo => Title.newFromText(test[1], siteInfo).getPrefixedDBKey())
.then(res => assert.deepEqual(res, test[2]));
Expand Down Expand Up @@ -285,14 +286,14 @@ const doTest = (formatversion) => {
[0, ':User:Test', 2, 'User:Test'],
];
testCases.forEach((test) => {
it('For ns:' + test[0] + ' should default ' + test[1] + ' to ' + test[2], () => {
it(`For ns:${test[0]} should default ${test[1]} to ${test[2]}`, () => {
return getSiteInfo('en.wikipedia.org')
.then((siteInfo) => {
const t = Title.newFromText(test[1], siteInfo, test[0]);
return [t.getNamespace()._id, t.getPrefixedDBKey()];
})
.then((res) => {
assert.deepEqual(res[0], test[2])
assert.deepEqual(res[0], test[2]);
assert.deepEqual(res[1], test[3]);
});
});
Expand Down Expand Up @@ -362,12 +363,12 @@ const doTest = (formatversion) => {
let idx = 0;
data.forEach((test) => {
idx++;
it('Should covert byte range. Test ' + idx, () => {
it(`Should covert byte range. Test ${idx}`, () => {
assert.deepEqual(utils.convertByteClassToUnicodeClass(test[0]), test[1]);
});
});

/* it('Should fetch domains', () => {
/* it('Should fetch domains', () => {
return preq.get({
uri: 'https://en.wikipedia.org/w/api.php?action=sitematrix&format=json'
})
Expand Down

0 comments on commit 8776d21

Please sign in to comment.