Initial commit of 001code-html Scratch frontend project.

Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-16 15:37:45 +08:00
commit 6e0a1fbcbb
11350 changed files with 965674 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
const test = require('tap').test;
const RateLimiter = require('../../src/util/rateLimiter.js');
test('rate limiter', t => {
// Create a rate limiter with maximum of 20 sends per second
const rate = 20;
const limiter = new RateLimiter(rate);
// Simulate time passing with a stubbed timer
let simulatedTime = Date.now();
limiter._timer = {timeElapsed: () => simulatedTime};
// The rate limiter starts with a number of tokens equal to the max rate
t.equal(limiter._count, rate);
// Running okayToSend a number of times equal to the max rate
// uses up all of the tokens
for (let i = 0; i < rate; i++) {
t.true(limiter.okayToSend());
// Tokens are counting down
t.equal(limiter._count, rate - (i + 1));
}
t.false(limiter.okayToSend());
// Advance the timer enough so we get exactly one more token
// One extra millisecond is required to get over the threshold
simulatedTime += (1000 / rate) + 1;
t.true(limiter.okayToSend());
t.false(limiter.okayToSend());
t.end();
});