Steve-xmh / scratch-judge

A custom scratch-vm used to watch program status and output result about the program.
BSD 3-Clause "New" or "Revised" License
10 stars 2 forks source link

scratch-judge

A custom scratch-vm used to watch program status and output result about the program.

Usage (English)

By Bash:

npm i -g scratch-judge
scj -h
scj src/index.js -p test/test.sb3 -d test/ -o 3
# Do your own :D

By NodeJS:

const judge = require('scratch-judge')
judge({
    projectFile: 'path/to/your/scratch/project/file',
    fileNameFormat: '#{n}',
    testFolder: 'path/to/your/test/folder',
    testpoints: 10,
    time: 1000,
    mem: 40960,
    turbo: true,
    format: false
}).then((evt) => {
    evt.on('point', (result) => {
        // Emit when a point is finished its test.
    }).on('error', (err) => {
        // Emit when a point occurs an error.
    }).once('end', (results) => {
        // Emit when all the points are finished their test.
        // Result is an array contains all the result.
    })
})

CLI Description

Run scj -h to check usage.

API Description

Promise judge(Object options) Start a test.

If runs as command, it will output the testing result to stdout.

Or if be invoke as module, it will return a Promise and resolve the result types of JSON.

Here is a list of available options:

Then it will return a promise will reslove with a JudgeEvent extends on EventEmitter, it will emit these events while testing:

JudgeTestingPointResult struct:

Like this project?

Feel free to give tips to me! Chinese link. (I don't have patreon sry ;-;)