Skip to content

Commit

Permalink
Merge pull request #101 from ShellyDCMS/restore-cypress-as-dependency
Browse files Browse the repository at this point in the history
restore cypress as dependency
  • Loading branch information
ShellyDCMS committed Jun 8, 2024
2 parents 3064bd4 + 99dbeb1 commit 9563920
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 64 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shellygo/cypress-test-utils",
"description": "Cypress Test Automation Utilities",
"version": "2.1.10",
"version": "2.1.11",
"author": "Shelly Goldblit",
"private": false,
"license": "MIT",
Expand Down Expand Up @@ -30,16 +30,16 @@
"generate-md-docs": "typedoc --includeVersion --plugin typedoc-plugin-markdown --plugin typedoc-plugin-merge-modules --options typedoc.md.json",
"generate-docs": "typedoc --includeVersion --plugin typedoc-plugin-merge-modules --options typedoc.html.json"
},
"peerDependencies": {
"cypress": ">=12.17.3"
},
"peerDependencies": {},
"dependencies": {
"@cypress/mount-utils": "^4.0.0",
"@types/chai-subset": "^1.3.3",
"chai-subset": "^1.6.0",
"cypress": ">=12.17.3",
"cypress-pipe": "^2.0.0",
"cypress-real-events": "^1.7.6",
"cypress-wait-if-happens": "^1.3.3",
"cypress-wait-until": "^1.7.2",
"cypress-wait-until": "^3.0.1",
"ts-stubber": "^1.0.2"
},
"devDependencies": {
Expand All @@ -49,7 +49,6 @@
"@types/react": "^18.2.7",
"cpx": "^1.5.0",
"cross-var": "^1.1.0",
"cypress": "^12.17.3",
"gh-pages": "^5.0.0",
"lit": "^2.7.4",
"mochawesome": "^7.1.3",
Expand Down
16 changes: 8 additions & 8 deletions src/assertable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "cypress-pipe";

/** Assertable wraps Cypress.Chainable so that your tests are as decoupled as possible from Cypress.
* By using the Assertable class, you can use the same assertions in your tests, regardless of the testing framework you use.
* All you need to do if you wish to replace Cypress with another testing framework and keep your tests, is to replace the implementation of the Assertable class.
Expand Down Expand Up @@ -98,10 +100,9 @@ export class Assertable<T> {
* ```
*/
public shouldEndWith = (value: string) =>
this.chainable.then(text => {
const suffix = (text as string).slice(-value.length);
cy.wrap(suffix).should("equal", value);
});
this.chainable
.pipe(text => (text as string).slice(-value.length))
.should("equal", value);

/**
* Asserts that text starts with value
Expand All @@ -111,10 +112,9 @@ export class Assertable<T> {
* ```
*/
public shouldStartWith = (value: string) =>
this.chainable.then(text => {
const prefix = (text as string).slice(0, value.length);
cy.wrap(prefix).should("equal", value);
});
this.chainable
.pipe(text => (text as string).slice(0, value.length))
.should("equal", value);

/**
* Causes all `.equal`, `.include`, `.members`, `.keys`, and `.property` assertions that follow in the chain to use deep equality instead of strict (`===`) equality. See the `deep-eql` project page for info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
Expand Down
45 changes: 24 additions & 21 deletions src/cypress-helper.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,24 @@ describe("cypress helper tests", () => {
describe("interception", () => {
it("should intercept request and mock response", async () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
url: "**/shellygo.com/whatever**",
response: { shelly: "go" },
alias: "whatever"
});
fetch("https:/shellygo/whatever");
fetch("https://shellygo.com/whatever");
then(get.responseBody("whatever")).shouldInclude({
shelly: "go"
});
});

it("given fixture should intercept request and mock response", async () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
url: "**/shellygo.com/whatever**",
response: { fixture: "user.json" },
alias: "whatever"
});

fetch("https:/shellygo/whatever");
fetch("https://shellygo.com/whatever");
then(get.responseBody("whatever")).shouldInclude({
name: "Jane Doe",
id: "1234",
Expand All @@ -118,19 +118,21 @@ describe("cypress helper tests", () => {
describe("given multiple requests", () => {
beforeEach(() => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
url: "**/shellygo.com/whatever**",
response: { shelly: "go" },
alias: "shellygo"
});
fetch("https:/shellygo/whatever");
fetch("https:/shellygo/whatever");
fetch("https://shellygo.com/whatever?shelly=1").then(() =>
fetch("https://shellygo.com/whatever?shelly=2").then(() =>
fetch("https://shellygo.com/whatever?shelly=3")
)
);
});

it("should wait for multiple responses", () => {
fetch("https:/shellygo/whatever?shelly=go");
when.waitForResponses("shellygo", 2);
then(get.requestQueryParams("shellygo")).shouldInclude({
shelly: "go"
shelly: "3"
});
});
});
Expand Down Expand Up @@ -165,27 +167,27 @@ describe("cypress helper tests", () => {
describe("when waiting for last call", () => {
beforeEach(() => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
url: "**/shellygo.com/whatever**",
response: { shelly: "go" },
alias: "shellygo"
});
fetch("https:/shellygo/whatever");
fetch("https:/shellygo/whatever");
fetch("https://shellygo.com/whatever");
fetch("https://shellygo.com/whatever");
when.waitForLastCall("shellygo");
});

it("should wait for last call", () => {
fetch("https:/shellygo/whatever?shelly=go");
fetch("https://shellygo.com/whatever?shelly=go");
then(get.requestQueryParams("shellygo")).shouldInclude({
shelly: "go"
});
});
});

