Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions ava-test/to.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import fs from 'fs';

import test from 'ava';

import shell from '..';
import utils from './utils/utils';

test.beforeEach(t => {
t.context.tmp = utils.getTempDir();
shell.config.silent = true;
shell.mkdir(t.context.tmp);
});

test.afterEach.always(t => {
shell.rm('-rf', t.context.tmp);
});


//
// Invalids
//

test('Normal strings don\'t have \'.to()\' anymore', t => {
const str = 'hello world';
t.is(typeof str.to, 'undefined');
});

test('no file argument', t => {
shell.ShellString('hello world').to();
t.truthy(shell.error());
});

test('cannot write to a non-existent directory', t => {
t.falsy(fs.existsSync('/asdfasdf')); // sanity check
shell.ShellString('hello world').to('/asdfasdf/file');
t.truthy(shell.error());
});

//
// Valids
//

test('can be chained', t => {
shell.ShellString('hello world').to(`${t.context.tmp}/to1`).to(`${t.context.tmp}/to2`);
let result = shell.cat(`${t.context.tmp}/to1`);
t.falsy(shell.error());
t.is(result.toString(), 'hello world');
result = shell.cat(`${t.context.tmp}/to2`);
t.falsy(shell.error());
t.is(result.toString(), 'hello world');
});

test('With a glob', t => {
shell.touch(`${t.context.tmp}/to1`);
shell.ShellString('goodbye').to(`${t.context.tmp}/t*1`);
t.falsy(fs.existsSync(`${t.context.tmp}/t*1`), 'globs are not interpreted literally');
const result = shell.cat(`${t.context.tmp}/to1`);
t.falsy(shell.error());
t.is(result.toString(), 'goodbye');
});
47 changes: 0 additions & 47 deletions test/to.js

This file was deleted.