From 947e47ebb6614bcfc53afa6d5c1d5d84986535cd Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Thu, 8 Dec 2016 20:14:44 -0800 Subject: [PATCH] test: refactor pwd tests to AVA (#582) --- ava-test/pwd.js | 41 +++++++++++++++++++++++++++++++++++++++++ test/pwd.js | 28 ---------------------------- 2 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 ava-test/pwd.js delete mode 100644 test/pwd.js diff --git a/ava-test/pwd.js b/ava-test/pwd.js new file mode 100644 index 0000000..84ad68b --- /dev/null +++ b/ava-test/pwd.js @@ -0,0 +1,41 @@ +import path from 'path'; + +import test from 'ava'; + +import shell from '..'; +import utils from './utils/utils'; + +const cur = process.cwd(); + +test.beforeEach(t => { + t.context.tmp = utils.getTempDir(); + shell.config.silent = true; + shell.mkdir(t.context.tmp); +}); + +test.afterEach.always(t => { + process.chdir(cur); + shell.rm('-rf', t.context.tmp); +}); + + +// +// Valids +// + +test('initial directory', t => { + const cwd = shell.pwd(); + t.falsy(shell.error()); + t.is(cwd.code, 0); + t.falsy(cwd.stderr); + t.is(cwd.toString(), path.resolve('.')); +}); + +test('after changing directory', t => { + shell.cd(t.context.tmp); + const cwd = shell.pwd(); + t.is(cwd.code, 0); + t.falsy(cwd.stderr); + t.falsy(shell.error()); + t.is(path.basename(cwd.toString()), t.context.tmp); +}); diff --git a/test/pwd.js b/test/pwd.js deleted file mode 100644 index 8d86b24..0000000 --- a/test/pwd.js +++ /dev/null @@ -1,28 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'); -var path = require('path'); - -shell.config.silent = true; - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Valids -// - -var _pwd = shell.pwd(); -assert.equal(shell.error(), null); -assert.equal(_pwd.code, 0); -assert.ok(!_pwd.stderr); -assert.equal(_pwd, path.resolve('.')); - -shell.cd('tmp'); -_pwd = shell.pwd(); -assert.equal(_pwd.code, 0); -assert.ok(!_pwd.stderr); -assert.equal(shell.error(), null); -assert.equal(path.basename(_pwd.toString()), 'tmp'); - -shell.exit(123);