shelljs/test/dirs.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

40 lines
767 B
JavaScript

import path from 'path';
import test from 'ava';
import shell from '..';
test.beforeEach(() => {
shell.config.resetForTesting();
shell.pushd('resources/pushd');
shell.pushd('a');
});
//
// Valids
//
const trail = [
path.resolve(path.resolve(), 'resources/pushd/a'),
path.resolve(path.resolve(), 'resources/pushd'),
path.resolve(),
];
test('no arguments', t => {
t.deepEqual(shell.dirs(), trail);
});
test('Single items', t => {
t.is(shell.dirs('+0'), trail[0]);
t.is(shell.dirs('+1'), trail[1]);
t.is(shell.dirs('+2'), trail[2]);
t.is(shell.dirs('-0'), trail[2]);
t.is(shell.dirs('-1'), trail[1]);
t.is(shell.dirs('-2'), trail[0]);
});
test('Clearing items', t => {
t.deepEqual(shell.dirs('-c'), []);
t.falsy(shell.error());
});