Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cypress 13 #524

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ node_modules
.github
.gitignore
CHANGELOG.md
cypress.json
cypress.config.js
generateDocs.sh
jsdoc_conf.json
LICENSE
LICENSE
cypress/
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-and-test:
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x, 20.x]

runs-on: ubuntu-latest

Expand Down
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
userAgent: "abcd",
});
3 changes: 0 additions & 3 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
// import * as Countly from "../../dist/countly_umd.js";
var hp = require("../support/helper.js");
var hp = require("../support/helper");

function initMain(clear) {
Countly.init({
Expand Down Expand Up @@ -62,22 +60,22 @@ describe("Test Countly.q related methods and processes", () => {
// Check that the .q is empty
expect(Countly.q.length).to.equal(0);

cy.fetch_local_request_queue().then((rq_2) => {
cy.fetch_local_request_queue().then((rq) => {
// Check that nothing sent to request queue
expect(rq_2.length).to.equal(0);
expect(rq.length).to.equal(0);
cy.fetch_local_event_queue().then((eq) => {
// Check that events are now in event queue
expect(eq.length).to.equal(4);

// Send events from event queue to request queue
Countly._internals.sendEventsForced();
cy.fetch_local_event_queue().then((eq_2) => {
cy.fetch_local_event_queue().then((eq) => {
// Check that event queue is empty
expect(eq_2.length).to.equal(0);
cy.fetch_local_request_queue().then((rq_3) => {
expect(eq.length).to.equal(0);
cy.fetch_local_request_queue().then((rq) => {
// Check that events are now in request queue
expect(rq_3.length).to.equal(1);
const eventsArray = JSON.parse(rq_3[0].events);
expect(rq.length).to.equal(1);
const eventsArray = JSON.parse(rq[0].events);
expect(eventsArray[0].key).to.equal("event_1");
expect(eventsArray[1].key).to.equal("event_2");
expect(eventsArray[2].key).to.equal("event_3");
Expand Down Expand Up @@ -125,16 +123,16 @@ describe("Test Countly.q related methods and processes", () => {
// Check that event queue has new device ID's orientation event
expect(eq.length).to.equal(1);
expect(eq[0].key).to.equal("[CLY]_orientation");
cy.fetch_local_request_queue().then((rq_2) => {
cy.fetch_local_request_queue().then((rq) => {
// Check that events are now in request queue (second request is begin session for new device ID)
expect(rq_2.length).to.equal(2);
const eventsArray = JSON.parse(rq_2[0].events);
expect(rq.length).to.equal(2);
const eventsArray = JSON.parse(rq[0].events);
expect(eventsArray[0].key).to.equal("event_1");
expect(eventsArray[1].key).to.equal("event_2");
expect(eventsArray[2].key).to.equal("event_3");
expect(eventsArray[3].key).to.equal("event_4");
// check begin session
expect(rq_2[1].begin_session).to.equal(1);
expect(rq[1].begin_session).to.equal(1);
});
});
});
Expand Down Expand Up @@ -175,16 +173,16 @@ describe("Test Countly.q related methods and processes", () => {
cy.fetch_local_event_queue().then((eq) => {
// Check that event queue is empty
expect(eq.length).to.equal(0);
cy.fetch_local_request_queue().then((rq_2) => {
cy.fetch_local_request_queue().then((rq) => {
// Check that events are now in request queue (second request is user details)
expect(rq_2.length).to.equal(2);
const eventsArray = JSON.parse(rq_2[0].events);
expect(rq.length).to.equal(2);
const eventsArray = JSON.parse(rq[0].events);
expect(eventsArray[0].key).to.equal("event_1");
expect(eventsArray[1].key).to.equal("event_2");
expect(eventsArray[2].key).to.equal("event_3");
expect(eventsArray[3].key).to.equal("event_4");
// check user details
const user_details = JSON.parse(rq_2[1].user_details);
const user_details = JSON.parse(rq[1].user_details);
expect(user_details.name).to.equal("test_user");
});
});
Expand Down Expand Up @@ -227,16 +225,16 @@ describe("Test Countly.q related methods and processes", () => {
cy.fetch_local_event_queue().then((eq) => {
// Check that event queue is empty
expect(eq.length).to.equal(0);
cy.fetch_local_request_queue().then((rq_2) => {
cy.fetch_local_request_queue().then((rq) => {
// Check that events are now in request queue (second request is user details)
expect(rq_2.length).to.equal(2);
const eventsArray = JSON.parse(rq_2[0].events);
expect(rq.length).to.equal(2);
const eventsArray = JSON.parse(rq[0].events);
expect(eventsArray[0].key).to.equal("event_1");
expect(eventsArray[1].key).to.equal("event_2");
expect(eventsArray[2].key).to.equal("event_3");
expect(eventsArray[3].key).to.equal("event_4");
// check user data
const user_details = JSON.parse(rq_2[1].user_details);
const user_details = JSON.parse(rq[1].user_details);
expect(user_details.custom.name).to.equal("test_user");
});
});
Expand Down Expand Up @@ -267,15 +265,15 @@ describe("Test Countly.q related methods and processes", () => {
expect(Countly.q.length).to.equal(4);
// Wait for heartBeat to process the .q
cy.wait(1500).then(() => {
// Check that the .q is empty
// Check that the .q is empty
expect(Countly.q.length).to.equal(0);
cy.fetch_local_event_queue().then((eq_2) => {
// Check that event queue is empty as all must be in request queue
expect(eq_2.length).to.equal(0);
cy.fetch_local_request_queue().then((rq_2) => {
// Check that events are now in request queue
expect(rq_2.length).to.equal(1);
const eventsArray = JSON.parse(rq_2[0].events);
cy.fetch_local_event_queue().then((eq) => {
// Check that event queue is empty as all must be in request queue
expect(eq.length).to.equal(0);
cy.fetch_local_request_queue().then((rq) => {
// Check that events are now in request queue
expect(rq.length).to.equal(1);
const eventsArray = JSON.parse(rq[0].events);
expect(eventsArray[0].key).to.equal("event_1");
expect(eventsArray[1].key).to.equal("event_2");
expect(eventsArray[2].key).to.equal("event_3");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
// import * as Countly from "../../dist/countly_umd.js";
var hp = require("../support/helper.js");

function initMain(name, version) {
Expand All @@ -22,7 +21,7 @@ const SDK_VERSION = "24.4.1";
describe("Bridged SDK Utilities Tests", () => {
it("Check if we can override sdk name and version successful", () => {
hp.haltAndClearStorage(() => {
initMain("javascript_gtm_web", "24.0.0");
initMain('javascript_gtm_web', '24.0.0');
hp.events();
cy.fetch_local_request_queue().then((eq) => {
expect(eq).to.have.length(1);
Expand All @@ -33,7 +32,7 @@ describe("Bridged SDK Utilities Tests", () => {
});
it("Check if SDK uses default values if SDK name and version was not overriden", () => {
hp.haltAndClearStorage(() => {
initMain(undefined, undefined);
initMain(undefined, undefined);
hp.events();
cy.fetch_local_request_queue().then((eq) => {
expect(eq).to.have.length(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
var hp = require("../support/helper");
// import * as Countly from "../../dist/countly_umd.js";
var hp = require("../support/helper.js");

function initMain(consent) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
require_consent: consent,
device_id: "György Ligeti",
test_mode: true,
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/crashes.js → cypress/e2e/crashes.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var hp = require("../support/helper");
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
test_mode: true
});
}
Expand All @@ -26,7 +26,7 @@ describe("Crashes tests ", () => {
catch (err) {
Countly.log_error(err);
}
cy.wait(3000).then(() => {
cy.wait(1000).then(() => {
cy.fetch_local_request_queue().then((rq) => {
cy.check_crash(rq[0], hp.appKey);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var hp = require("../support/helper");
function initMain(deviceId, offline, searchQuery, clear, rq, eq) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
device_id: deviceId,
test_mode: rq,
test_mode_eq: eq,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Countly = require("../../lib/countly");
var hp = require("../support/helper");
var hp = require("../support/helper.js");

// ========================================
// Device ID change tests
Expand All @@ -14,7 +14,7 @@ var hp = require("../support/helper");
function initMain(offline) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
test_mode: true,
debug: true,
offline_mode: offline
Expand Down Expand Up @@ -220,7 +220,7 @@ describe("Device ID change tests ", ()=>{
});

describe("Set ID change tests ", () => {
it("set_id should be non merge as there was dev provided id", () => {
it('set_id should be non merge as there was dev provided id', () => {
hp.haltAndClearStorage(() => {
Countly.init({
app_key: "YOUR_APP_KEY",
Expand All @@ -239,16 +239,16 @@ describe("Set ID change tests ", () => {
cy.fetch_local_request_queue().then((eq2) => {
expect(eq2.length).to.equal(3); // no merge request
expect(eq2[0].device_id).to.equal("old ID");
expect(eq2[0].events).to.contains("\"key\":\"1\"");
expect(eq2[0].events).to.contains('"key\":\"1\"');
expect(eq2[1].device_id).to.equal("new ID");
expect(eq2[1].begin_session).to.equal(1);
expect(eq2[2].device_id).to.equal("new ID");
expect(eq2[2].events).to.contains("\"key\":\"2\"");
expect(eq2[2].events).to.contains('"key\":\"2\"');
});
});
});
});
it("set_id should be merge as there was sdk generated id", () => {
it('set_id should be merge as there was sdk generated id', () => {
hp.haltAndClearStorage(() => {
initMain(false); // init normally
Countly.add_event(eventObj("1")); // record an event.
Expand All @@ -264,13 +264,14 @@ describe("Set ID change tests ", () => {
cy.log(eq2);
expect(eq2.length).to.equal(3); // merge request
expect(eq2[0].device_id).to.equal(generatedID);
expect(eq2[0].events).to.contains("\"key\":\"1\"");
expect(eq2[0].events).to.contains('"key\":\"1\"');
expect(eq2[1].device_id).to.equal("new ID");
expect(eq2[1].old_device_id).to.equal(generatedID);
expect(eq2[2].device_id).to.equal("new ID");
expect(eq2[2].events).to.contains("\"key\":\"2\"");
expect(eq2[2].events).to.contains('"key\":\"2\"');
});
});
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var hp = require("../support/helper");
function initMain(deviceId, offline, searchQuery, clear) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
device_id: deviceId,
test_mode: true,
debug: true,
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/events.js → cypress/e2e/events.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var hp = require("../support/helper");
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
session_update: 3,
test_mode: true,
test_mode_eq: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var hp = require("../support/helper");
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
test_mode: true
});
}
Expand All @@ -14,7 +14,7 @@ describe("Health Check tests ", () => {
it("Check if health check is sent at the beginning", () => {
hp.haltAndClearStorage(() => {
initMain();
cy.intercept("https://your.domain.countly/i?*").as("getXhr");
cy.intercept("https://your.domain.count.ly/i?*").as("getXhr");
cy.wait("@getXhr").then((xhr) => {
const url = new URL(xhr.request.url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ function click_check(segmentation, offX, offY) {
expect(segmentation.height).to.be.ok;
expect(segmentation.view).to.be.ok;
expect(segmentation.width).to.be.ok;
expect(segmentation.x).to.equal(clickX + offX);
expect(segmentation.y).to.equal(clickY + offY);
expect(segmentation.x).to.be.above(clickX + offX - 2);
expect(segmentation.x).to.be.below(clickX + offX + 2);
expect(segmentation.y).to.be.above(clickY + offY - 2);
expect(segmentation.y).to.be.below(clickY + offY + 2);
}

describe("Browser heatmap tests, scrolls", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var hp = require("../support/helper");
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
debug: true,
test_mode: true
});
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("Integration test", () => {
// TODO: make better
cy.fetch_local_request_queue().then((rq) => {
cy.log(rq);
hp.testNormalFlow(rq, "/__cypress/iframes/integration%2Fintegration.js", hp.appKey);
hp.testNormalFlow(rq, "/__cypress/iframes/cypress%5Ce2e%5Cintegration.cy.js", hp.appKey);
expect(consentStatus).to.equal(true); // no consent necessary
expect(remote).to.eql({}); // deepEqual
expect(rq[0].device_id).to.equal(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const limits = {
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
test_mode_eq: true,
test_mode: true,
debug: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function common_rating_check(param, num) {
function initMain() {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
test_mode_eq: true,
test_mode: true,
debug: true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var hp = require("../support/helper");
function initMain(shouldStopRequests) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.countly",
url: "https://your.domain.count.ly",
app_version: "1.0",
// would prevent requests from being sent to the server if true
test_mode: shouldStopRequests
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("Remaining requests tests ", () => {
});
// End the session
Countly.end_session(undefined, true);
hp.interceptAndCheckRequests(undefined, undefined, undefined, undefined, "end_session", (requestParams) => {
hp.interceptAndCheckRequests(undefined, 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);
Expand Down
Loading
Loading