shelljs/test/pwd.js
Nate Fischer ac0ff873f1 refactor: add config.reset() and .resetForTesting() (#641)
Add .reset() and .resetForTesting() to shell.config and use .resetForTesting()
as a standard set-up for unit tests.
2017-01-07 22:40:38 -08:00

42 lines
777 B
JavaScript

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.resetForTesting();
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);
});