it("should intercept request and test query params", () => {
fetch("https:/shellygo/whatever?shelly=go");
fetch("https://shellygo.com/whatever?shelly=go");
given.interceptAndMockResponse({
url: "**/shellygo/whatever**",
url: "**/shellygo.com/whatever**",
response: { shelly: "go" },
alias: "shellygo"
});
Expand All @@ -194,13 +196,13 @@ describe("cypress helper tests", () => {

it("should intercept request and test body", () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever",
url: "**/shellygo.com/whatever",
method: "POST",
response: { shelly: "go" },
alias: "shellygo"
});

fetch("https:/shellygo/whatever", {
fetch("https://shellygo.com/whatever", {
method: "POST",
mode: "cors",
cache: "no-cache",
Expand All @@ -219,12 +221,12 @@ describe("cypress helper tests", () => {

it("should intercept request and test url", () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever/**",
url: "**/shellygo.com/whatever/**",
response: { shelly: "go" },
alias: "shellygo"
});

fetch("https:/shellygo/whatever/18?param=value");
fetch("https://shellygo.com/whatever/18?param=value");
then(get.requestUrl("shellygo")).shouldInclude("whatever/18");
});

Expand All @@ -241,19 +243,20 @@ describe("cypress helper tests", () => {

it("should intercept request and test header", () => {
given.interceptAndMockResponse({
url: "**/shellygo/whatever",
url: "**/shellygo.com/whatever*",
method: "POST",
response: { shelly: "go" },
alias: "shellygo"
});

fetch("https:/shellygo/whatever", {
fetch("https://shellygo.com/whatever", {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Methods": "*",
shelly: "go"
},
redirect: "follow",
Expand Down
63 changes: 34 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
resolved "https://registry.npmjs.org/@cypress/mount-utils/-/mount-utils-4.0.0.tgz"
integrity sha512-4w8WZpOALz5+vhJmPfh2HkT4NMsRP2DgVqSXxXu46GR5yUGfqJ0+WgUrmVuujtKKY6n1mDiO1L4AfZ+4bsEYGQ==

"@cypress/request@^2.88.11":
version "2.88.12"
resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.12.tgz#ba4911431738494a85e93fb04498cb38bc55d590"
integrity sha512-tOn+0mDZxASFM+cuAP9szGUGPI1HwWVSvdzm7V4cCsPdFTx6qMj29CwaQmRAMIEhORIUBFBsYROYJcveK4uOjA==
"@cypress/request@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@cypress/request/-/request-3.0.1.tgz#72d7d5425236a2413bd3d8bb66d02d9dc3168960"
integrity sha512-TWivJlJi8ZDx2wGOw1dbLuHJKUYX7bWySw377nlnGOW3hP9/MUKIsEdXT/YngWxVdgNCHRBmFlBipE+5/2ZZlQ==
dependencies:
aws-sign2 "~0.7.0"
aws4 "^1.8.0"
Expand All @@ -37,7 +37,7 @@
json-stringify-safe "~5.0.1"
mime-types "~2.1.19"
performance-now "^2.1.0"
qs "~6.10.3"
qs "6.10.4"
safe-buffer "^5.1.2"
tough-cookie "^4.1.3"
tunnel-agent "^0.6.0"
Expand Down Expand Up @@ -174,11 +174,6 @@
dependencies:
undici-types "~5.26.4"

"@types/node@^16.18.39":
version "16.18.97"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.97.tgz#d7926a8030f0d714d555b4550c0cc7731495cfe5"
integrity sha512-4muilE1Lbfn57unR+/nT9AFjWk0MtWi5muwCEJqnOvfRQDbSfLCUdN7vCIg8TYuaANfhLOV85ve+FNpiUsbSRg==

"@types/node@^20.2.5":
version "20.8.6"
resolved "https://registry.npmjs.org/@types/node/-/node-20.8.6.tgz"
Expand Down Expand Up @@ -1169,7 +1164,7 @@ buffer-crc32@~0.2.3:
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==

buffer@^5.6.0:
buffer@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
Expand Down Expand Up @@ -1449,35 +1444,39 @@ csstype@^3.0.2:
resolved "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

cypress-pipe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/cypress-pipe/-/cypress-pipe-2.0.0.tgz#577df7a70a8603d89a96dfe4092a605962181af8"
integrity sha512-KW9s+bz4tFLucH3rBGfjW+Q12n7S4QpUSSyxiGrgPOfoHlbYWzAGB3H26MO0VTojqf9NVvfd5Kt0MH5XMgbfyg==

cypress-real-events@^1.7.6:
version "1.10.3"
resolved "https://registry.npmjs.org/cypress-real-events/-/cypress-real-events-1.10.3.tgz"
integrity sha512-YN3fn+CJIAM638sE6uMvv2/n3PsWowdd0rOiN6ZoyezNAMyENfuQHvccLKZpN+apGfQZYetCml6QXLYgDid2fg==

cypress-wait-if-happens@^1.3.3:
version "1.3.3"
resolved "https://registry.npmjs.org/cypress-wait-if-happens/-/cypress-wait-if-happens-1.3.3.tgz"
resolved "https://registry.yarnpkg.com/cypress-wait-if-happens/-/cypress-wait-if-happens-1.3.3.tgz#609803d8bc264f1e29e20144f37f13e33b523847"
integrity sha512-1+fxadD2UFlJWZMzs2/1OA9ZUqMQ+I1Z86Gc2ifZrDZ6GmYihzTbixNAzt++t46to6qHsiXeYQ48gBg1UjYhyQ==

cypress-wait-until@^1.7.2:
version "1.7.2"
resolved "https://registry.npmjs.org/cypress-wait-until/-/cypress-wait-until-1.7.2.tgz"
integrity sha512-uZ+M8/MqRcpf+FII/UZrU7g1qYZ4aVlHcgyVopnladyoBrpoaMJ4PKZDrdOJ05H5RHbr7s9Tid635X3E+ZLU/Q==
cypress-wait-until@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/cypress-wait-until/-/cypress-wait-until-3.0.1.tgz#6a697a600f4fb8cd2897489a15fda77c9857abec"
integrity sha512-kpoa8yL6Bi/JNsThGBbrrm7g4SNzYyBUv9M5pF6/NTVm/ClY0HnJzeuWnHiAUZKIZ5l86Oedb12wQyjx7/CWPg==

cypress@^12.17.3:
version "12.17.3"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.17.3.tgz#1e2b19037236fc60e4a4b3a14f0846be17a1fc0e"
integrity sha512-/R4+xdIDjUSLYkiQfwJd630S81KIgicmQOLXotFxVXkl+eTeVO+3bHXxdi5KBh/OgC33HWN33kHX+0tQR/ZWpg==
cypress@>=12.17.3:
version "13.11.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.11.0.tgz#17097366390424cba5db6bf0ee5e97503f036e07"
integrity sha512-NXXogbAxVlVje4XHX+Cx5eMFZv4Dho/2rIcdBHg9CNPFUGZdM4cRdgIgM7USmNYsC12XY0bZENEQ+KBk72fl+A==
dependencies:
"@cypress/request" "^2.88.11"
"@cypress/request" "^3.0.0"
"@cypress/xvfb" "^1.2.4"
"@types/node" "^16.18.39"
"@types/sinonjs__fake-timers" "8.1.1"
"@types/sizzle" "^2.3.2"
arch "^2.2.0"
blob-util "^2.0.2"
bluebird "^3.7.2"
buffer "^5.6.0"
buffer "^5.7.1"
cachedir "^2.3.0"
chalk "^4.1.0"
check-more-types "^2.24.0"
Expand All @@ -1495,7 +1494,7 @@ cypress@^12.17.3:
figures "^3.2.0"
fs-extra "^9.1.0"
getos "^3.2.1"
is-ci "^3.0.0"
is-ci "^3.0.1"
is-installed-globally "~0.4.0"
lazy-ass "^1.6.0"
listr2 "^3.8.3"
Expand All @@ -1504,6 +1503,7 @@ cypress@^12.17.3:
minimist "^1.2.8"
ospath "^1.2.2"
pretty-bytes "^5.6.0"
process "^0.11.10"
proxy-from-env "1.0.0"
request-progress "^3.0.0"
semver "^7.5.3"
Expand Down Expand Up @@ -2268,7 +2268,7 @@ is-buffer@^1.1.5:
resolved "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-ci@^3.0.0:
is-ci@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-3.0.1.tgz#db6ecbed1bd659c43dac0f45661e7674103d1867"
integrity sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==
Expand Down Expand Up @@ -3083,6 +3083,11 @@ process-nextick-args@~2.0.0:
resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==

process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==

prop-types@^15.7.2:
version "15.8.1"
resolved "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz"
Expand Down Expand Up @@ -3120,10 +3125,10 @@ punycode@^2.1.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==

qs@~6.10.3:
version "6.10.5"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.5.tgz#974715920a80ff6a262264acd2c7e6c2a53282b4"
integrity sha512-O5RlPh0VFtR78y79rgcgKK4wbAI0C5zGVLztOIdpWX6ep368q5Hv6XRxDvXuZ9q3C6v+e3n8UfZZJw7IIG27eQ==
qs@6.10.4:
version "6.10.4"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.4.tgz#6a3003755add91c0ec9eacdc5f878b034e73f9e7"
integrity sha512-OQiU+C+Ds5qiH91qh/mg0w+8nwQuLjM4F4M/PbmhDOoYehPh+Fb0bDjtR1sOvy7YKxvj28Y/M0PhP5uVX0kB+g==
dependencies:
side-channel "^1.0.4"

Expand Down

0 comments on commit 9563920

Please sign in to comment.