npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scratch-judge

v1.1.0

Published

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

Downloads

17

Readme

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:

  • String projectFile Path to the scratch project which is supported by the Scratch 3.0 and needs to be tested.
  • String fileNameFormat Optional. The format of the file name. Will replace #{n} to the testing point number. Such as P1000-#{n} will be translated to P1000-1.in and P1000-1.out . Default is #{n}.
  • String testFolder Path to your test folder which is included your input file like 1.in 1.out in order.
  • Number testpoints Optional. The amount of testing points will be run. Default is 10.
  • Number time Optional. Time that each testing points can use. The unit is milliseconds. Default is 1000.
  • Number mem Optional. Memory that each testing points can use. The unit is kilobytes. Default is 25600 (25MB) if traceFullMemory is true , or it's 40960 (4MB).
  • Boolean turbo Optional. Using turbo mode to test. Default is true.
  • Boolean debug Optional. Output debug message to stdout. Default is false.
  • Boolean format Optional. Output formatted json result after test. Only be used in cli. Default is false, output unformatted result.
  • Boolean traceFullMemory Optional. Trace memory of the NodeJS runtime. Or it will subtract from the memory scratch-vm running to the memory before start testing. Default is true.

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

  • point JudgeTestingPointResult Emit when a point is finished its test. It will return a value contain the result.
  • end JudgeTestingPointResult[] Emit when all points are finished their tests. It will return a array contains all result each testing point.
  • error Error Emit when a point occurred an error. But the other testing points will not stop and continue running.

JudgeTestingPointResult struct:

  • number id Point number.
  • string status Result of the test. Such as AC, RE, TLE, MLE, WA.
  • string details Detail of result, it will contain error string if status is RE, or line number of wrong answer if status is WA.
  • Error error An error object if status is RE.
  • number usedTime Time that testing point has used. In milliseconds.
  • number usedMemory Memory that testing point has used. In kilobytes.
  • string[] answer An array of project output if status is WA.

Like this project?

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