From ca40a0403a18cc97dc7e7cbe948a4f8cc79a183c Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 30 Oct 2024 15:33:03 +0100 Subject: [PATCH] Use patched cavy --- .github/workflows/pr_android.yml | 2 +- e2e/index.js | 5 +- e2e/index.test.js | 4 + e2e/package-lock.json | 335 ++++++++++++++++++++++++++++ e2e/package.json | 12 +- e2e/patches/@types+cavy+3.2.9.patch | 27 +++ e2e/patches/cavy+4.0.2.patch | 27 +++ e2e/src/TestableApp.tsx | 18 +- e2e/src/utils/TestReporter.ts | 73 ++++++ 9 files changed, 478 insertions(+), 25 deletions(-) create mode 100644 e2e/index.test.js create mode 100644 e2e/patches/@types+cavy+3.2.9.patch create mode 100644 e2e/patches/cavy+4.0.2.patch create mode 100644 e2e/src/utils/TestReporter.ts diff --git a/.github/workflows/pr_android.yml b/.github/workflows/pr_android.yml index a45c49d2b..6733e02b1 100644 --- a/.github/workflows/pr_android.yml +++ b/.github/workflows/pr_android.yml @@ -81,7 +81,7 @@ jobs: emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true script: | - npm run test:e2e:android:release + npm run test:e2e:android echo "### E2E Test Summary" >> $GITHUB_STEP_SUMMARY e2e_summary_table=$(adb logcat -d -v raw | grep "E2E_RESULTS" | sed "s/'E2E_RESULTS', //") echo "$e2e_summary_table" | tee -a $GITHUB_STEP_SUMMARY diff --git a/e2e/index.js b/e2e/index.js index ccf48e6cb..7d53b6374 100644 --- a/e2e/index.js +++ b/e2e/index.js @@ -1,4 +1 @@ -import { AppRegistry } from 'react-native'; -import { TestableApp } from './src/TestableApp'; - -AppRegistry.registerComponent('ReactNativeTHEOplayerE2E', () => TestableApp); +console.error('This app can only be used with cavy-cli'); diff --git a/e2e/index.test.js b/e2e/index.test.js new file mode 100644 index 000000000..ccf48e6cb --- /dev/null +++ b/e2e/index.test.js @@ -0,0 +1,4 @@ +import { AppRegistry } from 'react-native'; +import { TestableApp } from './src/TestableApp'; + +AppRegistry.registerComponent('ReactNativeTHEOplayerE2E', () => TestableApp); diff --git a/e2e/package-lock.json b/e2e/package-lock.json index 0620f60b4..c9bda843b 100644 --- a/e2e/package-lock.json +++ b/e2e/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "react-native-theoplayer-e2e", "version": "0.0.1", + "hasInstallScript": true, "dependencies": { "@theoplayer/react-native-analytics-adobe": "^1.6.0", "@theoplayer/react-native-analytics-comscore": "^1.7.1", @@ -37,11 +38,14 @@ "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-react-native-web": "^0.17.7", "cavy": "^4.0.2", + "cavy-cli": "^3.0.0", "copy-webpack-plugin": "^12.0.2", "eslint": "^8.57.1", "html-webpack-plugin": "^5.6.3", + "patch-package": "^8.0.0", "react-native-svg-web": "^1.0.9", "typescript": "5.0.4", + "uninstall": "^0.0.0", "webpack": "^5.95.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.1.0" @@ -4382,6 +4386,12 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "dev": true }, + "node_modules/@yarnpkg/lockfile": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", + "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", + "dev": true + }, "node_modules/abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", @@ -4757,6 +4767,15 @@ "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, + "node_modules/at-least-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -5251,6 +5270,21 @@ "react-native": ">= 0.59.0 <= 0.66.0" } }, + "node_modules/cavy-cli": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cavy-cli/-/cavy-cli-3.0.0.tgz", + "integrity": "sha512-gQETN+fKNsXexvnSblxZY2rKT4kMfkWVg+FR7GehJ5mLkzDEH81snnROKI6PCgh17yg5+LmU2OKRyRgtWUB4+Q==", + "dev": true, + "dependencies": { + "chalk": "^2.3.0", + "commander": "^2.12.2", + "ws": "^7.3.0", + "xml2js": "^0.4.23" + }, + "bin": { + "cavy": "cavy.js" + } + }, "node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -7539,6 +7573,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/find-yarn-workspace-root": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz", + "integrity": "sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ==", + "dev": true, + "dependencies": { + "micromatch": "^4.0.2" + } + }, "node_modules/flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", @@ -9475,6 +9518,24 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, + "node_modules/json-stable-stringify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.1.1.tgz", + "integrity": "sha512-SU/971Kt5qVQfJpyDveVhQ/vya+5hvrjClFOcr8c0Fq5aODJjMwutrOfCU+eCnVD5gpx1Q3fEqkyom77zH1iIg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.5", + "isarray": "^2.0.5", + "jsonify": "^0.0.1", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", @@ -9500,6 +9561,15 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonify": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.1.tgz", + "integrity": "sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/jsx-ast-utils": { "version": "3.3.5", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz", @@ -9532,6 +9602,15 @@ "node": ">=0.10.0" } }, + "node_modules/klaw-sync": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz", + "integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.11" + } + }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -10971,6 +11050,15 @@ "node": ">=8" } }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -11075,6 +11163,207 @@ "tslib": "^2.0.3" } }, + "node_modules/patch-package": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/patch-package/-/patch-package-8.0.0.tgz", + "integrity": "sha512-da8BVIhzjtgScwDJ2TtKsfT5JFWz1hYoBl9rUQ1f38MC2HwnEIkK8VN3dKMKcP7P7bvvgzNDbfNHtx3MsQb5vA==", + "dev": true, + "dependencies": { + "@yarnpkg/lockfile": "^1.1.0", + "chalk": "^4.1.2", + "ci-info": "^3.7.0", + "cross-spawn": "^7.0.3", + "find-yarn-workspace-root": "^2.0.0", + "fs-extra": "^9.0.0", + "json-stable-stringify": "^1.0.2", + "klaw-sync": "^6.0.0", + "minimist": "^1.2.6", + "open": "^7.4.2", + "rimraf": "^2.6.3", + "semver": "^7.5.3", + "slash": "^2.0.0", + "tmp": "^0.0.33", + "yaml": "^2.2.2" + }, + "bin": { + "patch-package": "index.js" + }, + "engines": { + "node": ">=14", + "npm": ">5" + } + }, + "node_modules/patch-package/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/patch-package/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/patch-package/node_modules/ci-info": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", + "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "engines": { + "node": ">=8" + } + }, + "node_modules/patch-package/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/patch-package/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/patch-package/node_modules/fs-extra": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, + "dependencies": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/patch-package/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/patch-package/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/patch-package/node_modules/open": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/patch-package/node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, + "node_modules/patch-package/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/patch-package/node_modules/slash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/patch-package/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/patch-package/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -12627,6 +12916,12 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/sax": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==", + "dev": true + }, "node_modules/scheduler": { "version": "0.23.2", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", @@ -13509,6 +13804,18 @@ "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==", "dev": true }, + "node_modules/tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "dependencies": { + "os-tmpdir": "~1.0.2" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -13812,6 +14119,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/uninstall": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/uninstall/-/uninstall-0.0.0.tgz", + "integrity": "sha512-pjP/0+A4gsbDVa8XH/S2GZdT9NPJW8NFMy3GI7HnsWG+NAmFSSj3QidNosXBI9cPtxxNExEDdhKFO6sli8K3mA==", + "dev": true + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -14623,6 +14936,28 @@ } } }, + "node_modules/xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dev": true, + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/e2e/package.json b/e2e/package.json index b05dd4454..b9e091ec1 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -5,11 +5,10 @@ "private": true, "scripts": { "start": "npx react-native start", - "test:e2e:android": "npx react-native run-android --terminal bash", - "test:e2e:android:release": "npx react-native run-android --terminal bash --mode release", - "test:e2e:ios": "npx react-native run-ios --terminal bash", - "test:e2e:ios:release": "npx react-native run-ios --terminal bash --mode release", - "lint": "eslint \"**/*.{ts,tsx}\"" + "test:e2e:android": "npx cavy run-android --terminal bash --mode release", + "test:e2e:ios": "npx cavy run-ios --terminal bash", + "lint": "eslint \"**/*.{ts,tsx}\"", + "postinstall": "patch-package" }, "dependencies": { "@theoplayer/react-native-analytics-adobe": "^1.6.0", @@ -41,11 +40,14 @@ "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-react-native-web": "^0.17.7", "cavy": "^4.0.2", + "cavy-cli": "^3.0.0", "copy-webpack-plugin": "^12.0.2", "eslint": "^8.57.1", "html-webpack-plugin": "^5.6.3", + "patch-package": "^8.0.0", "react-native-svg-web": "^1.0.9", "typescript": "5.0.4", + "uninstall": "^0.0.0", "webpack": "^5.95.0", "webpack-cli": "^5.1.4", "webpack-dev-server": "^5.1.0" diff --git a/e2e/patches/@types+cavy+3.2.9.patch b/e2e/patches/@types+cavy+3.2.9.patch new file mode 100644 index 000000000..40c091ce9 --- /dev/null +++ b/e2e/patches/@types+cavy+3.2.9.patch @@ -0,0 +1,27 @@ +diff --git a/node_modules/@types/cavy/index.d.ts b/node_modules/@types/cavy/index.d.ts +index 9e0fb3f..1857974 100644 +--- a/node_modules/@types/cavy/index.d.ts ++++ b/node_modules/@types/cavy/index.d.ts +@@ -19,6 +19,13 @@ export function wrap

( + WrappedComponent: React.ComponentClass

| React.FunctionComponent

, + ): React.ComponentClass

; + ++export interface TestReporter { ++ type: string; ++ onStart: () => void; ++ send: (result: TestReport) => void; ++ onFinish: (report: TestReport) => void; ++} ++ + export interface TesterProps { + children: React.ReactElement; + store: TestHookStore; +@@ -26,7 +33,7 @@ export interface TesterProps { + waitTime?: number | undefined; + startDelay?: number | undefined; + clearAsyncStorage?: boolean | undefined; +- reporter?: ((report: TestReport) => void) | undefined; ++ reporter?: typeof TestReporter | undefined; + + // Deprecated + sendReport?: boolean | undefined; diff --git a/e2e/patches/cavy+4.0.2.patch b/e2e/patches/cavy+4.0.2.patch new file mode 100644 index 000000000..e5f4fbdd5 --- /dev/null +++ b/e2e/patches/cavy+4.0.2.patch @@ -0,0 +1,27 @@ +diff --git a/node_modules/cavy/src/Tester.js b/node_modules/cavy/src/Tester.js +index c61e31a..8d222ae 100644 +--- a/node_modules/cavy/src/Tester.js ++++ b/node_modules/cavy/src/Tester.js +@@ -57,20 +57,8 @@ export default class Tester extends Component { + key: Math.random() + }; + this.testHookStore = props.store; +- // Default to sending a test report to cavy-cli if no custom reporter is +- // supplied. +- if (props.reporter instanceof Function) { +- const message = 'Deprecation warning: support for custom function' + +- 'reporters will soon be deprecated. Cavy supports custom ' + +- 'class based reporters. For more info, see the ' + +- 'documentation here: ' + +- 'https://cavy.app/docs/guides/writing-custom-reporters'; +- console.warn(message); +- this.reporter = props.reporter; +- } else { +- reporterClass = props.reporter || Reporter; +- this.reporter = new reporterClass; +- } ++ reporterClass = props.reporter || Reporter; ++ this.reporter = new reporterClass; + } + + componentDidMount() { diff --git a/e2e/src/TestableApp.tsx b/e2e/src/TestableApp.tsx index 395ef79a3..c7bbd11d5 100644 --- a/e2e/src/TestableApp.tsx +++ b/e2e/src/TestableApp.tsx @@ -1,9 +1,10 @@ import React, { Component } from 'react'; -import { Tester, TestHookStore, TestReport } from 'cavy'; +import { Tester, TestHookStore } from 'cavy'; import { Platform, SafeAreaView, StyleSheet, View, ViewStyle } from 'react-native'; import { TestableTHEOplayerView } from './components/TestableTHEOplayerView'; import Specs from './tests'; import { getStatusBarHeight } from 'react-native-status-bar-height'; +import { Reporter } from './utils/TestReporter'; const testHookStore = new TestHookStore(); @@ -19,23 +20,10 @@ const PLAYER_CONTAINER_STYLE: ViewStyle = { backgroundColor: '#000000', }; -const generateTable = (report: TestReport): string => { - return ( - `|Description|'Test results ๐Ÿงช'|\n` + - `|---|---|\n` + - report.results.map((result) => `|${result.message} | ${result.passed ? 'โœ…' : 'โŒ'}|`).join('\n') - ); -}; - -const reporter = (report: TestReport) => { - // Write the test results to a github workflow summary. - console.log(`E2E_RESULTS`, generateTable(report)); -}; - export class TestableApp extends Component { render() { return ( - + diff --git a/e2e/src/utils/TestReporter.ts b/e2e/src/utils/TestReporter.ts new file mode 100644 index 000000000..3092f6399 --- /dev/null +++ b/e2e/src/utils/TestReporter.ts @@ -0,0 +1,73 @@ +import { TestReport, TestReporter } from 'cavy'; + +interface TestData { + event: string; + data: TestReport; +} + +export class Reporter implements TestReporter { + private ws: WebSocket | undefined = undefined; + + get type(): string { + return 'realtime'; + } + + // Internal: Creates a websocket connection to the cavy-cli server. + onStart() { + const url = 'ws://127.0.0.1:8082/'; + this.ws = new WebSocket(url); + } + + // Internal: Send a single test result to cavy-cli over the websocket connection. + send(result: TestReport) { + if (this.websocketReady()) { + const testData = { event: 'singleResult', data: result }; + this.sendData(testData); + } + } + + // Internal: Send report to cavy-cli over the websocket connection. + onFinish(report: TestReport) { + if (this.websocketReady()) { + const testData = { event: 'testingComplete', data: report }; + this.sendData(testData); + console.log(`E2E_RESULTS`, this.generateTable(report)); + } else { + // If cavy-cli is not running, let people know in a friendly way + const message = + "Skipping sending test report to cavy-cli - if you'd " + + 'like information on how to set up cavy-cli, check out the README ' + + 'https://github.com/pixielabs/cavy-cli'; + + console.log(message); + } + } + + // Private: Determines whether data can be sent over the websocket. + websocketReady() { + // WebSocket.readyState 1 means the web socket connection is OPEN. + return this.ws?.readyState == 1; + } + + // Private: Sends data over the websocket and console logs any errors. + sendData(testData: TestData) { + try { + this.ws?.send(JSON.stringify(testData)); + if (testData?.event == 'testingComplete') { + console.log('Cavy test report successfully sent to cavy-cli'); + } + } catch (e: any) { + console.group('Error sending test data'); + console.warn(e.message); + console.groupEnd(); + } + } + + generateTable(report: TestReport): string { + return ( + `|Description|'Test results ๐Ÿงช'|\n` + + `|---|---|\n` + + report.results.map((result) => `|${result.message} | ${result.passed ? 'โœ…' : 'โŒ'}|`).join('\n') + ); + } +}