diff --git a/.gitignore b/.gitignore index f1acec4..31dc032 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ node_modules/ dist/ rollup.config.js Countly.d.ts +src/ +instrumented/ +coverage/ +.nyc_output/ ``` \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d348080..926ea10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 24.11.1 + +* Deprecated `initializeRatingWidgets` method, use `feedback.showRating` instead. +* Deprecated `enableRatingWidgets` method, use `feedback.showRating` instead. +* Added an interface `content` for Content feature methods: + * `enterContentZone`, to start Content checks (Experimental!) + * `exitContentZone`, to stop Content checks (Experimental!) + ## 24.11.0 * Mitigated an issue where SDK could try to send old stored offline mode data during init if `clear_stored_id` was true diff --git a/Countly.js b/Countly.js index b5fff36..954b8d6 100644 --- a/Countly.js +++ b/Countly.js @@ -174,7 +174,7 @@ if (isBrowser) { var key = parts.pop(); var appKey = parts.pop(); if (Countly.i && Countly.i[appKey]) { - Countly.i[appKey].onStorageChange(key, e.newValue); + Countly.i[appKey]._internals.onStorageChange(key, e.newValue); } }); } diff --git a/cypress.config.js b/cypress.config.js index 7fb2fb4..13700d1 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,9 +1,18 @@ import { defineConfig } from "cypress"; +import { createRequire } from "module"; + +const require = createRequire(import.meta.url); export default defineConfig({ e2e: { setupNodeEvents(on, config) { - // implement node event listeners here + const codeCoverageTask = require('@cypress/code-coverage/task'); + codeCoverageTask(on, config); + + // Include any other plugin code... + + // IMPORTANT: Return the config object with any changed environment variables + return config; }, }, userAgent: "abcd", diff --git a/cypress/e2e/remaining_requests.cy.js b/cypress/e2e/remaining_requests.cy.js index 9c4af2d..4d69b76 100644 --- a/cypress/e2e/remaining_requests.cy.js +++ b/cypress/e2e/remaining_requests.cy.js @@ -16,41 +16,22 @@ describe("Remaining requests tests ", () => { it("Checks the requests for rr", () => { hp.haltAndClearStorage(() => { initMain(false); + Countly.begin_session(); + Countly.end_session(undefined, true); - // We will expect 4 requests: health check, begin_session, end_session, orientation - hp.interceptAndCheckRequests("POST", undefined, undefined, "?hc=*", "hc", (requestParams) => { - const params = JSON.parse(requestParams.get("hc")); - assert.isTrue(typeof params.el === "number"); - assert.isTrue(typeof params.wl === "number"); - assert.isTrue(typeof params.sc === "number"); - assert.isTrue(typeof params.em === "string"); - expect(requestParams.get("rr")).to.equal(null); - }); cy.wait(1000).then(() => { - // Create a session - Countly.begin_session(); - hp.interceptAndCheckRequests("POST", undefined, undefined, "?begin_session=*", "begin_session", (requestParams) => { - expect(requestParams.get("begin_session")).to.equal("1"); - expect(requestParams.get("rr")).to.equal("3"); - expect(requestParams.get("av")).to.equal(av); - }); - // End the session - Countly.end_session(undefined, true); - hp.interceptAndCheckRequests("POST", undefined, undefined, "?end_session=*", "end", (requestParams) => { - expect(requestParams.get("end_session")).to.equal("1"); - expect(requestParams.get("rr")).to.equal("2"); - expect(requestParams.get("av")).to.equal(av); - }); - hp.interceptAndCheckRequests("POST", undefined, undefined, undefined, "orientation", (requestParams) => { - expect(JSON.parse(requestParams.get("events"))[0].key).to.equal("[CLY]_orientation"); - expect(requestParams.get("rr")).to.equal("1"); - expect(requestParams.get("av")).to.equal(av); - }); - cy.wait(100).then(() => { - cy.fetch_local_request_queue().then((rq) => { - expect(rq.length).to.equal(0); - }); - }); + var queues = Countly._internals.getLocalQueues(); + expect(queues.eventQ.length).to.equal(0); + expect(queues.requestQ.length).to.equal(3); + expect(queues.requestQ[0]["begin_session"]).to.equal(1); + expect(queues.requestQ[1]["end_session"]).to.equal(1); + expect(JSON.parse(queues.requestQ[2]["events"])[0].key).to.equal("[CLY]_orientation"); + + var requests = Countly._internals.testingGetRequests(); + expect(requests.length).to.equal(2); + expect(requests[0].params["rr"]).to.equal(undefined); + expect(requests[1].params["rr"]).to.equal(3); + expect(requests[1].params["av"]).to.equal(av); }); }); }); diff --git a/cypress/e2e/sessions.cy.js b/cypress/e2e/sessions.cy.js index 1b47548..a3f8f6d 100644 --- a/cypress/e2e/sessions.cy.js +++ b/cypress/e2e/sessions.cy.js @@ -97,9 +97,7 @@ describe("Browser session tests, auto", () => { describe("Browser session tests, manual 1", () => { it("Single sessions test with manual sessions", () => { cy.visit("./cypress/fixtures/session_test_manual_1.html?use_session_cookie=true"); - cy.contains("Start").click().wait(waitTime); - cy.contains("Event").click().wait(300); - cy.contains("End").click().wait(300); + cy.wait(waitTime + 1000); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { cy.log(rq); @@ -109,10 +107,10 @@ describe("Browser session tests, manual 1", () => { cy.check_session(rq[0], undefined, undefined, app_key); // third object of the queue should be about session extension, also input the expected duration cy.check_session(rq[2], 5, undefined, app_key); - // fourth object of the queue should be about event sent - cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); // fifth object of the queue should be about session extension, also input the expected duration - cy.check_session(rq[4], 1, undefined, app_key); + cy.check_session(rq[3], 1, undefined, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[4].events)[0], eventObj, undefined, false); }); }); }); @@ -160,12 +158,7 @@ describe("Browser session tests, auto, no cookie", () => { describe("Browser session tests, manual 1, no cookie", () => { it("Single bounce test with manual sessions with no cookies", () => { cy.visit("./cypress/fixtures/session_test_manual_1.html"); - cy.contains("Start").click(); - cy.wait(waitTime); - cy.contains("Event").click(); - cy.wait(300); - cy.contains("End").click(); - cy.wait(300); + cy.wait(waitTime + 1000); cy.visit("./cypress/fixtures/base.html"); cy.fetch_local_request_queue(app_key).then((rq) => { cy.log(rq); @@ -175,10 +168,10 @@ describe("Browser session tests, manual 1, no cookie", () => { cy.check_session(rq[0], undefined, undefined, app_key); // third object of the queue should be about session extension, also input the expected duration cy.check_session(rq[2], 5, undefined, app_key); - // fourth object of the queue should be about event sent - cy.check_event(JSON.parse(rq[3].events)[0], eventObj, undefined, false); // fifth object of the queue should be about session extension, also input the expected duration - cy.check_session(rq[4], 1, true, app_key); + cy.check_session(rq[3], 1, true, app_key); + // fourth object of the queue should be about event sent + cy.check_event(JSON.parse(rq[4].events)[0], eventObj, undefined, false); }); }); }); diff --git a/cypress/e2e/web_worker_queues.cy.js b/cypress/e2e/web_worker_queues.cy.js index d612d86..1b6279f 100644 --- a/cypress/e2e/web_worker_queues.cy.js +++ b/cypress/e2e/web_worker_queues.cy.js @@ -18,16 +18,17 @@ describe("Web Worker Local Queue Tests", () => { requestQueue = e.data.requestQ; // Array of requests eventQueue = e.data.eventQ; // Array of events myWorker.terminate(); // terminate worker - + }; + cy.wait(3000).then(() => { // verify event queue expect(eventQueue.length).to.equal(2); cy.check_event(eventQueue[0], { key: "key" }, undefined, false); cy.check_view_event(eventQueue[1], "home_page", undefined, false); - + // verify request queue expect(requestQueue.length).to.equal(2); cy.check_session(requestQueue[0], undefined, false, false, true); cy.check_session(requestQueue[1], 0, false, false, false); - }; + }); }); }); \ No newline at end of file diff --git a/cypress/fixtures/session_test_manual_1.html b/cypress/fixtures/session_test_manual_1.html index 2f7fa41..4d135b0 100644 --- a/cypress/fixtures/session_test_manual_1.html +++ b/cypress/fixtures/session_test_manual_1.html @@ -32,28 +32,20 @@ use_session_cookie: confObj.use_session_cookie || false, debug:true }) + Countly.begin_session(); + setTimeout(() => { + Countly.add_event({ + key: "buttonClick", + "segmentation": { + "id": "id" + } + }); + Countly.end_session(undefined, true); + }, 7000); + +
- - - - -