Skip to content

Commit

Permalink
eslint: fix new-cap in tests (wikimedia-gadgets#2129)
Browse files Browse the repository at this point in the history
manual fixes

related wikimedia-gadgets#2084
  • Loading branch information
NovemLinguae authored Dec 13, 2024
1 parent c2874ba commit 95efda0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 45 deletions.
1 change: 0 additions & 1 deletion tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"object-curly-spacing": "off",
"space-in-parens": "off",

"new-cap": "warn",
"no-undef": "warn",
"no-useless-escape": "warn"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/morebits.batchOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

describe('Morebits.batchOperation', () => {
test('Contruction', () => {
assert.true(new Morebits.batchOperation() instanceof Morebits.batchOperation, 'Correct instance');
assert.true(new Morebits.BatchOperation() instanceof Morebits.batchOperation, 'Correct instance');
});
const batch = new Morebits.batchOperation();
const batch = new Morebits.BatchOperation();
const pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest'];
batch.setPageList(pageList);
const chunkLength = 2;
Expand Down
56 changes: 28 additions & 28 deletions tests/morebits.date.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ describe('Morebits.date', () => {
test('Construction', () => {
// getTime and toISOString imply testing of inherited methods
// Allow off-by-one values in milliseconds for not-quite-simultaneous date contructions
expect(Math.abs(new Morebits.date().getTime() - Date.now())).toBeLessThanOrEqual(1);
expect(Math.abs(new Morebits.Date().getTime() - Date.now())).toBeLessThanOrEqual(1);

assert.strictEqual(new Morebits.date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring');
assert.strictEqual(new Morebits.date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts');
assert.strictEqual(new Morebits.date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format');
assert.strictEqual(new Morebits.date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number');
assert.strictEqual(new Morebits.date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string');
assert.strictEqual(new Morebits.date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit');
assert.strictEqual(new Morebits.date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit');
assert.strictEqual(new Morebits.Date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring');
assert.strictEqual(new Morebits.Date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format');
assert.strictEqual(new Morebits.Date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number');
assert.strictEqual(new Morebits.Date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string');
assert.strictEqual(new Morebits.Date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit');
assert.strictEqual(new Morebits.Date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit');
});
const date = new Morebits.date(timestampMediaWiki);
const date = new Morebits.Date(timestampMediaWiki);
test('Methods', () => {
assert.true(date.isValid(), 'Valid');
// Logs a message; not a failure, but annoying
assert.false(new Morebits.date('no').isValid(), 'Invalid');
assert.false(new Morebits.Date('no').isValid(), 'Invalid');

// Ideally we would test the differences between UTC and non-UTC dates
assert.strictEqual(date.getUTCDayName(), 'Saturday', 'getUTCDayName');
assert.strictEqual(date.getUTCDayNameAbbrev(), 'Sat', 'getUTCDayNameAbbrev');
assert.strictEqual(date.getUTCMonthName(), 'November', 'getUTCMonthName');
assert.strictEqual(date.getUTCMonthNameAbbrev(), 'Nov', 'getUTCMonthNameAbbrev');

assert.true(new Morebits.date(now).isAfter(date), 'isAfter');
assert.true(new Morebits.Date(now).isAfter(date), 'isAfter');
assert.true(date.isBefore(new Date(now)), 'isBefore');
});
test('RegEx headers', () => {
Expand All @@ -43,25 +43,25 @@ describe('Morebits.date', () => {
assert.false(date.monthHeaderRegex().test('==December 2020=='), 'Wrong month');
});
test('add/subtract', () => {
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string");
assert.strictEqual(new Morebits.date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string");
assert.strictEqual(new Morebits.Date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST

assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month');
assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month');
assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year');

assert.throws(() => new Morebits.date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided');
assert.throws(() => new Morebits.date(timestampMediaWiki).add(1), 'throws: no unit');
assert.throws(() => new Morebits.date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit');
assert.throws(() => new Morebits.Date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided');
assert.throws(() => new Morebits.Date(timestampMediaWiki).add(1), 'throws: no unit');
assert.throws(() => new Morebits.Date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit');
});
test('Formats', () => {
assert.strictEqual(new Morebits.date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format');
assert.strictEqual(new Morebits.Date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format');
assert.strictEqual(date.format('dddd D MMMM YY h:mA', 'utc'), 'Saturday 7 November 20 4:26PM', 'Some weirder stuff');
assert.strictEqual(date.format('MMt[h month], [d]a[y] D, h [o\'clock] A', 'utc'), '11th month, day 7, 4 o\'clock PM', 'Format escapes');
assert.strictEqual(date.format('dddd D MMMM YY h:mA', 600), 'Sunday 8 November 20 2:26AM', 'non-UTC formatting');
Expand All @@ -70,7 +70,7 @@ describe('Morebits.date', () => {
test('Calendar', () => {
assert.strictEqual(date.calendar('utc'), '2020-11-07', 'Old calendar');
assert.strictEqual(date.calendar(600), '2020-11-08', 'Old non-UTC');
assert.strictEqual(new Morebits.date(now).calendar('utc'), 'Today at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'New calendar');
assert.strictEqual(new Morebits.date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'Close calendar');
assert.strictEqual(new Morebits.Date(now).calendar('utc'), 'Today at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'New calendar');
assert.strictEqual(new Morebits.Date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'Close calendar');
});
});
4 changes: 2 additions & 2 deletions tests/morebits.quickForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param data
*/
function renderElement(data) {
return new Morebits.quickForm.element(data).render();
return new Morebits.QuickForm.Element(data).render();
}

describe('quickform', () => {
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('quickform', () => {
};

const getRenderedForm = () => {
const form = new Morebits.quickForm(() => {});
const form = new Morebits.QuickForm(() => {});
form.append(inputConfig);
form.append(checkboxesConfig);
form.append(checkboxListConfig);
Expand Down
6 changes: 3 additions & 3 deletions tests/morebits.taskManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe('Morebits.taskManager', () => {
test('Contruction', () => {
const tm = new Morebits.taskManager();
const tm = new Morebits.TaskManager();
assert.true(tm instanceof Morebits.taskManager, 'Correct instance');
});

Expand All @@ -21,7 +21,7 @@ describe('Morebits.taskManager', () => {

test('Simple', () => {
generateFuncs();
const simple = new Morebits.taskManager();
const simple = new Morebits.TaskManager();
simple.add(data.one, []);
simple.add(data.two, [data.one]);
simple.add(data.three, [data.two]);
Expand All @@ -32,7 +32,7 @@ describe('Morebits.taskManager', () => {
});
test('Complex', () => {
generateFuncs();
const complex = new Morebits.taskManager();
const complex = new Morebits.TaskManager();
complex.add(data.one, [data.two]);
complex.add(data.two, [data.three, data.four]);
complex.add(data.three, []);
Expand Down
10 changes: 5 additions & 5 deletions tests/morebits.unbinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

describe('Morebits.unbinder', () => {
test('Construction', () => {
assert.throws(() => new Morebits.unbinder(), 'throws: no string');
assert.throws(() => new Morebits.unbinder([42]), 'throws: not a string');
const u = new Morebits.unbinder('Hello world');
assert.throws(() => new Morebits.Unbinder(), 'throws: no string');
assert.throws(() => new Morebits.Unbinder([42]), 'throws: not a string');
const u = new Morebits.Unbinder('Hello world');
assert.true(u instanceof Morebits.unbinder, 'Correct instance');
assert.throws(() => u.unbind(), 'throws: Missing prefix');
assert.throws(() => u.unbind('w'), 'throws: Missing postfix');
});
test('Run', () => {
let u = new Morebits.unbinder('Hello world <!-- world --> world');
let u = new Morebits.Unbinder('Hello world <!-- world --> world');
u.unbind('<!--', '-->');
u.content = u.content.replace(/world/g, 'earth');
assert.strictEqual(u.rebind(), 'Hello earth <!-- world --> earth', 'Simple replace');

u = new Morebits.unbinder('Hello world <!-- world --> world [link link] [[link|link]]');
u = new Morebits.Unbinder('Hello world <!-- world --> world [link link] [[link|link]]');
assert.true(u instanceof Morebits.unbinder, 'Correct instance');
u.unbind('<!--', '-->');
u.unbind('\\[\\[', '\\]\\]');
Expand Down
8 changes: 4 additions & 4 deletions tests/morebits.wikitext.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ describe('Morebits.wikitext', () => {

test('Morebits.wikitext.page', () => {
const text = '{{short description}}{{about}}[[File:Fee.svg]]O, [[Juliet|she]] doth {{plural|teach}} the torches to burn bright!';
const page = new Morebits.wikitext.page(text);
const page = new Morebits.wikitext.Page(text);
assert.true(page instanceof Morebits.wikitext.page, 'Correct instance');
assert.strictEqual(page.getText(), text, 'Got text');

// Throws
assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates(), 'throws: no tag');
assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates('tag'), 'throws: no regex');
assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates(), 'throws: no tag');
assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates('tag'), 'throws: no regex');

// Define all the tests individually, with the appropriate method,
// input, expected output, and (spreaded) parameters.
Expand Down Expand Up @@ -356,7 +356,7 @@ describe('Morebits.wikitext', () => {
];

tests.forEach((test) => {
const page = new Morebits.wikitext.page(test.input);
const page = new Morebits.wikitext.Page(test.input);
assert.strictEqual(page[test.method](...test.params).getText(), test.expected, test.method + ' - ' + test.name);
});
});
Expand Down

0 comments on commit 95efda0

Please sign in to comment.