Skip to content

Commit

Permalink
switch to fs.promises vs bluebird for tests (#2226)
Browse files Browse the repository at this point in the history
- also switch to more idiomatic JS using newer syntax
  • Loading branch information
joshgoebel committed Oct 26, 2019
1 parent 25a81dd commit a69eb6a
Show file tree
Hide file tree
Showing 28 changed files with 195 additions and 205 deletions.
16 changes: 8 additions & 8 deletions test/api/autoDetection.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
'use strict';

let hljs = require('../../build');
let should = require('should');
const hljs = require('../../build');
const should = require('should');

describe('.autoDetection()', function() {
it('should get an existing language', function() {
describe('.autoDetection()', () => {
it('should get an existing language', () => {
const result = hljs.autoDetection('python');

result.should.be.instanceOf(Object);
});

it('should get an existing language by alias', function() {
it('should get an existing language by alias', () => {
const result = hljs.autoDetection('py');

result.should.be.instanceOf(Object);
});

it('should be case insensitive', function() {
it('should be case insensitive', () => {
const result = hljs.autoDetection('pYTHOn');

result.should.be.instanceOf(Object);
});

it('should return undefined', function() {
it('should return undefined', () => {
const result = hljs.autoDetection('-impossible-');

should.strictEqual(result, undefined);
});

it('should not break on undefined', function() {
it('should not break on undefined', () => {
const result = hljs.autoDetection(undefined);

should.strictEqual(result, undefined);
Expand Down
9 changes: 4 additions & 5 deletions test/api/binaryNumber.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

let hljs = require('../../build');

const hljs = require('../../build');
const pattern = new RegExp(`${hljs.BINARY_NUMBER_RE}$`);

describe('.BINARY_NUMBER_RE', function() {
it('should match binary numbers', function() {
describe('.BINARY_NUMBER_RE', () => {
it('should match binary numbers', () => {
const numbers = [ '0b0101', '0b1100', '0b1001'
, '0b11110101', '0b11001111'
, '0b1010111111000001'
Expand All @@ -14,7 +13,7 @@ describe('.BINARY_NUMBER_RE', function() {
numbers.should.matchEach(pattern);
});

it('should not match binary numbers greater than 2', function() {
it('should not match binary numbers greater than 2', () => {
const numbers = [ '0b2101', '0b1130', '0b1041'
, '0b11150101', '0b11061111'
, '0b1010111117000001'
Expand Down
20 changes: 10 additions & 10 deletions test/api/cNumber.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict';

let _ = require('lodash');
let hljs = require('../../build');
let utility = require('../utility');
const _ = require('lodash');
const hljs = require('../../build');
const utility = require('../utility');

const pattern = new RegExp(`${hljs.C_NUMBER_RE}$`);
let numberToString = utility.numberToString;
const numberToString = utility.numberToString;

describe('.C_NUMBER_RE', function() {
it('should match regular numbers', function() {
describe('.C_NUMBER_RE', () => {
it('should match regular numbers', () => {
const numbers = _.map(_.range(0, 1001), numberToString);

numbers.should.matchEach(pattern);
});

it('should match decimals', function() {
it('should match decimals', () => {
const decimal = _.map(_.range(0, 1.001, 0.001), numberToString);
const noLeadingZero = ['.1234', '.5206', '.0002', '.9998'];

Expand All @@ -23,21 +23,21 @@ describe('.C_NUMBER_RE', function() {
numbers.should.matchEach(pattern);
});

it('should match hex numbers', function() {
it('should match hex numbers', () => {
const numbers = [ '0xbada55', '0xfa1755', '0x45362e', '0xfedcba'
, '0x123456', '0x00000f', '0xfff000', '0xf0e1d2'
];

numbers.should.matchEach(pattern);
});

it('should not match hex numbers greater than "f"', function() {
it('should not match hex numbers greater than "f"', () => {
const numbers = ['0xgada55', '0xfh1755', '0x45i62e'];

numbers.should.not.matchEach(pattern);
});

it('should not match binary numbers', function() {
it('should not match binary numbers', () => {
const numbers = ['0b0101', '0b1100', '0b1001'];

numbers.should.not.matchEach(pattern);
Expand Down
10 changes: 5 additions & 5 deletions test/api/fixmarkup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

let should = require('should');
let hljs = require('../../build');
const should = require('should');
const hljs = require('../../build');

describe('.fixmarkup()', function() {
after(function() {
describe('.fixmarkup()', () => {
after(() => {
hljs.configure({ useBR: false })
})

it('should not add "undefined" to the beginning of the result (#1452)', function() {
it('should not add "undefined" to the beginning of the result (#1452)', () => {
hljs.configure({ useBR: true })
const value = '{ <span class="hljs-attr">"some"</span>: \n <span class="hljs-string">"json"</span> }';
const result = hljs.fixMarkup(value);
Expand Down
18 changes: 9 additions & 9 deletions test/api/getLanguage.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
'use strict';

let hljs = require('../../build');
let should = require('should');
const hljs = require('../../build');
const should = require('should');

describe('.getLanguage()', function() {
it('should get an existing language', function() {
describe('.getLanguage()', () => {
it('should get an existing language', () => {
const result = hljs.getLanguage('python');

result.should.be.instanceOf(Object);
});

it('should get an existing language by alias', function() {
it('should get an existing language by alias', () => {
const result = hljs.getLanguage('py');

result.should.be.instanceOf(Object);
});

it('should be case insensitive', function() {
it('should be case insensitive', () => {
const result = hljs.getLanguage('pYTHOn');

result.should.be.instanceOf(Object);
});

it('should return undefined', function() {
it('should return undefined', () => {
const result = hljs.getLanguage('-impossible-');

should.strictEqual(result, undefined);
});

it('should not break on undefined', function() {
it('should not break on undefined', () => {
const result = hljs.getLanguage(undefined);

should.strictEqual(result, undefined);
});

it('should get the csharp language by c# alias', function() {
it('should get the csharp language by c# alias', () => {
const result = hljs.getLanguage('c#');

result.should.be.instanceOf(Object);
Expand Down
8 changes: 4 additions & 4 deletions test/api/highlight.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

let hljs = require('../../build');
let should = require('should');
const hljs = require('../../build');
const should = require('should');

describe('.highlight()', function() {
it('should works without continuation', function() {
describe('.highlight()', () => {
it('should works without continuation', () => {
const code = "public void moveTo(int x, int y, int z);";
const result = hljs.highlight('java', code, false, false);

Expand Down
8 changes: 4 additions & 4 deletions test/api/ident.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

let hljs = require('../../build');
const hljs = require('../../build');

const pattern = new RegExp(`^${hljs.IDENT_RE}$`);

describe('.IDENT_RE', function() {
it('should match non-underscore starting words', function() {
describe('.IDENT_RE', () => {
it('should match non-underscore starting words', () => {
const words = [ 'foo' , 'bar' , 'baz'
, 'Foo' , 'Bar' , 'Baz'
, 'f_oo', 'ba_r', 'baz_'
Expand All @@ -15,7 +15,7 @@ describe('.IDENT_RE', function() {
words.should.matchEach(pattern);
});

it('should not match underscore starting words', function() {
it('should not match underscore starting words', () => {
const words = [ '_foo' , '_bar' , '_baz'
, '_Foo' , '_Bar' , '_Baz'
, '_f_oo', '_ba_r', '_baz_'
Expand Down
10 changes: 5 additions & 5 deletions test/api/keywords.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

let hljs = require('../../build');
const hljs = require('../../build');

describe('computing the relevance score of a language', function() {
it('should ignore common keywords', function() {
describe('computing the relevance score of a language', () => {
it('should ignore common keywords', () => {
const grammar =function () {
return {
keywords:
Expand All @@ -17,7 +17,7 @@ describe('computing the relevance score of a language', function() {

result.relevance.should.equal(3)
});
it ('should not ignore weighted common keywords', function() {
it ('should not ignore weighted common keywords', () => {
const grammar =function () {
return {
keywords:
Expand All @@ -31,7 +31,7 @@ describe('computing the relevance score of a language', function() {

result.relevance.should.equal(13)
});
it ('should not ignore weighted common keywords (if 1 is forced)', function() {
it ('should not ignore weighted common keywords (if 1 is forced)', () => {
const grammar = function () {
return {
keywords:
Expand Down
14 changes: 7 additions & 7 deletions test/api/number.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

let _ = require('lodash');
let hljs = require('../../build');
let utility = require('../utility');
const _ = require('lodash');
const hljs = require('../../build');
const utility = require('../utility');

const pattern = new RegExp(`${hljs.NUMBER_RE}$`);
let numberToString = utility.numberToString;
const numberToString = utility.numberToString;

describe('.NUMBER_RE', function() {
it('should match regular numbers and decimals', function() {
describe('.NUMBER_RE', () => {
it('should match regular numbers and decimals', () => {
const number = _.map(_.range(0, 1001), numberToString);
const decimal = _.map(_.range(0, 1.001, 0.001), numberToString);
const noLeadingZero = ['.1234', '.5206', '.0002', '.9998'];
Expand All @@ -18,7 +18,7 @@ describe('.NUMBER_RE', function() {
numbers.should.matchEach(pattern);
});

it('should not match hex or binary numbers', function() {
it('should not match hex or binary numbers', () => {
const numbers = [ '0xbada55', '0xfa1755', '0x45362e'
, '0b0101' , '0b1100' , '0b1001'
];
Expand Down
12 changes: 6 additions & 6 deletions test/api/starters.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
'use strict';

let hljs = require('../../build');
const hljs = require('../../build');

const pattern = new RegExp(`^${hljs.RE_STARTERS_RE}$`);

describe('.RE_STARTERS_RE', function() {
it('should match boolean operators', function() {
describe('.RE_STARTERS_RE', () => {
it('should match boolean operators', () => {
const operators = [ '!', '!=', '!==', '==', '===', '<=', '>='
, '<', '>', '||', '&&', '?'
];

operators.should.matchEach(pattern);
});

it('should match arithmetic operators', function() {
it('should match arithmetic operators', () => {
const operators = [ '*', '*=', '+', '+=', '-', '-=', '/', '/='
, '%', '%='
];

operators.should.matchEach(pattern);
});

it('should match binary operators', function() {
it('should match binary operators', () => {
const operators = [ '&', '&=', '|', '|=', '<<', '<<=', '>>', '>>='
, '>>>', '>>>=', '^', '^=', '~'
];

operators.should.matchEach(pattern);
});

it('should match miscellaneous operators', function() {
it('should match miscellaneous operators', () => {
const operators = [',', '=', ':', ';', '[', '{', '('];

operators.should.matchEach(pattern);
Expand Down
8 changes: 4 additions & 4 deletions test/api/underscoreIdent.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

let hljs = require('../../build');
const hljs = require('../../build');

const pattern = new RegExp(`^${hljs.UNDERSCORE_IDENT_RE}$`);

describe('.UNDERSCORE_IDENT_RE', function() {
it('should match any word starting without numbers', function() {
describe('.UNDERSCORE_IDENT_RE', () => {
it('should match any word starting without numbers', () => {
const words = [ 'foo' , 'bar' , 'baz'
, 'Foo' , 'Bar' , 'Baz'
, '_foo' , '_bar' , '_baz'
Expand All @@ -17,7 +17,7 @@ describe('.UNDERSCORE_IDENT_RE', function() {
words.should.matchEach(pattern);
});

it('should not match any word starting with numbers', function() {
it('should not match any word starting with numbers', () => {
const words = [ '1foo' , '6bar' , '0baz'
, '2Foo' , '7Bar' , '1Baz'
, '3f_oo', '8ba_r', '2baz_'
Expand Down
10 changes: 5 additions & 5 deletions test/browser/plain.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

let bluebird = require('bluebird');
let { JSDOM } = require('jsdom');
let utility = require('../utility');
let glob = bluebird.promisify(require('glob'));
let fs = require('fs');
const { JSDOM } = require('jsdom');
const utility = require('../utility');
const {promisify} = require('util');
const glob = promisify(require('glob'));
const fs = require('fs');

describe('plain browser', function() {
before(function() {
Expand Down
8 changes: 4 additions & 4 deletions test/browser/worker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

let bluebird = require('bluebird');
let Worker = require('tiny-worker');
let utility = require('../utility');
let glob = bluebird.promisify(require('glob'));
const Worker = require('tiny-worker');
const utility = require('../utility');
const {promisify} = require('util');
const glob = promisify(require('glob'));

describe('web worker', function() {
before(function() {
Expand Down
Loading

0 comments on commit a69eb6a

Please sign in to comment.