Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

Commit

Permalink
Add peripheral tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhynes committed Jul 9, 2015
1 parent 2cbd70c commit 0fd009b
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules/
coverage/
2 changes: 1 addition & 1 deletion autoload/js_host.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function! js_host#RequireJSHost(host)
let plugin_host = expand('<sfile>:p:h').'/index.js'
let plugin_host = g:node_host_dir . '/index.js'
let args = [plugin_host]
try
return rpcstart(a:host.orig_name, args)
Expand Down
26 changes: 6 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var gulp = require('gulp'),

PATH = {
src: [ 'index.js', 'gulpfile.js', 'lib/**/*.js' ],
test: 'test/**/*.js'
test: 'test/*.js'
}

if ( process.env.NODE_ENV !== 'production' ) {
Expand All @@ -22,26 +22,12 @@ if ( process.env.NODE_ENV !== 'production' ) {
tldr = require('mocha-tldr-reporter')
}

gulp.task( 'default', [ 'watch' ] )
gulp.task( 'default', [ 'checkstyle', 'test', 'watch' ] )

gulp.task( 'test', function( done ) {
gulp.src( PATH.src )
.pipe( plumber() )
.pipe( istanbul({
includeUntested: true
}) )
.pipe( istanbul.hookRequire() )
.on( 'finish', function() {
gulp.src( PATH.test )
.pipe( plumber() )
.pipe( mocha({ reporter: tldr }) )
.pipe( plumber() )
.pipe( istanbul.writeReports({
reporters: [ 'html' ]
}) )
.pipe( plumber() )
.on( 'end', done )
})
gulp.task( 'test', function() {
return gulp.src( PATH.test )
.pipe( plumber() )
.pipe( mocha({ reporter: tldr }) )
})

gulp.task( 'checkstyle', function() {
Expand Down
1 change: 0 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ Plugin.prototype.load = function() {
Module.prototype._compile = Plugin._compileInSandbox( sandbox )
moduleExports = sandbox.module.require( path )
Module.prototype._compile = oldCompile
console.log( moduleExports )
return moduleExports
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"devDependencies": {
"chai": "^3.0.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.0",
"gulp-jscs": "^1.6.0",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.1.2",
Expand Down
1 change: 1 addition & 0 deletions plugin/js_host.vim
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
let g:node_host_dir = expand('<sfile>:p:h:h')
call remote#host#Register('node', '*.js', function('js_host#RequireJSHost'))
24 changes: 24 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asi": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"freeze": true,
"immed": true,
"latedef": true,
"noarg": true,
"node": true,
"nonew": true,
"quotmark": "single",
"undef": true,
"unused": true,

"globals": {
"describe": true,
"before": true,
"beforeEach": true,
"it": true
}
}
25 changes: 25 additions & 0 deletions test/rplugin/node/test.js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
loaded = [] instanceof Array
globals = global
required = require('fixture')
console.log('ahh, silence')

plugin.commandSync('JSHostTestCmd', {
range: '',
nargs: '*',
}, function( nvim, args, range ) {
if ( args[0] === 'can haz response?') {
throw new Error('no >:(')
}
return [args, range]
})

plugin.autocmdSync('BufEnter', {
pattern: '*.js',
eval: 'expand("<afile>")'
}, function( nvim, filename ) {
debug('This is an annoying function')
})

plugin.function('Func', function( nvim, args ) {
return 'Funcy ' + args
})
11 changes: 11 additions & 0 deletions test/rplugin/node/test.js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "test.js",
"version": "1.0.0",
"description": "A test fixture",
"main": "index.js",
"scripts": {
"test": "gulp test"
},
"author": "",
"license": "MIT"
}
10 changes: 10 additions & 0 deletions test/test_devnull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var assert = require('chai').assert,
DevNull = require('../lib/devnull')

describe('DevNull', function() {
it('should be webscale', function( done ) {
var devnull = new DevNull()
assert.isNull( devnull.read(), 'Read should return null' )
assert.isTrue( devnull.write( 'benchmarks', done ), 'Write should succeed' )
})
})
49 changes: 49 additions & 0 deletions test/test_plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var assert = require('chai').assert,
path = require('path'),
Plugin = require('../lib/plugin'),
PLUGIN_PATH = path.join( __dirname, 'rplugin', 'node', 'test.js' )

describe('Plugin', function() {
var plugin

beforeEach( function() {
plugin = new Plugin( PLUGIN_PATH ).load()
})

it('should collect the specs from a plugin file', function() {
var exSPECted = [
{ type: 'command', name: 'JSHostTestCmd', sync: true,
opts: { range: '', nargs: '*' } },
{ type: 'autocmd', name: 'BufEnter', sync: true,
opts: { pattern: '*.js', eval: 'expand("<afile>")' } },
{ type: 'function', name: 'Func', sync: false, opts: {} }
]
assert.deepEqual( plugin.specs, exSPECted )
})

it('should collect the handlers from a plugin', function() {
var handlerId = [ PLUGIN_PATH, 'function', 'Func' ].join(':')
assert.strictEqual( plugin.handlers[ handlerId ]( null, 'town' ), 'Funcy town' )
})

it('should load the plugin a sandbox', function() {
var sandbox = plugin.sandbox
assert.isTrue( sandbox.loaded, 'Plugin was not loaded' )
assert.isUndefined( global.loaded, 'Plugin polluted host global scope' )
assert.notInclude( Object.keys( sandbox.process ), [ 'chdir', 'exit' ],
'Plugin should not have dangerous `process` functions')
})

it('should load files required by the plugin in a sandbox', function() {
var required = plugin.sandbox.required
assert.strictEqual( required.loaded, 'you bet!',
'require() from within a plugin failed' )
assert.notInclude( Object.keys( required.globals.process ), [ 'chdir', 'exit' ],
'Plugin should not have dangerous `process` functions')
})

it('should cache loaded plugins', function() {
var samePlugin = new Plugin( PLUGIN_PATH ).load()
assert.strictEqual( plugin, samePlugin )
})
})

0 comments on commit 0fd009b

Please sign in to comment.