Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eush77 committed Jun 8, 2015
1 parent 6a6b781 commit 12062a9
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- iojs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# repl-here

[![Dependency Status][david-badge]][david]
[![Build Status](https://travis-ci.org/eush77/repl-here.svg?branch=master)](https://travis-ci.org/eush77/repl-here) [![Dependency Status][david-badge]][david]

Node REPL that autoloads all modules in `./node_modules/` at startup, just like core libs.

Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"bin": {
"repl-here": "cli.js"
},
"scripts": {
"test": "tape test/*.js"
},
"files": [
"cli.js",
"index.js",
Expand Down Expand Up @@ -45,5 +48,9 @@
"text-table": "^0.2.0",
"validate-npm-package-name": "^2.2.0"
},
"devDependencies": {}
"devDependencies": {
"object.assign": "^3.0.0",
"tape": "^4.0.0",
"through2": "^0.6.5"
}
}
1 change: 1 addition & 0 deletions test/fixtures/node_modules/.bin/truth

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/node_modules/in+va+lid/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/fixtures/node_modules/module-as-directory/bin/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/node_modules/module-as-directory/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/node_modules/module-as-file.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

var replHere = require('..');

var test = require('tape'),
through = require('through2'),
assign = require('object.assign');

var Repl = require('repl'),
path = require('path');


test(function (t) {
var repl = Repl.start({
input: through(),
output: through()
});

var oldContext = assign({}, repl.context);

var loaded = ['module-as-directory', 'module-as-file.json'];
var loadedName = ['moduleAsDirectory', 'moduleAsFile'];
var failed = ['empty'];

replHere(repl, path.join(__dirname, 'fixtures'))
.on('fail', function (err, module) {
t.error(err, 'fails on a broken module');
t.notEqual(failed.indexOf(module), -1, 'fails on ' + module);
})

.on('load', function (module, name) {
var i = loaded.indexOf(module);
t.notEqual(i, -1, 'loads ' + module);
t.equal(loadedName[i], name, 'loads ' + module + ' as ' + name);
})

.on('end', function () {
t.test('context', function (t) {
Object.keys(oldContext).forEach(function (name) {
t.equal(repl.context[name], oldContext[name],
'includes ' + name + ' from the default repl context');
});

loadedName.forEach(function (name) {
t.equal(repl.context[name], name,
'includes ' + name + ' from the correct node module');
});

t.equal(Object.keys(repl.context).length,
Object.keys(oldContext).length + loadedName.length,
'doesn\'t have anything unexpected');
t.end();
});
t.end();
});
});

0 comments on commit 12062a9

Please sign in to comment.