it("check main flow", () => { const AppProxy = Proxyquire("../app", { express: Sinon.stub().returns(express), }); const application = new AppProxy.Application(); const stubInitSessionManagement = Sinon.stub(application, "initSessionManagement"); const stubInitPassport = Sinon.stub(application, "initPassport"); const stubInitSessionFiltering = Sinon.stub(application, "initSessionFiltering"); const stubInitRestEndpoints = Sinon.stub(application, "initRestEndpoints"); const stubInitStaticContent = Sinon.stub(application, "initStaticContent"); const stubStartServer = Sinon.stub(application, "startServer"); application.initExpress(); stubInitSessionManagement.restore(); stubInitPassport.restore(); stubInitSessionFiltering.restore(); stubInitRestEndpoints.restore(); stubInitStaticContent.restore(); stubStartServer.restore(); Sinon.assert.callOrder( stubInitSessionManagement.withArgs(express), stubInitPassport.withArgs(express), stubInitSessionFiltering.withArgs(express), stubInitRestEndpoints.withArgs(express), stubInitStaticContent.withArgs(express), stubStartServer.withArgs(express), ); });
test("mount should be called in ideal timing", (t) => { const testNode3 = rootNode.children[0]; testNode3.enabled = true; const order = [testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy]; sinon.assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy); order.forEach(v => { t.truthy(v.getCall(1).args[0] === "mount"); }); });
it('should preserve order and execute task in FIFO style', async () => { const sequence = new Sequence(Symbol.for('seq'), seqConfig); const spy1 = sinon.stub(); const spy2 = sinon.stub(); const spy3 = sinon.stub(); // This resolves in 5ms sequence.addAndPromise(getPromiseWorker('1', false, 5, spy1)); // This resolves in 3ms sequence.addAndPromise(getPromiseWorker('2', false, 3, spy2)); // This resolves in 1ms await sequence.addAndPromise(getPromiseWorker('3', false, 1, spy3)); sinon.assert.callOrder(spy1, spy2, spy3); });
it("check main flow", () => { const application = new App.Application(); const app = Express(); const stubAppUse = Sinon.stub(app, "use"); application.initRestEndpoints(app); stubAppUse.restore(); Sinon.assert.callOrder( stubAppUse.withArgs("/rest/v1/tasks", RouterTasks.router), stubAppUse.withArgs("/rest/v1/user", RouterUser.router), stubAppUse.withArgs("/rest/v1/report", RouterReport.router), ); });
it("check main flow", () => { const application = new App.Application(); const app = Express(); const staticHandler = { static: "payload", }; const stubExpressStatic = Sinon.stub(Express, "static").returns(staticHandler); const stubAppUse = Sinon.stub(app, "use"); application.initStaticContent(app); stubExpressStatic.restore(); stubAppUse.restore(); Sinon.assert.callOrder( stubExpressStatic.withArgs("../WebClient"), stubAppUse.withArgs(staticHandler), ); });
it("check main flow", () => { const cookieParser = {Cookie: "payload"}; const expressSession = {Session: "payload"}; const stubCookie = Sinon.stub().returns(cookieParser); const stubSession = Sinon.stub().returns(expressSession); const AppProxy = Proxyquire("../app", { "cookie-parser": stubCookie, "express-session": stubSession, }); const application = new AppProxy.Application(); const app = Express(); const config = { session: { secret: "Session Secret", }, }; const stubConfig = Sinon.stub(AppProxy, "config").get(() => config); const stubAppUse = Sinon.stub(app, "use"); application.initSessionManagement(app); stubConfig.restore(); stubAppUse.restore(); Sinon.assert.callOrder( stubCookie, stubAppUse, stubSession, stubAppUse, ); Sinon.assert.calledWithExactly(stubCookie); Sinon.assert.calledWithExactly(stubSession, { resave: true, saveUninitialized: false, secret: config.session.secret, }); Sinon.assert.callCount(stubAppUse, 2); stubAppUse.args[0][0].should.be.deep.equal(cookieParser); stubAppUse.args[1][0].should.be.deep.equals(expressSession); });
it("check main flow", () => { const application = new App.Application(); const app = Express(); const config = { server_port: 1234, }; const stubConfig = Sinon.stub(App, "config").get(() => config); const stubAppListen = Sinon.stub(app, "listen"); const stubConsoleLog = Sinon.stub(console, "log"); application.startServer(app); stubConfig.restore(); stubAppListen.restore(); stubConsoleLog.restore(); Sinon.assert.callOrder( stubAppListen.withArgs(config.server_port), stubConsoleLog.withArgs("Listening for port: " + config.server_port), ); });
it("check main flow", () => { const application = new App.Application(); const app = Express(); const initResult: any = { pay: "load", }; const stubPassportInitialize = Sinon.stub(Passport, "initialize").returns(initResult); const stubAppUse = Sinon.stub(app, "use"); const stubInitPassportSession = Sinon.stub(application, "initPassportSession"); const stubInitPassportLogin = Sinon.stub(application, "initPassportLogin"); const stubInitPassportCallback = Sinon.stub(application, "initPassportCallback"); const stubInitPassportLogout = Sinon.stub(application, "initPassportLogout"); application.initPassport(app); stubPassportInitialize.restore(); stubAppUse.restore(); stubInitPassportSession.restore(); stubInitPassportLogin.restore(); stubInitPassportCallback.restore(); stubInitPassportLogout.restore(); Sinon.assert.callOrder( stubPassportInitialize, stubAppUse, stubInitPassportSession, stubInitPassportLogin, stubInitPassportCallback, stubInitPassportLogout, ); Sinon.assert.calledWithExactly(stubPassportInitialize); Sinon.assert.calledWithExactly(stubAppUse, initResult); Sinon.assert.calledWithExactly(stubInitPassportSession, app); Sinon.assert.calledWithExactly(stubInitPassportLogin, app); Sinon.assert.calledWithExactly(stubInitPassportCallback, app); Sinon.assert.calledWithExactly(stubInitPassportLogout, app); });
aspect.on(obj, 'method', aspectStub1); aspect.on(obj, 'method', aspectStub2); aspect.on(obj, 'method', aspectStub3); assert.strictEqual(obj.method(0), 6); assert.deepEqual(aspectStub1.lastCall.args, methodSpy.lastCall.args); assert.deepEqual(aspectStub2.lastCall.args, methodSpy.lastCall.args); assert.deepEqual(aspectStub3.lastCall.args, methodSpy.lastCall.args); assert.isTrue(methodSpy.calledOnce); assert.isTrue(aspectStub1.calledOnce); assert.isTrue(aspectStub2.calledOnce); assert.isTrue(aspectStub3.calledOnce); sinon.assert.callOrder(methodSpy, aspectStub1, aspectStub2, aspectStub3); } }, 'handle.destroy()': { 'prevents aspect from being called'() { const aspectSpy = createBeforeSpy(); const handle = aspect.before(obj, 'method', aspectSpy); obj.method(0); assert.notEqual(obj.method, methodSpy); handle.destroy(); obj.method(1); assert.notEqual(obj.method, methodSpy); assert.isTrue(methodSpy.calledTwice);
previewManager.parseManifestFromActiveEditor(json).then(function (message) { sinon.assert.callOrder(deserializeJSONStub, getReadMeStub); expect(message).to.equal(success); })