Skip to content

Commit

Permalink
jest + eslint + nsp + coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 27, 2017
1 parent a41c95d commit 0ba55c5
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
coverage/
44 changes: 0 additions & 44 deletions .jshintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_js:
- 4
- 6
- node
after_script:
- cat ./coverage/lcov.info | coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mem-fs-editor [![Build Status](https://travis-ci.org/SBoudrias/mem-fs-editor.svg?branch=master)](https://travis-ci.org/SBoudrias/mem-fs-editor)
mem-fs-editor [![Build Status](https://img.shields.io/travis/SBoudrias/mem-fs-editor.svg)](https://travis-ci.org/SBoudrias/mem-fs-editor) [![NPM version](https://img.shields.io/npm/v/generator-license.svg)](https://www.npmjs.org/package/generator-license) [![Coverage Status](https://coveralls.io/repos/github/SBoudrias/mem-fs-editor/badge.svg)](https://coveralls.io/github/SBoudrias/mem-fs-editor) [![David Dependencies](https://img.shields.io/david/SBoudrias/mem-fs-editor.svg)](https://david-dm.org/SBoudrias/mem-fs-editor) [![David Dev Dependencies](https://img.shields.io/david/dev/SBoudrias/mem-fs-editor.svg)](https://david-dm.org/SBoudrias/mem-fs-editor#info=devDependencies)
=============

File edition helpers working on top of [mem-fs](https://github.com/SBoudrias/mem-fs)
Expand Down
7 changes: 3 additions & 4 deletions test/commit.js → __tests__/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('#commit()', function () {
var fixtureDir = path.join(os.tmpdir(), '/mem-fs-editor-test-fixture');
var output = path.join(os.tmpdir(), '/mem-fs-editor-test');

beforeEach(function(done) {
beforeEach(function (done) {
rimraf.sync(fixtureDir);
var store = memFs.create();
this.fs = editor.create(store);
Expand All @@ -39,7 +39,7 @@ describe('#commit()', function () {
var filter = through.obj(function (file, enc, cb) {
called++;
file.contents = new Buffer('modified');
this.push(file)
this.push(file);
cb();
});

Expand Down Expand Up @@ -96,8 +96,7 @@ describe('#commit()', function () {
this.fs.copy(path.join(__dirname, 'fixtures/file-a.txt'), 'copy-to-delete');
this.fs.delete('copy-to-delete');

var file = this.fs.store.get('to-delete');

this.fs.store.get('to-delete');
this.fs.commit([
through.obj(function (file, enc, cb) {
assert.notEqual(file.path, path.resolve('to-delete'));
Expand Down
12 changes: 6 additions & 6 deletions test/copy-tpl.js → __tests__/copy-tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ var editor = require('..');
var memFs = require('mem-fs');

describe('#copyTpl()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});

it('copy file and process contents as underscore template', function () {
var filepath = path.join(__dirname, 'fixtures/file-tpl.txt');
var newPath = '/new/path/file.txt';
this.fs.copyTpl(filepath, newPath, { name: 'new content' });
this.fs.copyTpl(filepath, newPath, {name: 'new content'});
assert.equal(this.fs.read(newPath), 'new content\n');
});

it('allow setting custom template delimiters', function() {
it('allow setting custom template delimiters', function () {
var filepath = path.join(__dirname, 'fixtures/file-tpl-custom-delimiter.txt');
var newPath = '/new/path/file.txt';
this.fs.copyTpl(filepath, newPath, { name: 'mustache' }, {
this.fs.copyTpl(filepath, newPath, {name: 'mustache'}, {
delimiter: '?'
});
assert.equal(this.fs.read(newPath), 'mustache\n');
});

it('allow including partials', function() {
it('allow including partials', function () {
var filepath = path.join(__dirname, 'fixtures/file-tpl-include.txt');
var newPath = '/new/path/file.txt';
this.fs.copyTpl(filepath, newPath);
assert.equal(this.fs.read(newPath), 'partial\n\n');
});

it('allow including glob options', function() {
it('allow including glob options', function () {
var filenames = [
path.join(__dirname, 'fixtures/file-tpl-partial.txt'),
path.join(__dirname, 'fixtures/file-tpl.txt')
Expand Down
22 changes: 13 additions & 9 deletions test/copy.js → __tests__/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var editor = require('..');
var memFs = require('mem-fs');

describe('#copy()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -36,7 +36,7 @@ describe('#copy()', function () {
var newPath = '/new/path/file.txt';
this.fs.copy(filepath, newPath, {
process: function (contentsArg) {
assert(contentsArg instanceof Buffer)
assert(contentsArg instanceof Buffer);
assert.equal(contentsArg, initialContents);
return contents;
}
Expand All @@ -45,48 +45,52 @@ describe('#copy()', function () {
});

it('copy by directory', function () {
this.fs.copy(__dirname + '/fixtures', '/output');
this.fs.copy(path.join(__dirname, '/fixtures'), '/output');
assert.equal(this.fs.read('/output/file-a.txt'), 'foo\n');
assert.equal(this.fs.read('/output/nested/file.txt'), 'nested\n');
});

it('copy by globbing', function () {
this.fs.copy(__dirname + '/fixtures/**', '/output');
this.fs.copy(path.join(__dirname, '/fixtures/**'), '/output');
assert.equal(this.fs.read('/output/file-a.txt'), 'foo\n');
assert.equal(this.fs.read('/output/nested/file.txt'), 'nested\n');
});

it('copy by globbing multiple patterns', function () {
this.fs.copy([__dirname + '/fixtures/**', '!**/*tpl*'], '/output');
this.fs.copy([path.join(__dirname, '/fixtures/**'), '!**/*tpl*'], '/output');
assert.equal(this.fs.read('/output/file-a.txt'), 'foo\n');
assert.equal(this.fs.read('/output/nested/file.txt'), 'nested\n');
assert.throws(this.fs.read.bind(this.fs, '/output/file-tpl.txt'));
});

it('copy files by globbing and process contents', function () {
var process = sinon.stub().returnsArg(0);
this.fs.copy(__dirname + '/fixtures/**', '/output', { process: process });
this.fs.copy(path.join(__dirname, '/fixtures/**'), '/output', {process: process});
sinon.assert.callCount(process, 7); // 5 total files under 'fixtures', not counting folders
assert.equal(this.fs.read('/output/file-a.txt'), 'foo\n');
assert.equal(this.fs.read('/output/nested/file.txt'), 'nested\n');
});

it('accepts directory name with "."', function () {
this.fs.copy(__dirname + '/fixtures/**', '/out.put');
this.fs.copy(path.join(__dirname, '/fixtures/**'), '/out.put');
assert.equal(this.fs.read('/out.put/file-a.txt'), 'foo\n');
assert.equal(this.fs.read('/out.put/nested/file.txt'), 'nested\n');
});

it('requires destination directory when globbing', function () {
assert.throws(
this.fs.copy.bind(this.fs, __dirname + '/fixtures/**', __dirname + '/fixtures/file-a.txt')
this.fs.copy.bind(
this.fs,
path.join(__dirname, '/fixtures/**'),
path.join(__dirname, '/fixtures/file-a.txt')
)
);
});

it('preserve permissions', function (done) {
var filename = path.join(os.tmpdir(), 'perm.txt');
var copyname = path.join(os.tmpdir(), 'copy-perm.txt');
fs.writeFileSync(filename, 'foo', { mode: parseInt(733, 8) });
fs.writeFileSync(filename, 'foo', {mode: parseInt(733, 8)});

this.fs.copy(filename, copyname);

Expand Down
4 changes: 2 additions & 2 deletions test/delete.js → __tests__/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var editor = require('..');
var memFs = require('mem-fs');

describe('#delete()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -32,7 +32,7 @@ describe('#delete()', function () {
assert.equal(this.fs.store.get('foo').state, 'deleted');
});

it('after delete a file should set isNew flag on write', function() {
it('after delete a file should set isNew flag on write', function () {
var filepath = path.join(__dirname, 'fixtures/file-a.txt');
this.fs.delete(filepath);
this.fs.write(filepath, 'foo');
Expand Down
6 changes: 3 additions & 3 deletions test/exists.js → __tests__/exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var fileA = path.join(__dirname, 'fixtures/file-a.txt');
var fileDelete = path.join(__dirname, 'fixtures/deleteAfter');

describe('#exists()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -18,13 +18,13 @@ describe('#exists()', function () {
assert.equal(this.fs.exists('something that doesnt exist'), false);
});

it('file does exist', function () {
it('file does exist', function () {
this.fs.read(fileA);
assert.equal(this.fs.exists(fileA), true);
});

it('file doesn\'t exist after delete', function () {
this.fs.write(fileDelete, 'some content' );
this.fs.write(fileDelete, 'some content');
this.fs.delete(fileDelete);
assert.equal(this.fs.exists(fileDelete), false);
});
Expand Down
5 changes: 2 additions & 3 deletions test/extend-json.js → __tests__/extend-json.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

var assert = require('assert');
var path = require('path');
var sinon = require('sinon');
var editor = require('..');
var memFs = require('mem-fs');

describe('#extendJSON()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand Down Expand Up @@ -36,7 +35,7 @@ describe('#extendJSON()', function () {

it('stringify with optional arguments (for JSON.stringify)', function () {
var filepath = path.join(__dirname, 'fixtures/does-not-exist.txt');
var contents = { foo: 'bar' };
var contents = {foo: 'bar'};
var write = sinon.spy(this.fs, 'write');
this.fs.extendJSON(filepath, contents, '\n', 4);
sinon.assert.calledOnce(write);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions test/move.js → __tests__/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

var assert = require('assert');
var path = require('path');
var sinon = require('sinon');
var editor = require('..');
var memFs = require('mem-fs');

describe('#move()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -21,7 +20,7 @@ describe('#move()', function () {
assert.throws(this.fs.read.bind(this.fs, filepath));
});

it('move directory', function() {
it('move directory', function () {
var filename = 'file.txt';
var dirpath = path.join(__dirname, 'fixtures/nested');
var filepath = path.join(dirpath, filename);
Expand All @@ -32,7 +31,7 @@ describe('#move()', function () {
assert.throws(this.fs.read.bind(this.fs, filepath));
});

it('move file to an existing `to` path', function() {
it('move file to an existing `to` path', function () {
var filepath = path.join(__dirname, 'fixtures/file-a.txt');
var initialContents = this.fs.read(filepath);
var newpath = path.join(__dirname, 'fixtures/nested/file.txt');
Expand All @@ -55,7 +54,7 @@ describe('#move()', function () {
assert.throws(this.fs.read.bind(this.fs, path.join(fromdir, 'file.txt')));
});

it('throws when moving directory to an existing `to` path (as a file)', function() {
it('throws when moving directory to an existing `to` path (as a file)', function () {
var filepath = path.join(__dirname, 'fixtures/file-a.txt');
var frompath = path.join(__dirname, 'fixtures/nested');

Expand Down
6 changes: 3 additions & 3 deletions test/read-json.js → __tests__/read-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var memFs = require('mem-fs');
var escape = require('escape-regexp');

describe('#readJSON()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -28,12 +28,12 @@ describe('#readJSON()', function () {
});

it('return defaults if file does not exist and defaults is provided', function () {
var obj = this.fs.readJSON(path.join(__dirname, 'no-such-file.json'), { foo: 'bar' });
var obj = this.fs.readJSON(path.join(__dirname, 'no-such-file.json'), {foo: 'bar'});
assert.equal(obj.foo, 'bar');
});

it('throw error if file could not be parsed as JSON, even if defaults is provided', function () {
assert.throws(this.fs.readJSON.bind(this.fs, path.join(__dirname, 'fixtures/file-tpl.txt'), { foo: 'bar' }));
assert.throws(this.fs.readJSON.bind(this.fs, path.join(__dirname, 'fixtures/file-tpl.txt'), {foo: 'bar'}));
});

it('throw error with file path info', function () {
Expand Down
10 changes: 5 additions & 5 deletions test/read.js → __tests__/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var memFs = require('mem-fs');
var fileA = path.join(__dirname, 'fixtures/file-a.txt');

describe('#read()', function () {
beforeEach(function() {
beforeEach(function () {
var store = memFs.create();
this.fs = editor.create(store);
});
Expand All @@ -19,7 +19,7 @@ describe('#read()', function () {
});

it('get the buffer content of a file', function () {
var content = this.fs.read(fileA, { raw: true });
var content = this.fs.read(fileA, {raw: true});
assert(content instanceof Buffer);
assert.equal(content.toString(), 'foo\n');
});
Expand All @@ -34,12 +34,12 @@ describe('#read()', function () {
});

it('returns defaults as String if file does not exist and defaults is provided', function () {
var content = this.fs.read('file-who-does-not-exist.txt', { defaults: 'foo\n' });
var content = this.fs.read('file-who-does-not-exist.txt', {defaults: 'foo\n'});
assert.equal(content, 'foo\n');
});

it('returns defaults as String if file does not exist and defaults is provided as empty string', function () {
var content = this.fs.read('file-who-does-not-exist.txt', { defaults: '' });
var content = this.fs.read('file-who-does-not-exist.txt', {defaults: ''});
assert.equal(content, '');
});

Expand All @@ -54,7 +54,7 @@ describe('#read()', function () {

it('returns defaults if file is deleted', function () {
this.fs.delete(fileA);
var content = this.fs.read(fileA, { defaults: 'foo' });
var content = this.fs.read(fileA, {defaults: 'foo'});
assert.equal(content, 'foo');
});
});
1 change: 0 additions & 1 deletion test/util.js → __tests__/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('util.getCommonPath()', function () {
});
});


describe('util.globify()', function () {
it('returns path for file path', function () {
var filePath = path.resolve(__dirname, 'fixtures/file-a.txt');
Expand Down
Loading

0 comments on commit 0ba55c5

Please sign in to comment.