saronpasu

Villager
Member
Joined
Apr 6, 2012
Messages
26
Reaction score
32
First Language
Japanese
Primarily Uses
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".

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'}));

});
Step3: Create "NewPlugin/test" directory, and "NewPlugin/test/NewPlugin.spec.js".

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']);

        });

    });

 

});
 

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) {

    }

})();
Step6: Run test.

$ cd NewPlugin

$ gulp
Sample testable plugin is here, with test code is here.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,872
First Language
English
Hmm, unit testing framework to make it easier to test code. I like it.
 

hugolnx

Warper
Member
Joined
Dec 2, 2015
Messages
4
Reaction score
1
First Language
Portuguese
Great initiative!

I think automated tests will be very userful, maybe we shall be able to detect conflicts between scripts. :)

Congrats!
 

Latest Threads

Latest Posts

Latest Profile Posts


Swag collecting in the new randomly generated area. Now the mini map also shows the randomly generated features... And even illustrates the whole "bubble" system" that I made to manage memory... Though that part's inadvertent. We'll just call that "the fog of war"... Yes, that's what we'll do. Nobody will be the wiser! :kaopride:
not me being not lazy for 5 seconds and drawing another char portrait (her name is hazel)
its_hazel.png
Been a while since the last time I made a song remix. Had a blast making this
One thing those jp developer still get wrong about boob physic is that... men's muscly hard pecs can jiggle too.
Definitely glad I haven't released a few of my plugins that are technically done. As I learn more, I find ways to make my code more efficient, and in one case so far, discovered an existing function that did EXACTLY what I created my own function to do.

Forum statistics

Threads
110,454
Messages
1,053,432
Members
143,541
Latest member
Neikoku
Top