From 63d4a48d11f8e78b135407a47b904c91f650253e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 14 Oct 2015 23:41:11 +0700 Subject: [PATCH] ES2015ify the tests --- .editorconfig | 2 +- .travis.yml | 2 +- package.json | 7 ++++++- test-buffer.js | 26 -------------------------- test-real.js | 7 ++----- test.js | 37 ++++++++++++++++++++++++++----------- 6 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 test-buffer.js diff --git a/.editorconfig b/.editorconfig index 86c8f59..8f9d77e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,7 +7,7 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[{package.json,*.yml}] indent_style = space indent_size = 2 diff --git a/.travis.yml b/.travis.yml index ea4c8c5..aea1274 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: false language: node_js node_js: - - 'iojs' + - 'stable' - '0.12' diff --git a/package.json b/package.json index 5c23a41..f2e45b6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=0.12.0" }, "scripts": { - "test": "xo && ava test.js test-buffer.js && echo unicorns | ava test-real.js" + "test": "xo && ava test.js && echo unicorns | ava test-real.js" }, "files": [ "index.js" @@ -32,5 +32,10 @@ "ava": "*", "buffer-equals": "^1.0.3", "xo": "*" + }, + "xo": { + "ignores": [ + "test.js" + ] } } diff --git a/test-buffer.js b/test-buffer.js deleted file mode 100644 index 206624e..0000000 --- a/test-buffer.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; -var test = require('ava'); -var bufferEquals = require('buffer-equals'); -var stdin = require('./'); - -test('get stdin as a buffer', function (t) { - process.stdin.isTTY = false; - - var promise = stdin.buffer(function (data) { - t.true(bufferEquals(data, new Buffer('unicorns'))); - t.is(data.toString().trim(), 'unicorns'); - }); - - process.stdin.push(new Buffer('unicorns')); - process.stdin.emit('end'); - - return promise; -}); - -test('get empty buffer when no stdin', function (t) { - process.stdin.isTTY = true; - - return stdin.buffer(function (data) { - t.true(bufferEquals(data, new Buffer(''))); - }); -}); diff --git a/test-real.js b/test-real.js index 8ae6760..6241fd5 100644 --- a/test-real.js +++ b/test-real.js @@ -1,6 +1,3 @@ -'use strict'; -var stdin = require('./'); +import fn from './'; -stdin().then(function (data) { - process.exit(data ? 0 : 1); -}); +fn().then(data => process.exit(data ? 0 : 1)); diff --git a/test.js b/test.js index 43139eb..50b2557 100644 --- a/test.js +++ b/test.js @@ -1,24 +1,39 @@ -'use strict'; -var test = require('ava'); -var stdin = require('./'); +import test from 'ava'; +import bufferEquals from 'buffer-equals'; +import fn from './'; -test('get stdin', function (t) { +test.serial('get stdin', async t => { process.stdin.isTTY = false; - var promise = stdin(function (data) { - t.is(data.trim(), 'unicorns'); + setImmediate(() => { + process.stdin.push('unicorns'); + process.stdin.emit('end'); }); - process.stdin.push('unicorns'); + t.is((await fn()).trim(), 'unicorns'); +}); + +test.serial('get empty string when no stdin', async t => { + process.stdin.isTTY = true; + t.is(await fn(), ''); +}); + +test.serial('get stdin as a buffer', t => { + process.stdin.isTTY = false; + + const promise = fn.buffer(data => { + t.true(bufferEquals(data, new Buffer('unicorns'))); + t.is(data.toString().trim(), 'unicorns'); + }); + + process.stdin.push(new Buffer('unicorns')); process.stdin.emit('end'); return promise; }); -test('get empty string when no stdin', function (t) { +test.serial('get empty buffer when no stdin', async t => { process.stdin.isTTY = true; - return stdin(function (data) { - t.is(data, ''); - }); + t.true(bufferEquals(await fn.buffer(), new Buffer(''))); });