Hi, scripter.
I wrote MV Plugin's test code, and run test.
Requirements:
Step1: Create "NewPlugin" directory, and "NewPlugin/NewPlugin.js" file.
Step2: Write "NewPlugin/gulpfile.js".
Step3: Create "NewPlugin/test" directory, and "NewPlugin/test/NewPlugin.spec.js".
Step4: Write "NewPlugin/test/NewPlugin.spec.js" test code.
Step5: Write "NewPlugin/NewPlugin.js" plugin code.
Step6: Run test.
Sample testable plugin is here, with test code is here.
I wrote MV Plugin's test code, and run test.
Requirements:
Step1: Create "NewPlugin" directory, and "NewPlugin/NewPlugin.js" file.
Step2: Write "NewPlugin/gulpfile.js".
var gulp = require('gulp');
var mocha = require('gulp-mocha');
gulp.task('default', ['test']);
gulp.task('test', function() {
return gulp.src('test/NewPlugin.spec.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});
var mocha = require('gulp-mocha');
gulp.task('default', ['test']);
gulp.task('test', function() {
return gulp.src('test/NewPlugin.spec.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});
Step4: Write "NewPlugin/test/NewPlugin.spec.js" test code.
isTest = true;
should = require('chai').should();
sinon = require('sinon');
describe('NewPlugin', function() {
// initialize
before(function() {
// define mock PluginManager
PluginManager = {};
PluginManager.parameters = sinon.stub()
.withArgs('MyTemplate').returns({
// PluginParam: 'default'
});
// define mock Game_Interpreter
Game_Interpreter = function() {};
Game_Interpreter.prototype.pluginCommand = sinon.stub();
// import Test functions.
NewPlugin = require('../NewPlugin.js');
// localFunction = NewPlugin.localFunction;
});
describe('call from PluginCommand', function() {
beforeEach(function() {
gameInterpreter = new Game_Interpreter();
});
describe('command name match', function() {
it('valid argments', function() {
gameInterpreter.pluginCommand('CommandName', ['validArguments']);
});
it('invalid argments', function() {
gameInterpreter.pluginCommand('isAnyItemHave', ['invalidArguments']);
});
});
it('command name not match', function() {
gameInterpreter.pluginCommand('otherCommand', ['1', 'foo', 'bar']);
});
});
});
should = require('chai').should();
sinon = require('sinon');
describe('NewPlugin', function() {
// initialize
before(function() {
// define mock PluginManager
PluginManager = {};
PluginManager.parameters = sinon.stub()
.withArgs('MyTemplate').returns({
// PluginParam: 'default'
});
// define mock Game_Interpreter
Game_Interpreter = function() {};
Game_Interpreter.prototype.pluginCommand = sinon.stub();
// import Test functions.
NewPlugin = require('../NewPlugin.js');
// localFunction = NewPlugin.localFunction;
});
describe('call from PluginCommand', function() {
beforeEach(function() {
gameInterpreter = new Game_Interpreter();
});
describe('command name match', function() {
it('valid argments', function() {
gameInterpreter.pluginCommand('CommandName', ['validArguments']);
});
it('invalid argments', function() {
gameInterpreter.pluginCommand('isAnyItemHave', ['invalidArguments']);
});
});
it('command name not match', function() {
gameInterpreter.pluginCommand('otherCommand', ['1', 'foo', 'bar']);
});
});
});
Step5: Write "NewPlugin/NewPlugin.js" plugin code.
var Imported = Imported || {};
Imported.NewPlugin = {};
(function() {
'use strict';
var parameters = PluginManager.parameters('NewPlugin');
// var PluginParam = String(parameters['PluginParam'] || 'default');
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'CommandName') {
// write code.
}
};
try {
if (isTest) {
// exports.NewPlugin = localFunction;
}
}
catch(e) {
}
})();
Imported.NewPlugin = {};
(function() {
'use strict';
var parameters = PluginManager.parameters('NewPlugin');
// var PluginParam = String(parameters['PluginParam'] || 'default');
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'CommandName') {
// write code.
}
};
try {
if (isTest) {
// exports.NewPlugin = localFunction;
}
}
catch(e) {
}
})();
$ cd NewPlugin
$ gulp
$ gulp