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

51 lines
1.1 KiB
JavaScript

/* globals cat, config, cp, env, error, mkdir, rm */
import fs from 'fs';
import test from 'ava';
import '../global';
import utils from './utils/utils';
test.beforeEach(t => {
t.context.tmp = utils.getTempDir();
config.resetForTesting();
mkdir(t.context.tmp);
});
test.afterEach.always(t => {
rm('-rf', t.context.tmp);
});
//
// Valids
//
test('env is exported', t => {
t.is(process.env, env);
});
test('cat', t => {
const result = cat('test/resources/cat/file1');
t.falsy(error());
t.is(result.code, 0);
t.is(result.toString(), 'test1\n');
});
test('rm', t => {
cp('-f', 'test/resources/file1', `${t.context.tmp}/file1`);
t.truthy(fs.existsSync(`${t.context.tmp}/file1`));
const result = rm(`${t.context.tmp}/file1`);
t.falsy(error());
t.is(result.code, 0);
t.falsy(fs.existsSync(`${t.context.tmp}/file1`));
});
test('String.prototype is modified for global require', t => {
'foo'.to(`${t.context.tmp}/testfile.txt`);
t.is('foo', cat(`${t.context.tmp}/testfile.txt`).toString());
'bar'.toEnd(`${t.context.tmp}/testfile.txt`);
t.is('foobar', cat(`${t.context.tmp}/testfile.txt`).toString());
});