shelljs/test/global.js
Nate Fischer 57df38c6ea
chore(lint): update lint dependencies (#948)
This updates `eslint-config-airbnb-base` and `eslint-plugin-import`.
This also addresses lint errors these updates raise, and excludes
several rules.

This also adds a minor simplification to the gendocs script.

Test: npm run lint
Test: npm run gendocs
2019-07-12 12:36:55 -07:00

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