shelljs/test/dirs.js
Nate Fischer 2ee83ebf74 refactor(test): update AVA and refactor tests (#760)
This updates tests for `AVA` 19.0.0+.

`AVA` 0.18.0 has a breaking change which changes the current working directory
for tests. As a result, we need to change 'resources' -> 'test/resources' (and
 similar path changes).

`AVA` 0.19.0 has a breaking change that all tests must run at least one assert.
This breaking change was already resolved by #746, so no change was necessary in
this PR.

This updates to `AVA` 0.21.0, since there are no other breaking changes.
2017-08-11 11:03:13 -07:00

40 lines
782 B
JavaScript

import path from 'path';
import test from 'ava';
import shell from '..';
test.beforeEach(() => {
shell.config.resetForTesting();
shell.pushd('test/resources/pushd');
shell.pushd('a');
});
//
// Valids
//
const trail = [
path.resolve(path.resolve(), 'test/resources/pushd/a'),
path.resolve(path.resolve(), 'test/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());
});