Jeremy Penner
8dc252d70f
subrepo: subdir: "jsnes" merged: "d8021d0" upstream: origin: "https://github.com/bfirsh/jsnes.git" branch: "master" commit: "d8021d0" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
var assert = require("chai").assert;
|
|
var fs = require("fs");
|
|
var NES = require("../src/nes");
|
|
var sinon = require("sinon");
|
|
|
|
describe("NES", function() {
|
|
it("can be initialized", function() {
|
|
var nes = new NES();
|
|
});
|
|
|
|
it("loads a ROM and runs a frame", function(done) {
|
|
var onFrame = sinon.spy();
|
|
var nes = new NES({ onFrame: onFrame });
|
|
fs.readFile("roms/croom/croom.nes", function(err, data) {
|
|
if (err) return done(err);
|
|
nes.loadROM(data.toString("binary"));
|
|
nes.frame();
|
|
assert(onFrame.calledOnce);
|
|
assert.isArray(onFrame.args[0][0]);
|
|
assert.lengthOf(onFrame.args[0][0], 256 * 240);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("generates the correct frame buffer", function(done) {
|
|
var onFrame = sinon.spy();
|
|
var nes = new NES({ onFrame: onFrame });
|
|
fs.readFile("roms/croom/croom.nes", function(err, data) {
|
|
if (err) return done(err);
|
|
nes.loadROM(data.toString("binary"));
|
|
// Check the first index of a white pixel on the first 6 frames of
|
|
// output. Croom only uses 2 colors on the initial screen which makes
|
|
// it easy to detect. Comparing full snapshots of each frame takes too
|
|
// long.
|
|
var expectedIndexes = [-1, -1, -1, 2056, 4104, 4104];
|
|
for (var i = 0; i < 6; i++) {
|
|
nes.frame();
|
|
assert.equal(onFrame.lastCall.args[0].indexOf(0xFFFFFF), expectedIndexes[i]);
|
|
}
|
|
done();
|
|
});
|
|
});
|
|
|
|
describe("#loadROM()", function() {
|
|
it("throws an error given an invalid ROM", function() {
|
|
var nes = new NES();
|
|
assert.throws(function() {
|
|
nes.loadROM("foo");
|
|
}, "Not a valid NES ROM.");
|
|
});
|
|
});
|
|
|
|
describe("#getFPS()", function() {
|
|
var nes = new NES();
|
|
before(function(done) {
|
|
fs.readFile("roms/croom/croom.nes", function(err, data) {
|
|
if (err) return done(err);
|
|
nes.loadROM(data.toString("binary"));
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("returns an FPS count when frames have been run", function() {
|
|
assert.isNull(nes.getFPS());
|
|
nes.frame();
|
|
nes.frame();
|
|
var fps = nes.getFPS();
|
|
assert.isNumber(fps);
|
|
assert.isAbove(fps, 0);
|
|
});
|
|
});
|
|
});
|