Best JavaScript code snippet using playwright-internal
transaction.js
Source:transaction.js
1var request = require("request");2var qs = require("querystring");3var uuid = require("uuid");4var should = require("should");5var sinon = require("sinon");6var url = require("url");7var ua = require("../lib/index.js");8var utils = require("../lib/utils.js")9var config = require("../lib/config.js")10describe("ua", function () {11 describe("#transaction", function () {12 var _enqueue;13 beforeEach(function () {14 _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function (type, params, fn) {15 if (fn) {16 (typeof fn).should.equal('function', "#_enqueue should receive a callback")17 fn();18 }19 return this;20 });21 });22 afterEach(function () {23 _enqueue.restore()24 });25 it("should be available via the #t shortcut", function () {26 var visitor = ua()27 visitor.t.should.equal(visitor.transaction)28 });29 it("should accept arguments (transaction)", function () {30 var transaction = Math.random().toString();31 var visitor = ua()32 var result = visitor.transaction(transaction);33 visitor._context = result._context;34 result.should.eql(visitor, "should return a visitor that is identical except for the context");35 result.should.be.instanceof(ua.Visitor);36 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")37 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");38 _enqueue.args[0][0].should.equal("transaction");39 _enqueue.args[0][1].should.have.keys("ti")40 _enqueue.args[0][1].ti.should.equal(transaction);41 });42 it("should accept arguments (transaction, fn)", function () {43 var transaction = Math.random().toString();44 var fn = sinon.spy()45 ua().transaction(transaction, fn);46 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");47 _enqueue.args[0][0].should.equal("transaction");48 _enqueue.args[0][1].should.have.keys("ti")49 _enqueue.args[0][1].ti.should.equal(transaction);50 fn.calledOnce.should.equal(true, "callback should have been called once")51 });52 it("should accept arguments (transaction, revenue)", function () {53 var transaction = Math.random().toString();54 var revenue = Math.random();55 ua().transaction(transaction, revenue);56 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");57 _enqueue.args[0][0].should.equal("transaction");58 _enqueue.args[0][1].should.have.keys("ti", "tr")59 _enqueue.args[0][1].ti.should.equal(transaction);60 _enqueue.args[0][1].tr.should.equal(revenue);61 });62 it("should accept arguments (transaction, revenue, fn)", function () {63 var transaction = Math.random().toString();64 var revenue = Math.random();65 var fn = sinon.spy()66 ua().transaction(transaction, revenue, fn);67 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");68 _enqueue.args[0][0].should.equal("transaction");69 _enqueue.args[0][1].should.have.keys("ti", "tr")70 _enqueue.args[0][1].ti.should.equal(transaction);71 _enqueue.args[0][1].tr.should.equal(revenue);72 fn.calledOnce.should.equal(true, "callback should have been called once")73 });74 it("should accept arguments (transaction, revenue, shipping)", function () {75 var transaction = Math.random().toString();76 var revenue = Math.random();77 var shipping = Math.random();78 ua().transaction(transaction, revenue, shipping);79 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");80 _enqueue.args[0][0].should.equal("transaction");81 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts")82 _enqueue.args[0][1].ti.should.equal(transaction);83 _enqueue.args[0][1].tr.should.equal(revenue);84 _enqueue.args[0][1].ts.should.equal(shipping);85 });86 it("should accept arguments (transaction, revenue, shipping, fn)", function () {87 var transaction = Math.random().toString();88 var revenue = Math.random();89 var shipping = Math.random();90 var fn = sinon.spy()91 ua().transaction(transaction, revenue, shipping, fn);92 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");93 _enqueue.args[0][0].should.equal("transaction");94 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts")95 _enqueue.args[0][1].ti.should.equal(transaction);96 _enqueue.args[0][1].tr.should.equal(revenue);97 _enqueue.args[0][1].ts.should.equal(shipping);98 fn.calledOnce.should.equal(true, "callback should have been called once")99 });100 it("should accept arguments (transaction, revenue, shipping, tax)", function () {101 var transaction = Math.random().toString();102 var revenue = Math.random();103 var shipping = Math.random();104 var tax = Math.random();105 ua().transaction(transaction, revenue, shipping, tax);106 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");107 _enqueue.args[0][0].should.equal("transaction");108 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt")109 _enqueue.args[0][1].ti.should.equal(transaction);110 _enqueue.args[0][1].tr.should.equal(revenue);111 _enqueue.args[0][1].ts.should.equal(shipping);112 _enqueue.args[0][1].tt.should.equal(tax);113 });114 it("should accept arguments (transaction, revenue, shipping, tax, fn)", function () {115 var transaction = Math.random().toString();116 var revenue = Math.random();117 var shipping = Math.random();118 var tax = Math.random();119 var fn = sinon.spy()120 ua().transaction(transaction, revenue, shipping, tax, fn);121 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");122 _enqueue.args[0][0].should.equal("transaction");123 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt")124 _enqueue.args[0][1].ti.should.equal(transaction);125 _enqueue.args[0][1].tr.should.equal(revenue);126 _enqueue.args[0][1].ts.should.equal(shipping);127 _enqueue.args[0][1].tt.should.equal(tax);128 fn.calledOnce.should.equal(true, "callback should have been called once")129 });130 it("should accept arguments (transaction, revenue, shipping, tax, affiliation)", function () {131 var transaction = Math.random().toString();132 var revenue = Math.random();133 var shipping = Math.random();134 var tax = Math.random();135 var affiliation = Math.random().toString();136 ua().transaction(transaction, revenue, shipping, tax, affiliation);137 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");138 _enqueue.args[0][0].should.equal("transaction");139 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta")140 _enqueue.args[0][1].ti.should.equal(transaction);141 _enqueue.args[0][1].tr.should.equal(revenue);142 _enqueue.args[0][1].ts.should.equal(shipping);143 _enqueue.args[0][1].tt.should.equal(tax);144 _enqueue.args[0][1].ta.should.equal(affiliation);145 });146 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, fn)", function () {147 var transaction = Math.random().toString();148 var revenue = Math.random();149 var shipping = Math.random();150 var tax = Math.random();151 var affiliation = Math.random().toString();152 var fn = sinon.spy()153 ua().transaction(transaction, revenue, shipping, tax, affiliation, fn);154 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");155 _enqueue.args[0][0].should.equal("transaction");156 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta")157 _enqueue.args[0][1].ti.should.equal(transaction);158 _enqueue.args[0][1].tr.should.equal(revenue);159 _enqueue.args[0][1].ts.should.equal(shipping);160 _enqueue.args[0][1].tt.should.equal(tax);161 _enqueue.args[0][1].ta.should.equal(affiliation);162 fn.calledOnce.should.equal(true, "callback should have been called once")163 });164 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, params)", function () {165 var transaction = Math.random().toString();166 var revenue = Math.random();167 var shipping = Math.random();168 var tax = Math.random();169 var affiliation = Math.random().toString();170 var params = {p: Math.random().toString()}171 ua().transaction(transaction, revenue, shipping, tax, affiliation, params);172 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");173 _enqueue.args[0][0].should.equal("transaction");174 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")175 _enqueue.args[0][1].ti.should.equal(transaction);176 _enqueue.args[0][1].tr.should.equal(revenue);177 _enqueue.args[0][1].ts.should.equal(shipping);178 _enqueue.args[0][1].tt.should.equal(tax);179 _enqueue.args[0][1].ta.should.equal(affiliation);180 _enqueue.args[0][1].p.should.equal(params.p);181 });182 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, params, fn)", function () {183 var transaction = Math.random().toString();184 var revenue = Math.random();185 var shipping = Math.random();186 var tax = Math.random();187 var affiliation = Math.random().toString();188 var params = {p: Math.random().toString()}189 var fn = sinon.spy()190 ua().transaction(transaction, revenue, shipping, tax, affiliation, params, fn);191 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");192 _enqueue.args[0][0].should.equal("transaction");193 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")194 _enqueue.args[0][1].ti.should.equal(transaction);195 _enqueue.args[0][1].tr.should.equal(revenue);196 _enqueue.args[0][1].ts.should.equal(shipping);197 _enqueue.args[0][1].tt.should.equal(tax);198 _enqueue.args[0][1].ta.should.equal(affiliation);199 _enqueue.args[0][1].p.should.equal(params.p);200 fn.calledOnce.should.equal(true, "callback should have been called once")201 });202 it("should accept arguments (params)", function () {203 var params = {204 ti: Math.random().toString(),205 tr: Math.random(),206 ts: Math.random(),207 tt: Math.random(),208 ta: Math.random().toString(),209 p: Math.random().toString(),210 empty: null // Should be removed211 };212 var json = JSON.stringify(params);213 var visitor = ua()214 var result = visitor.transaction(params);215 visitor._context = result._context;216 result.should.eql(visitor, "should return a visitor that is identical except for the context");217 result.should.be.instanceof(ua.Visitor);218 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")219 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");220 _enqueue.args[0][0].should.equal("transaction");221 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")222 _enqueue.args[0][1].ti.should.equal(params.ti);223 _enqueue.args[0][1].tr.should.equal(params.tr);224 _enqueue.args[0][1].ts.should.equal(params.ts);225 _enqueue.args[0][1].tt.should.equal(params.tt);226 _enqueue.args[0][1].ta.should.equal(params.ta);227 _enqueue.args[0][1].p.should.equal(params.p);228 JSON.stringify(params).should.equal(json, "params should not have changed");229 });230 it("should accept arguments (params, fn)", function () {231 var params = {232 ti: Math.random().toString(),233 tr: Math.random(),234 ts: Math.random(),235 tt: Math.random(),236 ta: Math.random().toString(),237 p: Math.random().toString()238 };239 var fn = sinon.spy()240 var visitor = ua()241 var result = visitor.transaction(params, fn);242 visitor._context = result._context;243 result.should.eql(visitor, "should return a visitor that is identical except for the context");244 result.should.be.instanceof(ua.Visitor);245 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")246 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");247 _enqueue.args[0][0].should.equal("transaction");248 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")249 _enqueue.args[0][1].ti.should.equal(params.ti);250 _enqueue.args[0][1].tr.should.equal(params.tr);251 _enqueue.args[0][1].ts.should.equal(params.ts);252 _enqueue.args[0][1].tt.should.equal(params.tt);253 _enqueue.args[0][1].ta.should.equal(params.ta);254 _enqueue.args[0][1].p.should.equal(params.p);255 fn.calledOnce.should.equal(true, "callback should have been called once")256 });257 it("should fail without transaction ID", function () {258 var fn = sinon.spy()259 var visitor = ua()260 var result = visitor.transaction(null, fn);261 visitor._context = result._context;262 result.should.eql(visitor, "should return a visitor that is identical except for the context");263 result.should.be.instanceof(ua.Visitor);264 result._context.should.eql({}, "the transaction params should not be persisted")265 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");266 fn.calledOnce.should.equal(true, "callback should have been called once");267 fn.args[0][0].should.be.instanceof(Error);268 fn.thisValues[0].should.equal(visitor);269 });270 });...
event.js
Source:event.js
1var request = require("request");2var qs = require("querystring");3var uuid = require("uuid");4var should = require("should");5var sinon = require("sinon");6var url = require("url");7var ua = require("../lib/index.js");8var utils = require("../lib/utils.js")9var config = require("../lib/config.js")10describe("ua", function () {11 describe("#event", function () {12 var _enqueue;13 beforeEach(function () {14 _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function () {15 if (arguments.length === 3 && typeof arguments[2] === 'function') {16 arguments[2]();17 }18 return this;19 });20 });21 afterEach(function () {22 _enqueue.restore()23 });24 it("should be available via the #e shortcut", function () {25 var visitor = ua()26 visitor.e.should.equal(visitor.event)27 });28 it("should accept arguments (category, action)", function () {29 var category = Math.random().toString();30 var action = Math.random().toString();31 var visitor = ua()32 var result = visitor.event(category, action);33 visitor._context = result._context;34 result.should.eql(visitor, "should return a visitor that is identical except for the context");35 result.should.be.instanceof(ua.Visitor);36 result._context.should.eql(_enqueue.args[0][1], "the pageview params should be persisted as the context of the visitor clone")37 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");38 _enqueue.args[0][0].should.equal("event");39 _enqueue.args[0][1].should.have.keys("ec", "ea")40 _enqueue.args[0][1].ec.should.equal(category);41 _enqueue.args[0][1].ea.should.equal(action);42 });43 it("should accept arguments (category, action, fn)", function () {44 var category = Math.random().toString();45 var action = Math.random().toString();46 var fn = sinon.spy()47 ua().event(category, action, fn);48 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");49 _enqueue.args[0][0].should.equal("event");50 _enqueue.args[0][1].should.have.keys("ec", "ea")51 _enqueue.args[0][1].ec.should.equal(category);52 _enqueue.args[0][1].ea.should.equal(action);53 fn.calledOnce.should.equal(true, "callback should have been called once")54 });55 it("should accept arguments (category, action, label)", function () {56 var category = Math.random().toString();57 var action = Math.random().toString();58 var label = Math.random().toString();59 ua().event(category, action, label);60 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");61 _enqueue.args[0][0].should.equal("event");62 _enqueue.args[0][1].should.have.keys("ec", "ea", "el")63 _enqueue.args[0][1].ec.should.equal(category);64 _enqueue.args[0][1].ea.should.equal(action);65 _enqueue.args[0][1].el.should.equal(label);66 });67 it("should accept arguments (category, action, label, fn)", function () {68 var category = Math.random().toString();69 var action = Math.random().toString();70 var label = Math.random().toString();71 var fn = sinon.spy()72 ua().event(category, action, label, fn);73 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");74 _enqueue.args[0][0].should.equal("event");75 _enqueue.args[0][1].should.have.keys("ec", "ea", "el")76 _enqueue.args[0][1].ec.should.equal(category);77 _enqueue.args[0][1].ea.should.equal(action);78 _enqueue.args[0][1].el.should.equal(label);79 fn.calledOnce.should.equal(true, "callback should have been called once")80 });81 it("should accept arguments (category, action, label, value)", function () {82 var category = Math.random().toString();83 var action = Math.random().toString();84 var label = Math.random().toString();85 var value = Math.random();86 ua().event(category, action, label, value);87 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");88 _enqueue.args[0][0].should.equal("event");89 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev")90 _enqueue.args[0][1].ec.should.equal(category);91 _enqueue.args[0][1].ea.should.equal(action);92 _enqueue.args[0][1].el.should.equal(label);93 _enqueue.args[0][1].ev.should.equal(value);94 });95 it("should accept arguments (category, action, label, value, fn)", function () {96 var category = Math.random().toString();97 var action = Math.random().toString();98 var label = Math.random().toString();99 var value = Math.random();100 var fn = sinon.spy()101 ua().event(category, action, label, value, fn);102 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");103 _enqueue.args[0][0].should.equal("event");104 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev")105 _enqueue.args[0][1].ec.should.equal(category);106 _enqueue.args[0][1].ea.should.equal(action);107 _enqueue.args[0][1].el.should.equal(label);108 _enqueue.args[0][1].ev.should.equal(value);109 fn.calledOnce.should.equal(true, "callback should have been called once")110 });111 it("should accept arguments (category, action, label, value, params, fn)", function () {112 var category = Math.random().toString();113 var action = Math.random().toString();114 var label = Math.random().toString();115 var value = Math.random();116 var params = {"p": "/" + Math.random()}117 var fn = sinon.spy()118 ua().event(category, action, label, value, params, fn);119 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");120 _enqueue.args[0][0].should.equal("event");121 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")122 _enqueue.args[0][1].ec.should.equal(category);123 _enqueue.args[0][1].ea.should.equal(action);124 _enqueue.args[0][1].el.should.equal(label);125 _enqueue.args[0][1].ev.should.equal(value);126 _enqueue.args[0][1].p.should.equal(params.p);127 fn.calledOnce.should.equal(true, "callback should have been called once")128 });129 it("should accept arguments (params)", function () {130 var params = {131 ec: Math.random().toString(),132 ea: Math.random().toString(),133 el: Math.random().toString(),134 ev: Math.random(),135 "p": "/" + Math.random(),136 "empty": null137 }138 var json = JSON.stringify(params)139 ua().event(params);140 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");141 _enqueue.args[0][0].should.equal("event");142 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")143 _enqueue.args[0][1].ec.should.equal(params.ec);144 _enqueue.args[0][1].ea.should.equal(params.ea);145 _enqueue.args[0][1].el.should.equal(params.el);146 _enqueue.args[0][1].ev.should.equal(params.ev);147 _enqueue.args[0][1].p.should.equal(params.p);148 JSON.stringify(params).should.equal(json, "params should not have been modified")149 });150 it("should accept arguments (params, fn)", function () {151 var params = {152 ec: Math.random().toString(),153 ea: Math.random().toString(),154 el: Math.random().toString(),155 ev: Math.random(),156 "p": "/" + Math.random()157 }158 var fn = sinon.spy()159 ua().event(params, fn);160 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");161 _enqueue.args[0][0].should.equal("event");162 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")163 _enqueue.args[0][1].ec.should.equal(params.ec);164 _enqueue.args[0][1].ea.should.equal(params.ea);165 _enqueue.args[0][1].el.should.equal(params.el);166 _enqueue.args[0][1].ev.should.equal(params.ev);167 _enqueue.args[0][1].p.should.equal(params.p);168 fn.calledOnce.should.equal(true, "callback should have been called once")169 });170 it("should use the dp attribute as p for providing a event path", function () {171 var params = {172 ec: Math.random().toString(),173 ea: Math.random().toString(),174 "dp": "/" + Math.random(),175 }176 var json = JSON.stringify(params)177 ua().event(params);178 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");179 _enqueue.args[0][0].should.equal("event");180 _enqueue.args[0][1].should.have.keys("ec", "ea", "p")181 _enqueue.args[0][1].ec.should.equal(params.ec);182 _enqueue.args[0][1].ea.should.equal(params.ea);183 _enqueue.args[0][1].p.should.equal(params.dp);184 JSON.stringify(params).should.equal(json, "params should not have been modified")185 });186 it("should allow daisy-chaining and re-using parameters", function () {187 var params = {188 ec: Math.random().toString(),189 ea: Math.random().toString(),190 el: Math.random().toString(),191 ev: Math.random()192 }193 ua().event(params).event()194 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for each event");195 _enqueue.args[0][0].should.equal(_enqueue.args[1][0]);196 _enqueue.args[0][1].ec.should.equal(_enqueue.args[1][1].ec);197 _enqueue.args[0][1].ea.should.equal(_enqueue.args[1][1].ea);198 _enqueue.args[0][1].el.should.equal(_enqueue.args[1][1].el);199 _enqueue.args[0][1].ev.should.equal(_enqueue.args[1][1].ev);200 });201 it("should extend and overwrite params when daisy-chaining", function () {202 var params = {203 ec: Math.random().toString(),204 ea: Math.random().toString(),205 el: Math.random().toString(),206 ev: Math.random()207 }208 var category = Math.random().toString();209 ua().event(params).event(category)210 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for each event");211 _enqueue.args[0][0].should.equal(_enqueue.args[1][0]);212 _enqueue.args[0][1].ea.should.equal(_enqueue.args[1][1].ea);213 _enqueue.args[0][1].el.should.equal(_enqueue.args[1][1].el);214 _enqueue.args[0][1].ev.should.equal(_enqueue.args[1][1].ev);215 _enqueue.args[0][1].ec.should.equal(params.ec);216 _enqueue.args[1][1].ec.should.equal(category);217 });218 it("should re-use the path when daisy-chained to a pageview", function () {219 var path = "/" + Math.random()220 var params = {221 ec: Math.random().toString(),222 ea: Math.random().toString(),223 el: Math.random().toString(),224 ev: Math.random()225 }226 ua().pageview(path).event(params).event(params);227 _enqueue.calledThrice.should.equal(true, "#_enqueue should have been called twice, once for the pageview, once for the pageview");228 _enqueue.args[1][1].p.should.equal(path)229 _enqueue.args[2][1].p.should.equal(path)230 })231 it("should fail without event category", function () {232 var fn = sinon.spy()233 var action = Math.random().toString();234 var visitor = ua()235 var result = visitor.event(null, action, fn);236 visitor._context = result._context;237 result.should.eql(visitor, "should return a visitor that is identical except for the context");238 result.should.be.instanceof(ua.Visitor);239 result._context.should.eql({}, "the transaction params should not be persisted")240 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");241 fn.calledOnce.should.equal(true, "callback should have been called once");242 fn.args[0][0].should.be.instanceof(Error);243 fn.thisValues[0].should.equal(visitor);244 });245 it("should fail without event action", function () {246 var fn = sinon.spy()247 var category = Math.random().toString();248 var visitor = ua()249 var result = visitor.event(category, null, fn);250 visitor._context = result._context;251 result.should.eql(visitor, "should return a visitor that is identical except for the context");252 result.should.be.instanceof(ua.Visitor);253 result._context.should.eql({}, "the transaction params should not be persisted")254 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");255 fn.calledOnce.should.equal(true, "callback should have been called once");256 fn.args[0][0].should.be.instanceof(Error);257 fn.thisValues[0].should.equal(visitor);258 });259 });...
glados-ip4.js
Source:glados-ip4.js
...8 alert(msg);9 };10 this.afterStartup = function() {11 // Force scrolling with a few 'help' commands.12 _KernelInputQueue.enqueue('h');13 _KernelInputQueue.enqueue('e');14 _KernelInputQueue.enqueue('l');15 _KernelInputQueue.enqueue('p');16 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);17 _KernelInputQueue.enqueue('h');18 _KernelInputQueue.enqueue('e');19 _KernelInputQueue.enqueue('l');20 _KernelInputQueue.enqueue('p');21 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);22 // Test the 'ver' command.23 _KernelInputQueue.enqueue('v');24 _KernelInputQueue.enqueue('e');25 _KernelInputQueue.enqueue('r');26 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);27 // Test the 'date' command.28 _KernelInputQueue.enqueue('d');29 _KernelInputQueue.enqueue('a');30 _KernelInputQueue.enqueue('t');31 _KernelInputQueue.enqueue('e');32 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);33 // Test the 'whereami' command.34 _KernelInputQueue.enqueue('w');35 _KernelInputQueue.enqueue('h');36 _KernelInputQueue.enqueue('e');37 _KernelInputQueue.enqueue('r');38 _KernelInputQueue.enqueue('e');39 _KernelInputQueue.enqueue('a');40 _KernelInputQueue.enqueue('m');41 _KernelInputQueue.enqueue('i');42 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);43 44 // Test the 'status' command.45 _KernelInputQueue.enqueue('S');46 _KernelInputQueue.enqueue('t');47 _KernelInputQueue.enqueue('A');48 _KernelInputQueue.enqueue('t');49 _KernelInputQueue.enqueue('U');50 _KernelInputQueue.enqueue('s');51 _KernelInputQueue.enqueue(' ');52 _KernelInputQueue.enqueue('F');53 _KernelInputQueue.enqueue('i');54 _KernelInputQueue.enqueue('N');55 _KernelInputQueue.enqueue('a');56 _KernelInputQueue.enqueue('L');57 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);58 59 // Load some invalid user program code60 document.getElementById("taProgramInput").value="This is NOT hex.";61 _KernelInputQueue.enqueue('l');62 _KernelInputQueue.enqueue('o');63 _KernelInputQueue.enqueue('a');64 _KernelInputQueue.enqueue('d');65 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);66 // Format the hard drive so we can load FOUR or more programs.67 _KernelInputQueue.enqueue('f');68 _KernelInputQueue.enqueue('o');69 _KernelInputQueue.enqueue('r');70 _KernelInputQueue.enqueue('m');71 _KernelInputQueue.enqueue('a');72 _KernelInputQueue.enqueue('t');73 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);74 // getschedule75 _KernelInputQueue.enqueue('g');76 _KernelInputQueue.enqueue('e');77 _KernelInputQueue.enqueue('t');78 _KernelInputQueue.enqueue('s');79 _KernelInputQueue.enqueue('c');80 _KernelInputQueue.enqueue('h');81 _KernelInputQueue.enqueue('e');82 _KernelInputQueue.enqueue('d');83 _KernelInputQueue.enqueue('u');84 _KernelInputQueue.enqueue('l');85 _KernelInputQueue.enqueue('e');86 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);87 // Load FOUR different valid user programs code and run them. . . . and here.88 var code1 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 03 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 61 00 61 64 6F 6E 65 00";89 var code2 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 06 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 62 00 62 64 6F 6E 65 00";90 var code3 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 09 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 63 00 63 64 6F 6E 65 00";91 var code4 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 0C AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 64 00 64 64 6F 6E 65 00";92 setTimeout(function(){ document.getElementById("taProgramInput").value = code1;93 _KernelInputQueue.enqueue('l');94 _KernelInputQueue.enqueue('o');95 _KernelInputQueue.enqueue('a');96 _KernelInputQueue.enqueue('d');97 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 98 }, 1000);99 setTimeout(function(){ document.getElementById("taProgramInput").value = code2;100 _KernelInputQueue.enqueue('l');101 _KernelInputQueue.enqueue('o');102 _KernelInputQueue.enqueue('a');103 _KernelInputQueue.enqueue('d');104 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 105 }, 2000);106 setTimeout(function(){ document.getElementById("taProgramInput").value = code3;107 _KernelInputQueue.enqueue('l');108 _KernelInputQueue.enqueue('o');109 _KernelInputQueue.enqueue('a');110 _KernelInputQueue.enqueue('d');111 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 112 }, 3000);113 setTimeout(function(){ document.getElementById("taProgramInput").value = code4;114 _KernelInputQueue.enqueue('l');115 _KernelInputQueue.enqueue('o');116 _KernelInputQueue.enqueue('a');117 _KernelInputQueue.enqueue('d');118 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 119 }, 3000);120 setTimeout(function(){ _KernelInputQueue.enqueue('r');121 _KernelInputQueue.enqueue('u');122 _KernelInputQueue.enqueue('n');123 _KernelInputQueue.enqueue('a');124 _KernelInputQueue.enqueue('l'); 125 _KernelInputQueue.enqueue('l'); 126 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 127 }, 4000);128 // Remind myself to test the file system.129 _KernelInputQueue.enqueue('S');130 _KernelInputQueue.enqueue('t');131 _KernelInputQueue.enqueue('A');132 _KernelInputQueue.enqueue('t');133 _KernelInputQueue.enqueue('U');134 _KernelInputQueue.enqueue('s');135 _KernelInputQueue.enqueue(' ');136 _KernelInputQueue.enqueue('T');137 _KernelInputQueue.enqueue('e');138 _KernelInputQueue.enqueue('s');139 _KernelInputQueue.enqueue('t');140 _KernelInputQueue.enqueue(' ');141 _KernelInputQueue.enqueue('t');142 _KernelInputQueue.enqueue('h');143 _KernelInputQueue.enqueue('e');144 _KernelInputQueue.enqueue(' ');145 _KernelInputQueue.enqueue('f');146 _KernelInputQueue.enqueue('i');147 _KernelInputQueue.enqueue('l');148 _KernelInputQueue.enqueue('e');149 _KernelInputQueue.enqueue(' ');150 _KernelInputQueue.enqueue('s');151 _KernelInputQueue.enqueue('y');152 _KernelInputQueue.enqueue('s');153 _KernelInputQueue.enqueue('t');154 _KernelInputQueue.enqueue('e');155 _KernelInputQueue.enqueue('m');156 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);157 };158 ...
queue_spec.js
Source:queue_spec.js
...47 it('Should accept a single input parameter', () => {48 expect(queue.enqueue.length).to.equal(1);49 });50 it('Should create a new node with the value provided as input', () => {51 queue.enqueue('A');52 expect(queue.front.value).to.equal('A');53 });54 it('Should reassign both the front and back pointers when a new node is added to the back of an empty queue', () => {55 queue.enqueue('A');56 expect(queue.front.value).to.equal('A');57 expect(queue.back.value).to.equal('A');58 });59 it('Should reassign only the back pointer when new nodes are added to the back of the queue of size one or greater', () => {60 queue.enqueue('A');61 queue.enqueue('B');62 expect(queue.front.value).to.equal('A');63 expect(queue.back.value).to.equal('B');64 queue.enqueue('C');65 expect(queue.front.value).to.equal('A');66 expect(queue.back.value).to.equal('C');67 });68 it('Should point the next property of the front node to the node that follows it for queues of size one or greater', () => {69 queue.enqueue('A');70 queue.enqueue('B');71 expect(queue.front.next.value).to.eql('B');72 queue.enqueue('C');73 expect(queue.front.next.value).to.equal('B');74 });75 it('Should increment the queue\'s length by one each time a node is added to the queue', () => {76 expect(queue.length).to.equal(0);77 queue.enqueue('A');78 expect(queue.length).to.equal(1);79 queue.enqueue('B');80 expect(queue.length).to.equal(2);81 queue.enqueue('C');82 expect(queue.length).to.equal(3);83 });84 it('Should return the size of the queue after a new node is added to the queue', () => {85 expect(queue.enqueue('A')).to.equal(1);86 expect(queue.enqueue('B')).to.equal(2);87 });88 });89 describe('dequeue', () => {90 it('Should not accept any input parameters', () => {91 expect(queue.dequeue.length).to.equal(0);92 });93 it('Should not throw an error when calling dequeue on an empty queue', () => {94 expect(function () { queue.dequeue() }).to.not.throw();95 });96 it('Should return null if called on an empty queue', () => {97 expect(queue.dequeue()).to.be.equal(null);98 });99 it('Should reassign the front and back pointers to null if there is only one node in the queue', () => {100 queue.enqueue('A');101 expect(queue.front.value).to.equal('A');102 expect(queue.back.value).to.equal('A');103 queue.dequeue();104 expect(queue.front).to.equal(null);105 expect(queue.back).to.equal(null);106 });107 it('Should reassign the front pointer to the node just behind the front node for queues of size two or greater', () => {108 queue.enqueue('A');109 queue.enqueue('B');110 queue.enqueue('C');111 expect(queue.front.value).to.equal('A');112 queue.dequeue();113 expect(queue.front.value).to.equal('B');114 queue.dequeue();115 expect(queue.front.value).to.equal('C');116 });117 it('Should decrement the queue\'s length by one each time a node is removed from the queue', () => {118 queue.enqueue('A');119 queue.enqueue('B');120 queue.enqueue('C');121 expect(queue.length).to.equal(3);122 queue.dequeue();123 expect(queue.length).to.equal(2);124 queue.dequeue();125 expect(queue.length).to.equal(1);126 });127 it('Should return the value of the node removed from the queue', () => {128 queue.enqueue('A');129 queue.enqueue('B');130 expect(queue.dequeue()).to.equal('A');131 expect(queue.dequeue()).to.equal('B');132 });133 });134 describe('size', () => {135 it('Should return a size of 0 for a new queue', () => {136 expect(queue.size()).to.equal(0);137 });138 it('Should return a size of 2 after two nodes are added to the queue', () => {139 queue.enqueue('A');140 queue.enqueue('B');141 expect(queue.size()).to.equal(2);142 });143 it('Should return a size of 1 after two nodes are added and then one is removed', () => {144 queue.enqueue('A');145 queue.enqueue('B');146 queue.dequeue();147 expect(queue.size()).to.equal(1);148 });149 it('Should return a size of 0 after more nodes were removed than were added', () => {150 queue.enqueue('A');151 queue.dequeue();152 queue.dequeue();153 expect(queue.size()).to.equal(0);154 });155 });156 });157 describe('Queue Behavior', () => {158 it('Should remove the least recently added of three nodes (FIFO)', () => {159 queue.enqueue('A');160 queue.enqueue('B');161 queue.enqueue('C');162 expect(queue.dequeue()).to.equal('A');163 });164 it('Should remove the oldest node after newer nodes have already been added and others have been removed', () => {165 queue.enqueue('A');166 queue.enqueue('B');167 queue.enqueue('C');168 queue.enqueue('D');169 queue.dequeue()170 expect(queue.dequeue()).to.equal('B');171 });172 });...
glados-ip3.js
Source:glados-ip3.js
...8 alert(msg);9 };10 this.afterStartup = function() {11 // Force scrolling with a few 'help' commands.12 _KernelInputQueue.enqueue('h');13 _KernelInputQueue.enqueue('e');14 _KernelInputQueue.enqueue('l');15 _KernelInputQueue.enqueue('p');16 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);17 _KernelInputQueue.enqueue('h');18 _KernelInputQueue.enqueue('e');19 _KernelInputQueue.enqueue('l');20 _KernelInputQueue.enqueue('p');21 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);22 // Test the 'ver' command.23 _KernelInputQueue.enqueue('v');24 _KernelInputQueue.enqueue('e');25 _KernelInputQueue.enqueue('r');26 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);27 // Test the 'date' command.28 _KernelInputQueue.enqueue('d');29 _KernelInputQueue.enqueue('a');30 _KernelInputQueue.enqueue('t');31 _KernelInputQueue.enqueue('e');32 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);33 // Test the 'whereami' command.34 _KernelInputQueue.enqueue('w');35 _KernelInputQueue.enqueue('h');36 _KernelInputQueue.enqueue('e');37 _KernelInputQueue.enqueue('r');38 _KernelInputQueue.enqueue('e');39 _KernelInputQueue.enqueue('a');40 _KernelInputQueue.enqueue('m');41 _KernelInputQueue.enqueue('i');42 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);43 44 // Test the 'status' command.45 _KernelInputQueue.enqueue('S');46 _KernelInputQueue.enqueue('t');47 _KernelInputQueue.enqueue('A');48 _KernelInputQueue.enqueue('t');49 _KernelInputQueue.enqueue('U');50 _KernelInputQueue.enqueue('s');51 _KernelInputQueue.enqueue(' ');52 _KernelInputQueue.enqueue('C');53 _KernelInputQueue.enqueue('a');54 _KernelInputQueue.enqueue('k');55 _KernelInputQueue.enqueue('e');56 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);57 58 // Load some invalid user program code59 document.getElementById("taProgramInput").value="This is NOT hex.";60 _KernelInputQueue.enqueue('l');61 _KernelInputQueue.enqueue('o');62 _KernelInputQueue.enqueue('a');63 _KernelInputQueue.enqueue('d');64 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);65 // Load THREE (slightly different) valid user programs code and run them. The differences are . . . . . . here . . . . . . and here.66 var code1 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 03 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 61 00 61 64 6F 6E 65 00";67 var code2 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 06 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 62 00 62 64 6F 6E 65 00";68 var code3 = "A9 00 8D 7B 00 A9 00 8D 7B 00 A9 00 8D 7C 00 A9 00 8D 7C 00 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 39 A0 7D A2 02 FF AC 7B 00 A2 01 FF AD 7B 00 8D 7A 00 A9 01 6D 7A 00 8D 7B 00 A9 09 AE 7B 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 01 EC 7A 00 D0 05 A9 01 8D 7C 00 A9 00 AE 7C 00 8D 7A 00 A9 00 EC 7A 00 D0 02 A9 01 8D 7A 00 A2 00 EC 7A 00 D0 AC A0 7F A2 02 FF 00 00 00 00 63 00 63 64 6F 6E 65 00";69 setTimeout(function(){ document.getElementById("taProgramInput").value = code1;70 _KernelInputQueue.enqueue('l');71 _KernelInputQueue.enqueue('o');72 _KernelInputQueue.enqueue('a');73 _KernelInputQueue.enqueue('d');74 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 75 }, 1000);76 setTimeout(function(){ document.getElementById("taProgramInput").value = code2;77 _KernelInputQueue.enqueue('l');78 _KernelInputQueue.enqueue('o');79 _KernelInputQueue.enqueue('a');80 _KernelInputQueue.enqueue('d');81 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 82 }, 2000);83 setTimeout(function(){ document.getElementById("taProgramInput").value = code3;84 _KernelInputQueue.enqueue('l');85 _KernelInputQueue.enqueue('o');86 _KernelInputQueue.enqueue('a');87 _KernelInputQueue.enqueue('d');88 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 89 }, 3000);90 setTimeout(function(){ _KernelInputQueue.enqueue('r');91 _KernelInputQueue.enqueue('u');92 _KernelInputQueue.enqueue('n');93 _KernelInputQueue.enqueue('a');94 _KernelInputQueue.enqueue('l'); 95 _KernelInputQueue.enqueue('l'); 96 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 97 }, 4000);98 };99 ...
glados-ip1.js
Source:glados-ip1.js
...10 alert(msg);11 };12 this.afterStartup = function() {13 // Force scrolling with a few 'help' commands.14 _KernelInputQueue.enqueue('h');15 _KernelInputQueue.enqueue('e');16 _KernelInputQueue.enqueue('l');17 _KernelInputQueue.enqueue('p');18 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 19 _KernelInputQueue.enqueue('h');20 _KernelInputQueue.enqueue('e');21 _KernelInputQueue.enqueue('l');22 _KernelInputQueue.enqueue('p');23 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);24 // Test the 'ver' command.25 _KernelInputQueue.enqueue('v');26 _KernelInputQueue.enqueue('e');27 _KernelInputQueue.enqueue('r');28 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);29 // Test the 'date' command.30 _KernelInputQueue.enqueue('d');31 _KernelInputQueue.enqueue('a');32 _KernelInputQueue.enqueue('t');33 _KernelInputQueue.enqueue('e');34 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);35 // Test the 'whereami' command.36 _KernelInputQueue.enqueue('w');37 _KernelInputQueue.enqueue('h');38 _KernelInputQueue.enqueue('e');39 _KernelInputQueue.enqueue('r');40 _KernelInputQueue.enqueue('e');41 _KernelInputQueue.enqueue('a');42 _KernelInputQueue.enqueue('m');43 _KernelInputQueue.enqueue('i');44 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);45 46 // Test the 'status' command.47 _KernelInputQueue.enqueue('S');48 _KernelInputQueue.enqueue('t');49 _KernelInputQueue.enqueue('A');50 _KernelInputQueue.enqueue('t');51 _KernelInputQueue.enqueue('U');52 _KernelInputQueue.enqueue('s');53 _KernelInputQueue.enqueue(' ');54 _KernelInputQueue.enqueue('T');55 _KernelInputQueue.enqueue('h');56 _KernelInputQueue.enqueue('e');57 _KernelInputQueue.enqueue(' ');58 _KernelInputQueue.enqueue('C');59 _KernelInputQueue.enqueue('a');60 _KernelInputQueue.enqueue('k');61 _KernelInputQueue.enqueue('e');62 _KernelInputQueue.enqueue(' ');63 _KernelInputQueue.enqueue('i');64 _KernelInputQueue.enqueue('s');65 _KernelInputQueue.enqueue(' ');66 _KernelInputQueue.enqueue('a');67 _KernelInputQueue.enqueue(' ');68 _KernelInputQueue.enqueue('l');69 _KernelInputQueue.enqueue('i');70 _KernelInputQueue.enqueue('e');71 _KernelInputQueue.enqueue('!');72 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]); 73 // Try and load some invalid user program code.74 document.getElementById("taProgramInput").value = "This is NOT hex.";75 _KernelInputQueue.enqueue('l');76 _KernelInputQueue.enqueue('o');77 _KernelInputQueue.enqueue('a');78 _KernelInputQueue.enqueue('d');79 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);80 // Try and load NO user program code. That should still casue an error.81 document.getElementById("taProgramInput").value = "";82 _KernelInputQueue.enqueue('l');83 _KernelInputQueue.enqueue('o');84 _KernelInputQueue.enqueue('a');85 _KernelInputQueue.enqueue('d');86 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);87 88 // Try and load some valid user program code.89 var code = "A9 00 8D 00 00 A9 00 8D 4B 00 A9 00 8D 4B 00 A2 03 EC 4B 00 D0 07 A2 01 EC 00 00 D0 05 A2 00 EC 00 00 D0 26 A0 4C A2 02 FF AC 4B 00 A2 01 FF A9 01 6D 4B 00 8D 4B 00 A2 02 EC 4B 00 D0 05 A0 55 A2 02 FF A2 01 EC 00 00 D0 C5 00 00 63 6F 75 6E 74 69 6E 67 00 68 65 6C 6C 6F 20 77 6F 72 6C 64 00";90 document.getElementById("taProgramInput").value = code;91 _KernelInputQueue.enqueue('l');92 _KernelInputQueue.enqueue('o');93 _KernelInputQueue.enqueue('a');94 _KernelInputQueue.enqueue('d');95 TSOS.Kernel.prototype.krnInterruptHandler(KEYBOARD_IRQ, [13, false]);96 };...
heap.spec.js
Source:heap.spec.js
...3describe('Heap tests', () => {4 context('Max heap', () => {5 it('Should push items to max-heap in expected order', () => {6 const heap = new Heap(false);7 heap.enqueue(33);8 expect(heap.getHeap()).to.eql([33]);9 heap.enqueue(30);10 expect(heap.getHeap()).to.eql([33, 30]);11 heap.enqueue(30);12 expect(heap.getHeap()).to.eql([33, 30, 30]);13 heap.enqueue(11);14 expect(heap.getHeap()).to.eql([33, 30, 30, 11]);15 });16 it('Should rebalance max-heap correctly after pushing an item', () => {17 const heap = new Heap(false);18 heap.enqueue(33);19 heap.enqueue(30);20 heap.enqueue(11);21 expect(heap.getHeap()).to.eql([33, 30, 11]);22 heap.enqueue(31);23 expect(heap.getHeap()).to.eql([33, 31, 11, 30]);24 heap.enqueue(34);25 expect(heap.getHeap()).to.eql([34, 33, 11, 30, 31]);26 heap.enqueue(22);27 expect(heap.getHeap()).to.eql([34, 33, 22, 30, 31, 11]);28 });29 it('Should rebalance max-heap correctly after pulling root', () => {30 const heap = new Heap(false);31 heap.enqueue(33);32 heap.enqueue(30);33 heap.enqueue(11);34 heap.enqueue(31);35 heap.enqueue(34);36 heap.enqueue(22);37 expect(heap.getHeap()).to.eql([34, 33, 22, 30, 31, 11]);38 let root = heap.dequeue();39 expect(root).to.be.eql(34);40 expect(heap.getHeap()).to.eql([33, 31, 22, 30, 11]);41 root = heap.dequeue();42 expect(root).to.be.eql(33);43 expect(heap.getHeap()).to.eql([31, 30, 22, 11]);44 root = heap.dequeue();45 expect(root).to.be.eql(31);46 expect(heap.getHeap()).to.eql([30, 11, 22]);47 root = heap.dequeue();48 expect(root).to.be.eql(30);49 expect(heap.getHeap()).to.eql([22, 11]);50 root = heap.dequeue();51 expect(root).to.be.eql(22);52 expect(heap.getHeap()).to.eql([11]);53 root = heap.dequeue();54 expect(root).to.be.eql(11);55 expect(heap.getHeap()).to.eql([]);56 root = heap.dequeue();57 expect(root).to.be.eql(undefined);58 expect(heap.getHeap()).to.eql([]);59 });60 });61 context('Min heap', () => {62 it('Should push items to min-heap in expected order', () => {63 const heap = new Heap(true);64 heap.enqueue(33);65 expect(heap.getHeap()).to.eql([33]);66 heap.enqueue(30);67 expect(heap.getHeap()).to.eql([30, 33]);68 heap.enqueue(30);69 expect(heap.getHeap()).to.eql([30, 33, 30]);70 heap.enqueue(11);71 expect(heap.getHeap()).to.eql([11, 30, 30, 33]);72 });73 it('Should rebalance min-heap correctly after pushing an item', () => {74 const heap = new Heap(true);75 heap.enqueue(33);76 heap.enqueue(30);77 heap.enqueue(11);78 expect(heap.getHeap()).to.eql([11, 33, 30]);79 heap.enqueue(31);80 expect(heap.getHeap()).to.eql([11, 31, 30, 33]);81 heap.enqueue(34);82 expect(heap.getHeap()).to.eql([11, 31, 30, 33, 34]);83 heap.enqueue(22);84 expect(heap.getHeap()).to.eql([11, 31, 22, 33, 34, 30]);85 });86 it('Should rebalance min-heap correctly after pulling root', () => {87 const heap = new Heap(true);88 heap.enqueue(33);89 heap.enqueue(30);90 heap.enqueue(11);91 heap.enqueue(31);92 heap.enqueue(34);93 heap.enqueue(22);94 expect(heap.getHeap()).to.eql([11, 31, 22, 33, 34, 30]);95 let root = heap.dequeue();96 expect(root).to.be.eql(11);97 expect(heap.getHeap()).to.eql([22, 31, 30, 33, 34]);98 root = heap.dequeue();99 expect(root).to.be.eql(22);100 expect(heap.getHeap()).to.eql([30, 31, 34, 33]);101 root = heap.dequeue();102 expect(root).to.be.eql(30);103 expect(heap.getHeap()).to.eql([31, 33, 34]);104 root = heap.dequeue();105 expect(root).to.be.eql(31);106 expect(heap.getHeap()).to.eql([33, 34]);107 root = heap.dequeue();...
QueueSpec.js
Source:QueueSpec.js
...4 beforeEach(function() {5 queue = new Queue();6 });7 it('can enqueue and dequeue items', function() {8 queue.enqueue(1);9 queue.enqueue('a');10 queue.enqueue(null);11 expect(queue.dequeue()).toEqual(1);12 expect(queue.dequeue()).toEqual('a');13 expect(queue.dequeue()).toEqual(null);14 });15 it('returns undefined when dequeueing while empty', function() {16 expect(queue.dequeue()).toBeUndefined();17 });18 it('updates length when enqueuing and dequeuing', function() {19 expect(queue.length).toEqual(0);20 queue.enqueue('a');21 expect(queue.length).toEqual(1);22 queue.dequeue();23 expect(queue.length).toEqual(0);24 });25 it('compacts underlying array', function() {26 var i;27 for (i = 0; i < 1000; i++) {28 queue.enqueue(i);29 }30 for (i = 0; i < 1000; i++) {31 queue.dequeue();32 }33 expect(queue._array.length).toBeLessThan(1000);34 });35 it('can peek at the item at the head of the queue', function() {36 queue.enqueue(1);37 queue.enqueue(2);38 expect(queue.peek()).toEqual(1);39 expect(queue.length).toEqual(2);40 });41 it('returns undefined when peeking while empty', function() {42 expect(queue.peek()).toBeUndefined();43 });44 it('can check if it contains an item', function() {45 queue.enqueue(1);46 expect(queue.contains(1)).toEqual(true);47 expect(queue.contains(2)).toEqual(false);48 });49 it('can clear items', function() {50 queue.enqueue(1);51 queue.enqueue(2);52 queue.clear();53 expect(queue.length).toEqual(0);54 });55 it('can sort items', function() {56 queue.enqueue(99);57 queue.enqueue(6);58 queue.enqueue(1);59 queue.enqueue(53);60 queue.enqueue(4);61 queue.enqueue(0);62 queue.dequeue(); //remove 9963 queue.sort(function(a, b) {64 return a - b;65 });66 expect(queue.dequeue()).toEqual(0);67 expect(queue.dequeue()).toEqual(1);68 expect(queue.dequeue()).toEqual(4);69 expect(queue.dequeue()).toEqual(6);70 expect(queue.dequeue()).toEqual(53);71 });...
Using AI Code Generation
1const { enqueue } = require('@playwright/test');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await enqueue(async () => {5 });6});7const { enqueue } = require('@playwright/test');8module.exports = {9 use: {10 async action() {11 await enqueue(async () => {12 });13 },14 },15};16import { enqueue } from '@playwright/test';17module.exports = {18 use: {19 async action() {20 await enqueue(async () => {21 });22 },23 },24};25import { enqueue } from '@playwright/test';26test('test', async ({ page }) => {27 await enqueue(async () => {28 });29});30const { enqueue } = require('@playwright/test');31test('test', async ({ page }) => {32 await enqueue(async () => {33 });34});
Using AI Code Generation
1const { enqueue } = require('playwright-internal-queue');2enqueue(() => {3 console.log('This is a test');4});5const { dequeue } = require('playwright-internal-queue');6dequeue();7const { clear } = require('playwright-internal-queue');8clear();9const { peek } = require('playwright-internal-queue');10peek();11const { size } = require('playwright-internal-queue');12size();
Using AI Code Generation
1const { enqueue } = require('@playwright/test/lib/queue');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await enqueue('test', async () => {5 });6});7const { dequeue } = require('@playwright/test/lib/queue');8const { test } = require('@playwright/test');9test('test', async ({ page }) => {10 await dequeue('test', async () => {11 });12});13const { clear } = require('@playwright/test/lib/queue');14const { test } = require('@playwright/test');15test('test', async ({ page }) => {16 await clear('test', async () => {17 });18});19const { size } = require('@playwright/test/lib/queue');20const { test } = require('@playwright/test');21test('test', async ({ page }) => {22 await size('test', async () => {23 });24});25const { isEmpty } = require('@playwright/test/lib/queue');26const { test } = require('@playwright/test');27test('test', async ({ page }) => {28 await isEmpty('test', async () => {29 });30});31const { isRunning } = require('@playwright/test/lib/queue');32const { test } = require('@playwright/test');33test('test', async ({ page }) => {34 await isRunning('test', async () => {35 });36});37const { isPaused } = require('@playwright/test/lib/queue');38const { test } = require('@playwright/test');39test('test', async ({ page }) => {40 await isPaused('test', async () => {41 });42});
Using AI Code Generation
1const { InternalQueue } = require("@playwright/test/lib/utils/internalQueue");2const queue = new InternalQueue();3queue.enqueue(async () => {4 console.log("Hello World");5});6const { InternalQueue } = require("@playwright/test/lib/utils/internalQueue");7const queue = new InternalQueue();8queue.enqueue(async () => {9 console.log("Hello World");10});
Using AI Code Generation
1const { enqueue } = require('playwright-core/lib/server/queue');2const { chromium } = require('playwright-core');3const fs = require('fs');4const path = require('path');5(async () => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 await page.screenshot({ path: 'google.png' });10 await browser.close();11})();12const { enqueue } = require('playwright-core/lib/server/queue');13const { chromium } = require('playwright-core');14const fs = require('fs');15const path = require('path');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await page.screenshot({ path: 'google.png' });21 await browser.close();22})();23const { enqueue } = require('playwright-core/lib/server/queue');24const { chromium } = require('playwright-core');25const fs = require('fs');26const path = require('path');27(async () => {28 const browser = await chromium.launch();29 const context = await browser.newContext();30 const page = await context.newPage();31 await page.screenshot({ path: 'google.png' });32 await browser.close();33})();34const { enqueue } = require('playwright-core/lib/server/queue');35const { chromium } = require('playwright-core');36const fs = require('fs');37const path = require('path');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.screenshot({ path: 'google.png' });43 await browser.close();44})();45const { enqueue } = require('playwright-core/lib/server/queue');46const { chromium } = require('playwright-core');47const fs = require('fs');48const path = require('path');49(async () => {
Using AI Code Generation
1await this.page.waitForSelector('css=button');2await this.page.click('css=button');3await this.page.waitForSelector('css=div');4await this.page.click('css=div');5await this.page.waitForSelector('css=span');6await this.page.click('css=span'
Using AI Code Generation
1const { enqueue } = require('playwright-core/lib/utils/queue');2const fs = require('fs');3(async () => {4 const browser = await playwright.chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForNavigation();8 await page.screenshot({ path: 'screenshot.png' });9 await browser.close();10})();
Using AI Code Generation
1const { enqueue } = require('playwright-internal-queue');2enqueue(async () => {3});4const { enqueue } = require('playwright-internal-queue');5module.exports = {6 use: {7 playwrightInternalQueue: {8 enqueue: async () => {9 await enqueue(async () => {10 });11 },12 },13 },14};15### `enqueue(fn)`16[MIT](LICENSE)
Using AI Code Generation
1const { enqueue, internalQueue } = require('playwright/lib/internal/queue');2enqueue(() => console.log('Hello world!'));3console.log(internalQueue);4const { dequeue, internalQueue } = require('playwright/lib/internal/queue');5dequeue()();6console.log(internalQueue);7const { enqueue, internalQueue } = require('playwright/lib/internal/queue');8enqueue(() => console.log('Hello world!'));9console.log(internalQueue);10const { dequeue, internalQueue } = require('playwright/lib/internal/queue');11dequeue()();12console.log(internalQueue);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!