Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.
Original Source
- Original title: MV Plugin Test Code
- Original author: saronpasu
- Original date: November 15, 2015
- Source thread: https://forums.rpgmakerweb.com/threads/mv-plugin-test-code.50564/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > JS Plugins In Development
Summary
Hi, scripter. I wrote MV Plugin's test code, and run test. Requirements: Node.js link
Archived First Post
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
Downloads / Referenced Files
Log in to download
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadCreator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
0
replies
1
view
Topic Summary
Loading summary...