From 8f8758182d3fe65e95ce484f41bf37debb2085ad Mon Sep 17 00:00:00 2001 From: segayuu Date: Thu, 18 Oct 2018 11:27:00 +0900 Subject: [PATCH] Refactoring test: es2016nify --- test/index.js | 2 +- test/scripts/cache_stream.js | 20 ++--- test/scripts/camel_case_keys.js | 24 +++--- test/scripts/escape_diacritic.js | 10 +-- test/scripts/escape_html.js | 10 +-- test/scripts/escape_regexp.js | 10 +-- test/scripts/hash.js | 20 ++--- test/scripts/highlight.js | 130 +++++++++++++++---------------- test/scripts/html_tag.js | 22 +++--- test/scripts/pattern.js | 32 ++++---- test/scripts/permalink.js | 18 ++--- test/scripts/slugize.js | 26 +++---- test/scripts/spawn.js | 92 ++++++++++------------ test/scripts/truncate.js | 18 ++--- test/scripts/word_wrap.js | 16 ++-- 15 files changed, 220 insertions(+), 230 deletions(-) diff --git a/test/index.js b/test/index.js index 855b61c8..834279c8 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -describe('util', function() { +describe('util', () => { require('./scripts/cache_stream'); require('./scripts/camel_case_keys'); require('./scripts/escape_diacritic'); diff --git a/test/scripts/cache_stream.js b/test/scripts/cache_stream.js index 37e7bc9a..6fab3f1b 100644 --- a/test/scripts/cache_stream.js +++ b/test/scripts/cache_stream.js @@ -1,26 +1,26 @@ 'use strict'; -var Readable = require('stream').Readable; +const { Readable } = require('stream'); -describe('CacheStream', function() { - var CacheStream = require('../../lib/cache_stream'); +describe('CacheStream', () => { + const CacheStream = require('../../lib/cache_stream'); - it('default', function() { - var src = new Readable(); - var cacheStream = new CacheStream(); - var content = Buffer.from('test'); + it('default', () => { + const src = new Readable(); + const cacheStream = new CacheStream(); + const content = Buffer.from('test'); src.push(content); src.push(null); src.pipe(cacheStream); - cacheStream.on('finish', function() { + cacheStream.on('finish', () => { cacheStream.getCache().should.eql(content); }); }); - it('destroy', function() { - var cacheStream = new CacheStream(); + it('destroy', () => { + const cacheStream = new CacheStream(); cacheStream._cache = [Buffer.alloc(1)]; cacheStream.destroy(); diff --git a/test/scripts/camel_case_keys.js b/test/scripts/camel_case_keys.js index 94dc2aaf..e8b0ba6a 100644 --- a/test/scripts/camel_case_keys.js +++ b/test/scripts/camel_case_keys.js @@ -1,12 +1,12 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('camelCaseKeys', function() { - var camelCaseKeys = require('../../lib/camel_case_keys'); +describe('camelCaseKeys', () => { + const camelCaseKeys = require('../../lib/camel_case_keys'); - it('default', function() { - var result = camelCaseKeys({ + it('default', () => { + const result = camelCaseKeys({ foo_bar: 'test' }); @@ -16,7 +16,7 @@ describe('camelCaseKeys', function() { }); }); - it('obj must be an object', function() { + it('obj must be an object', () => { try { camelCaseKeys(); } catch (err) { @@ -24,8 +24,8 @@ describe('camelCaseKeys', function() { } }); - it('setter', function() { - var result = camelCaseKeys({ + it('setter', () => { + const result = camelCaseKeys({ foo_bar: 'test' }); @@ -33,8 +33,8 @@ describe('camelCaseKeys', function() { result.fooBar.should.eql('new'); }); - it('ignore prefixing underscore', function() { - var result = camelCaseKeys({ + it('ignore prefixing underscore', () => { + const result = camelCaseKeys({ _foo_bar: 'test', __bar_baz: 'foo' }); @@ -47,8 +47,8 @@ describe('camelCaseKeys', function() { }); }); - it('do nothing if the key is camelCase', function() { - var result = camelCaseKeys({ + it('do nothing if the key is camelCase', () => { + const result = camelCaseKeys({ fooBar: 'test' }); diff --git a/test/scripts/escape_diacritic.js b/test/scripts/escape_diacritic.js index 225ac4d4..60751910 100644 --- a/test/scripts/escape_diacritic.js +++ b/test/scripts/escape_diacritic.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('escapeDiacritic', function() { - var escapeDiacritic = require('../../lib/escape_diacritic'); +describe('escapeDiacritic', () => { + const escapeDiacritic = require('../../lib/escape_diacritic'); - it('default', function() { + it('default', () => { escapeDiacritic('Hell\u00F2 w\u00F2rld').should.eql('Hello world'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { escapeDiacritic(); } catch (err) { diff --git a/test/scripts/escape_html.js b/test/scripts/escape_html.js index 68fc6ede..0207fc6f 100644 --- a/test/scripts/escape_html.js +++ b/test/scripts/escape_html.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('escapeHTML', function() { - var escapeHTML = require('../../lib/escape_html'); +describe('escapeHTML', () => { + const escapeHTML = require('../../lib/escape_html'); - it('default', function() { + it('default', () => { escapeHTML('

Hello "world".

').should.eql('<p>Hello "world".</p>'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { escapeHTML(); } catch (err) { diff --git a/test/scripts/escape_regexp.js b/test/scripts/escape_regexp.js index f74b6deb..7c3c5116 100644 --- a/test/scripts/escape_regexp.js +++ b/test/scripts/escape_regexp.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('escapeRegExp', function() { - var escapeRegExp = require('../../lib/escape_regexp'); +describe('escapeRegExp', () => { + const escapeRegExp = require('../../lib/escape_regexp'); - it('default', function() { + it('default', () => { escapeRegExp('hello*world').should.eql('hello\\*world'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { escapeRegExp(); } catch (err) { diff --git a/test/scripts/hash.js b/test/scripts/hash.js index 360e2f8a..b7b2e868 100644 --- a/test/scripts/hash.js +++ b/test/scripts/hash.js @@ -1,26 +1,26 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line -var crypto = require('crypto'); +const should = require('chai').should(); // eslint-disable-line +const crypto = require('crypto'); function sha1(content) { - var hash = crypto.createHash('sha1'); + const hash = crypto.createHash('sha1'); hash.update(content); return hash.digest(); } -describe('hash', function() { - var hash = require('../../lib/hash'); +describe('hash', () => { + const hash = require('../../lib/hash'); - it('hash', function() { - var content = '123456'; + it('hash', () => { + const content = '123456'; hash.hash(content).should.eql(sha1(content)); }); - it('HashStream', function() { - var content = '123456'; - var stream = new hash.HashStream(); + it('HashStream', () => { + const content = '123456'; + const stream = new hash.HashStream(); stream.write(Buffer.from(content)); stream.end(); diff --git a/test/scripts/highlight.js b/test/scripts/highlight.js index 5553b23b..3fb23900 100644 --- a/test/scripts/highlight.js +++ b/test/scripts/highlight.js @@ -1,32 +1,32 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line -var hljs = require('highlight.js'); -var Entities = require('html-entities').XmlEntities; -var entities = new Entities(); -var validator = require('html-tag-validator'); +const should = require('chai').should(); // eslint-disable-line +const hljs = require('highlight.js'); +const Entities = require('html-entities').XmlEntities; +const entities = new Entities(); +const validator = require('html-tag-validator'); -var testJson = { +const testJson = { foo: 1, bar: 2 }; -var testString = JSON.stringify(testJson, null, ' '); +const testString = JSON.stringify(testJson, null, ' '); -var start = '
'; -var end = '
'; +const start = '
'; +const end = '
'; -var gutterStart = '
';
-var gutterEnd = '
'; +const gutterStart = '
';
+const gutterEnd = '
'; -var codeStart = '
';
-var codeEnd = '
'; +const codeStart = '
';
+const codeEnd = '
'; function gutter(start, end) { - var result = gutterStart; + let result = gutterStart; - for (var i = start; i <= end; i++) { - result += '' + i + '
'; + for (let i = start; i <= end; i++) { + result += `${i}
`; } result += gutterEnd; @@ -35,7 +35,7 @@ function gutter(start, end) { } function code(str, lang) { - var data; + let data; if (lang) { data = hljs.highlight(lang.toLowerCase(), str); @@ -45,11 +45,11 @@ function code(str, lang) { data = {value: entities.encode(str)}; } - var lines = data.value.split('\n'); - var result = codeStart; + const lines = data.value.split('\n'); + let result = codeStart; - for (var i = 0, len = lines.length; i < len; i++) { - result += '' + lines[i] + '
'; + for (let i = 0, len = lines.length; i < len; i++) { + result += `${lines[i]}
`; } result += codeEnd; @@ -58,9 +58,9 @@ function code(str, lang) { } function assertResult(result) { - var expected = start; + let expected = start; - for (var i = 1, len = arguments.length; i < len; i++) { + for (let i = 1, len = arguments.length; i < len; i++) { expected += arguments[i]; } @@ -70,7 +70,7 @@ function assertResult(result) { } function validateHtmlAsync(str, done) { - validator(str, function(err, ast) { + validator(str, (err, ast) => { if (err) { done(err); } else { @@ -79,16 +79,16 @@ function validateHtmlAsync(str, done) { }); } -describe('highlight', function() { - var highlight = require('../../lib/highlight'); +describe('highlight', () => { + const highlight = require('../../lib/highlight'); - it('default', function(done) { - var result = highlight(testString); + it('default', done => { + const result = highlight(testString); assertResult(result, gutter(1, 4), code(testString)); validateHtmlAsync(result, done); }); - it('str must be a string', function() { + it('str must be a string', () => { try { highlight(); } catch (err) { @@ -96,26 +96,26 @@ describe('highlight', function() { } }); - it('gutter: false', function(done) { - var result = highlight(testString, {gutter: false}); + it('gutter: false', done => { + const result = highlight(testString, {gutter: false}); assertResult(result, code(testString)); validateHtmlAsync(result, done); }); - it('wrap: false', function(done) { - var result = highlight(testString, {wrap: false}); + it('wrap: false', done => { + const result = highlight(testString, {wrap: false}); result.should.eql(entities.encode(testString)); validateHtmlAsync(result, done); }); - it('firstLine', function(done) { - var result = highlight(testString, {firstLine: 3}); + it('firstLine', done => { + const result = highlight(testString, {firstLine: 3}); assertResult(result, gutter(3, 6), code(testString)); validateHtmlAsync(result, done); }); - it('lang = json', function(done) { - var result = highlight(testString, {lang: 'json'}); + it('lang = json', done => { + const result = highlight(testString, {lang: 'json'}); result.should.eql([ '
', @@ -126,8 +126,8 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('auto detect', function(done) { - var result = highlight(testString, {autoDetect: true}); + it('auto detect', done => { + const result = highlight(testString, {autoDetect: true}); result.should.eql([ '
', @@ -138,16 +138,16 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('don\'t highlight if language not found', function(done) { - var result = highlight('test', {lang: 'jrowiejrowi'}); + it('don\'t highlight if language not found', done => { + const result = highlight('test', {lang: 'jrowiejrowi'}); assertResult(result, gutter(1, 1), code('test')); validateHtmlAsync(result, done); }); it('don\'t highlight if parse failed'); - it('caption', function(done) { - var result = highlight(testString, { + it('caption', done => { + const result = highlight(testString, { caption: 'hello world' }); @@ -160,15 +160,15 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('tab', function(done) { - var str = [ + it('tab', done => { + const str = [ 'function fib(i){', '\tif (i <= 1) return i;', '\treturn fib(i - 1) + fib(i - 2);', '}' ].join('\n'); - var result = highlight(str, {tab: ' ', lang: 'js'}); + const result = highlight(str, {tab: ' ', lang: 'js'}); result.should.eql([ '
', @@ -179,8 +179,8 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('escape html entity', function(done) { - var str = [ + it('escape html entity', done => { + const str = [ 'deploy:', ' type: git', ' repo: ', @@ -188,13 +188,13 @@ describe('highlight', function() { ' message: [message]' ].join('\n'); - var result = highlight(str); + const result = highlight(str); result.should.include('<repository url>'); validateHtmlAsync(result, done); }); - it('parse multi-line strings correctly', function(done) { - var str = [ + it('parse multi-line strings correctly', done => { + const str = [ 'var string = `', ' Multi', ' line', @@ -202,7 +202,7 @@ describe('highlight', function() { '`' ].join('\n'); - var result = highlight(str, {lang: 'js'}); + const result = highlight(str, {lang: 'js'}); result.should.eql([ '
', gutter(1, 5), @@ -212,8 +212,8 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('parse multi-line strings including empty line', function(done) { - var str = [ + it('parse multi-line strings including empty line', done => { + const str = [ 'var string = `', ' Multi', '', @@ -221,7 +221,7 @@ describe('highlight', function() { '`' ].join('\n'); - var result = highlight(str, {lang: 'js'}); + const result = highlight(str, {lang: 'js'}); result.should.eql([ '
', gutter(1, 5), @@ -231,8 +231,8 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('auto detect of multi-line statement', function(done) { - var str = [ + it('auto detect of multi-line statement', done => { + const str = [ '"use strict";', 'var string = `', ' Multi', @@ -241,7 +241,7 @@ describe('highlight', function() { '`' ].join('\n'); - var result = highlight(str, {autoDetect: true}); + const result = highlight(str, {autoDetect: true}); result.should.eql([ '
', gutter(1, 6), @@ -251,15 +251,15 @@ describe('highlight', function() { validateHtmlAsync(result, done); }); - it('gives the highlight class to marked lines', function(done) { - var str = [ + it('gives the highlight class to marked lines', done => { + const str = [ 'roses are red', 'violets are blue', 'sugar is sweet', 'and so are you' ].join('\n'); - var result = highlight(str, {mark: [1, 3, 5]}); + const result = highlight(str, {mark: [1, 3, 5]}); result.should.include('class="line marked">roses'); result.should.include('class="line">violets'); @@ -269,14 +269,14 @@ describe('highlight', function() { }); it('hljs compatibility - with lines', (done) => { - var str = [ + const str = [ 'function (a) {', ' if (a > 3)', ' return true;', ' return false;', '}' ].join('\n'); - var result = highlight(str, {hljs: true, lang: 'javascript' }); + const result = highlight(str, {hljs: true, lang: 'javascript' }); result.should.include(gutterStart); result.should.include(codeStart); result.should.include('code class="hljs javascript"'); @@ -286,14 +286,14 @@ describe('highlight', function() { }); it('hljs compatibility - no lines', (done) => { - var str = [ + const str = [ 'function (a) {', ' if (a > 3)', ' return true;', ' return false;', '}' ].join('\n'); - var result = highlight(str, {hljs: true, gutter: false, lang: 'javascript' }); + const result = highlight(str, {hljs: true, gutter: false, lang: 'javascript' }); result.should.not.include(gutterStart); result.should.not.include(codeStart); result.should.include('code class="hljs javascript"'); diff --git a/test/scripts/html_tag.js b/test/scripts/html_tag.js index 4bf9182b..67b2470b 100644 --- a/test/scripts/html_tag.js +++ b/test/scripts/html_tag.js @@ -1,15 +1,15 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('htmlTag', function() { - var htmlTag = require('../../lib/html_tag'); +describe('htmlTag', () => { + const htmlTag = require('../../lib/html_tag'); - it('tag', function() { + it('tag', () => { htmlTag('hr').should.eql('
'); }); - it('tag + attrs', function() { + it('tag + attrs', () => { htmlTag('img', { src: 'http://placekitten.com/200/300' }).should.eql(''); @@ -21,41 +21,41 @@ describe('htmlTag', function() { }).should.eql(''); }); - it('tag + attrs + text', function() { + it('tag + attrs + text', () => { htmlTag('a', { href: 'http://zespia.tw' }, 'My blog').should.eql('My blog'); }); - it('tag + empty ALT attr', function() { + it('tag + empty ALT attr', () => { htmlTag('img', { src: 'http://placekitten.com/200/300', alt: '' }).should.eql(''); }); - it('passing a zero as attribute', function() { + it('passing a zero as attribute', () => { htmlTag('a', { href: 'http://zespia.tw', tabindex: 0 }, 'My blog').should.eql('My blog'); }); - it('passing a null alt attribute', function() { + it('passing a null alt attribute', () => { htmlTag('a', { href: 'http://zespia.tw', alt: null }, 'My blog').should.eql('My blog'); }); - it('passing a undefined alt attribute', function() { + it('passing a undefined alt attribute', () => { htmlTag('a', { href: 'http://zespia.tw', alt: undefined }, 'My blog').should.eql('My blog'); }); - it('tag is required', function() { + it('tag is required', () => { try { htmlTag(); } catch (err) { diff --git a/test/scripts/pattern.js b/test/scripts/pattern.js index c57416f2..a21010d9 100644 --- a/test/scripts/pattern.js +++ b/test/scripts/pattern.js @@ -1,13 +1,13 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('Pattern', function() { - var Pattern = require('../../lib/pattern'); +describe('Pattern', () => { + const Pattern = require('../../lib/pattern'); - it('String - posts/:id', function() { - var pattern = new Pattern('posts/:id'); - var result = pattern.match('/posts/89'); + it('String - posts/:id', () => { + const pattern = new Pattern('posts/:id'); + const result = pattern.match('/posts/89'); result.should.eql({ 0: 'posts/89', @@ -16,9 +16,9 @@ describe('Pattern', function() { }); }); - it('String - posts/*path', function() { - var pattern = new Pattern('posts/*path'); - var result = pattern.match('posts/2013/hello-world'); + it('String - posts/*path', () => { + const pattern = new Pattern('posts/*path'); + const result = pattern.match('posts/2013/hello-world'); result.should.eql({ 0: 'posts/2013/hello-world', @@ -27,8 +27,8 @@ describe('Pattern', function() { }); }); - it('String - posts/:id?', function() { - var pattern = new Pattern('posts/:id?'); + it('String - posts/:id?', () => { + const pattern = new Pattern('posts/:id?'); pattern.match('posts/').should.eql({ 0: 'posts/', @@ -43,15 +43,15 @@ describe('Pattern', function() { }); }); - it('RegExp', function() { - var pattern = new Pattern(/ab?cd/); + it('RegExp', () => { + const pattern = new Pattern(/ab?cd/); pattern.match('abcd').should.be.ok; pattern.match('acd').should.be.ok; }); - it('Function', function() { - var pattern = new Pattern(function(str) { + it('Function', () => { + const pattern = new Pattern(str => { str.should.eql('foo'); return {}; }); @@ -59,7 +59,7 @@ describe('Pattern', function() { pattern.match('foo').should.eql({}); }); - it('rule is required', function() { + it('rule is required', () => { try { // eslint-disable-next-line no-new new Pattern(); diff --git a/test/scripts/permalink.js b/test/scripts/permalink.js index a78717da..dbad6837 100644 --- a/test/scripts/permalink.js +++ b/test/scripts/permalink.js @@ -1,12 +1,12 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('Permalink', function() { - var Permalink = require('../../lib/permalink'); - var permalink; +describe('Permalink', () => { + const Permalink = require('../../lib/permalink'); + let permalink; - it('constructor', function() { + it('constructor', () => { permalink = new Permalink(':year/:month/:day/:title'); permalink.rule.should.eql(':year/:month/:day/:title'); @@ -26,7 +26,7 @@ describe('Permalink', function() { permalink.params.should.eql(['year', 'month', 'day', 'title']); }); - it('rule is required', function() { + it('rule is required', () => { try { // eslint-disable-next-line no-new new Permalink(); @@ -35,12 +35,12 @@ describe('Permalink', function() { } }); - it('test()', function() { + it('test()', () => { permalink.test('2014/01/31/test').should.be.true; permalink.test('foweirojwoier').should.be.false; }); - it('parse()', function() { + it('parse()', () => { permalink.parse('2014/01/31/test').should.eql({ year: '2014', month: '01', @@ -49,7 +49,7 @@ describe('Permalink', function() { }); }); - it('stringify()', function() { + it('stringify()', () => { permalink.stringify({ year: '2014', month: '01', diff --git a/test/scripts/slugize.js b/test/scripts/slugize.js index 324f859a..e4ddde89 100644 --- a/test/scripts/slugize.js +++ b/test/scripts/slugize.js @@ -1,47 +1,47 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('slugize', function() { - var slugize = require('../../lib/slugize'); +describe('slugize', () => { + const slugize = require('../../lib/slugize'); - it('spaces', function() { + it('spaces', () => { slugize('Hello World').should.eql('Hello-World'); }); - it('diacritic', function() { + it('diacritic', () => { slugize('Hell\u00F2 w\u00F2rld').should.eql('Hello-world'); }); - it('continous dashes', function() { + it('continous dashes', () => { slugize('Hello World').should.eql('Hello-World'); }); - it('prefixing and trailing dashes', function() { + it('prefixing and trailing dashes', () => { slugize('~Hello World~').should.eql('Hello-World'); }); - it('other special characters', function() { + it('other special characters', () => { slugize('Hello ~`!@#$%^&*()-_+=[]{}|\\;:"\'<>,.?/World').should.eql('Hello-World'); }); - it('custom separator', function() { + it('custom separator', () => { slugize('Hello World', {separator: '_'}).should.eql('Hello_World'); }); - it('lower case', function() { + it('lower case', () => { slugize('Hello World', {transform: 1}).should.eql('hello-world'); }); - it('upper case', function() { + it('upper case', () => { slugize('Hello World', {transform: 2}).should.eql('HELLO-WORLD'); }); - it('non-english', function() { + it('non-english', () => { slugize('遊戲').should.eql('遊戲'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { slugize(); } catch (err) { diff --git a/test/scripts/spawn.js b/test/scripts/spawn.js index 4e8cb13e..23fe3c64 100644 --- a/test/scripts/spawn.js +++ b/test/scripts/spawn.js @@ -1,31 +1,29 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line -var pathFn = require('path'); -var fs = require('fs'); -var rewire = require('rewire'); - -describe('spawn', function() { - var spawn = require('../../lib/spawn'); - var CacheStream = require('../../lib/cache_stream'); - var fixturePath = pathFn.join(__dirname, 'spawn_test.txt'); - var fixture = 'test content'; - - before(function(done) { +const should = require('chai').should(); // eslint-disable-line +const pathFn = require('path'); +const fs = require('fs'); +const rewire = require('rewire'); + +describe('spawn', () => { + const spawn = require('../../lib/spawn'); + const CacheStream = require('../../lib/cache_stream'); + const fixturePath = pathFn.join(__dirname, 'spawn_test.txt'); + const fixture = 'test content'; + + before(done => { fs.writeFile(fixturePath, fixture, done); }); - after(function(done) { + after(done => { fs.unlink(fixturePath, done); }); - it('default', function() { - return spawn('cat', [fixturePath]).then(function(content) { - content.should.eql(fixture); - }); - }); + it('default', () => spawn('cat', [fixturePath]).then(content => { + content.should.eql(fixture); + })); - it('command is required', function() { + it('command is required', () => { try { spawn(); } catch (err) { @@ -33,18 +31,16 @@ describe('spawn', function() { } }); - it('error', function() { - return spawn('cat', ['nothing']).catch(function(err) { - err.message.trim().should.eql('cat: nothing: No such file or directory'); - err.code.should.eql(1); - }); - }); + it('error', () => spawn('cat', ['nothing']).catch(err => { + err.message.trim().should.eql('cat: nothing: No such file or directory'); + err.code.should.eql(1); + })); - it('verbose - stdout', function() { - var spawn = rewire('../../lib/spawn'); - var stdoutCache = new CacheStream(); - var stderrCache = new CacheStream(); - var content = 'something'; + it('verbose - stdout', () => { + const spawn = rewire('../../lib/spawn'); + const stdoutCache = new CacheStream(); + const stderrCache = new CacheStream(); + const content = 'something'; spawn.__set__('process', { stdout: stdoutCache, @@ -53,15 +49,15 @@ describe('spawn', function() { return spawn('echo', [content], { verbose: true - }).then(function() { + }).then(() => { stdoutCache.getCache().toString('utf8').trim().should.eql(content); }); }); - it('verbose - stderr', function() { - var spawn = rewire('../../lib/spawn'); - var stdoutCache = new CacheStream(); - var stderrCache = new CacheStream(); + it('verbose - stderr', () => { + const spawn = rewire('../../lib/spawn'); + const stdoutCache = new CacheStream(); + const stderrCache = new CacheStream(); spawn.__set__('process', { stdout: stdoutCache, @@ -70,27 +66,21 @@ describe('spawn', function() { return spawn('cat', ['nothing'], { verbose: true - }).catch(function() { + }).catch(() => { stderrCache.getCache().toString('utf8').trim().should .eql('cat: nothing: No such file or directory'); }); }); - it('custom encoding', function() { - return spawn('cat', [fixturePath], {encoding: 'hex'}).then(function(content) { - content.should.eql(Buffer.from(fixture).toString('hex')); - }); - }); + it('custom encoding', () => spawn('cat', [fixturePath], {encoding: 'hex'}).then(content => { + content.should.eql(Buffer.from(fixture).toString('hex')); + })); - it('encoding = null', function() { - return spawn('cat', [fixturePath], {encoding: null}).then(function(content) { - content.should.eql(Buffer.from(fixture)); - }); - }); + it('encoding = null', () => spawn('cat', [fixturePath], {encoding: null}).then(content => { + content.should.eql(Buffer.from(fixture)); + })); - it('stdio = inherit', function() { - return spawn('echo', ['something'], { - stdio: 'inherit' - }); - }); + it('stdio = inherit', () => spawn('echo', ['something'], { + stdio: 'inherit' + })); }); diff --git a/test/scripts/truncate.js b/test/scripts/truncate.js index cc29b062..a5f633fe 100644 --- a/test/scripts/truncate.js +++ b/test/scripts/truncate.js @@ -1,36 +1,36 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('truncate', function() { - var truncate = require('../../lib/truncate'); +describe('truncate', () => { + const truncate = require('../../lib/truncate'); - it('default', function() { + it('default', () => { truncate('Once upon a time in a world far far away') .should.eql('Once upon a time in a world...'); }); - it('shorter string', function() { + it('shorter string', () => { truncate('Once upon') .should.eql('Once upon'); }); - it('truncate', function() { + it('truncate', () => { truncate('Once upon a time in a world far far away', {length: 17}) .should.eql('Once upon a ti...'); }); - it('separator', function() { + it('separator', () => { truncate('Once upon a time in a world far far away', {length: 17, separator: ' '}) .should.eql('Once upon a...'); }); - it('omission', function() { + it('omission', () => { truncate('And they found that many people were sleeping better.', {length: 25, omission: '... (continued)'}) .should.eql('And they f... (continued)'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { truncate(); } catch (err) { diff --git a/test/scripts/word_wrap.js b/test/scripts/word_wrap.js index ec89aed3..96a52d89 100644 --- a/test/scripts/word_wrap.js +++ b/test/scripts/word_wrap.js @@ -1,28 +1,28 @@ 'use strict'; -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line -describe('wordWrap', function() { - var wordWrap = require('../../lib/word_wrap'); +describe('wordWrap', () => { + const wordWrap = require('../../lib/word_wrap'); - it('default', function() { + it('default', () => { wordWrap('Once upon a time').should.eql('Once upon a time'); }); - it('default width', function() { + it('default width', () => { wordWrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...') .should.eql('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined...'); }); - it('width = 8', function() { + it('width = 8', () => { wordWrap('Once upon a time', {width: 8}).should.eql('Once\nupon a\ntime'); }); - it('width = 1', function() { + it('width = 1', () => { wordWrap('Once upon a time', {width: 1}).should.eql('Once\nupon\na\ntime'); }); - it('str must be a string', function() { + it('str must be a string', () => { try { wordWrap(); } catch (err) {