mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-25 16:07:37 +00:00
test: refactor pwd tests to AVA (#582)
This commit is contained in:
parent
76370ed946
commit
947e47ebb6
41
ava-test/pwd.js
Normal file
41
ava-test/pwd.js
Normal 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);
|
||||
});
|
||||
28
test/pwd.js
28
test/pwd.js
@ -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);
|
||||
Loading…
x
Reference in New Issue
Block a user