test: refactor pwd tests to AVA (#582)

This commit is contained in:
Nate Fischer 2016-12-08 20:14:44 -08:00 committed by Brandon Freitag
parent 76370ed946
commit 947e47ebb6
2 changed files with 41 additions and 28 deletions

41
ava-test/pwd.js Normal file
View File

@ -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);
});

View File

@ -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);