From 6c16252b3b378320d3b316011dd6742b7def8967 Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Sun, 11 Apr 2021 23:27:13 +0200 Subject: [PATCH] feat: Add E2E tests (#4) --- .github/workflows/qa.yml | 20 + .../Foo.txt.asc" | 17 + jest.config.js | 7 + package.json | 13 +- src/components/File.tsx | 2 + src/components/encrypt/Add.tsx | 4 +- src/components/encrypt/AddText.tsx | 3 + src/global.d.ts | 1 + src/screens/Intro.tsx | 5 + test-assets/key | 81 + test-assets/key.pub | 40 + tests/encryption.test.ts | 76 + tests/env-ts.ts | 50 + tests/env.js | 4 + webpack.config.ts | 25 +- yarn.lock | 2313 ++++++++++++++++- 16 files changed, 2618 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/qa.yml create mode 100644 ".tmp/(size = 21) => {\n let bytes = random(size)\n let id = ''\n / A compact alternative for `for (var i = 0; i < step; i++)`.\n while (size--) {\n / It is incorrect to use bytes exceeding the alphabet size.\n / The following mask reduces the random byte in the 0-255 value\n / range to the 0-63 value range. Therefore, adding hacks, such\n / as empty string fallback or magic numbers, is unneccessary because\n / the bitmask trims bytes down to the alphabet size.\n id += urlAlphabet[bytes[size] & 63]\n }\n return id\n}/Foo.txt.asc" create mode 100644 jest.config.js create mode 100644 src/global.d.ts create mode 100644 test-assets/key create mode 100644 test-assets/key.pub create mode 100644 tests/encryption.test.ts create mode 100644 tests/env-ts.ts create mode 100644 tests/env.js diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..331c64b --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,20 @@ +name: QA +on: + workflow_dispatch: + pull_request: +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. + with: + persist-credentials: false + + - name: Install 🔧 + run: | + yarn install + + - name: Test + run: | + yarn test diff --git "a/.tmp/(size = 21) => {\n let bytes = random(size)\n let id = ''\n / A compact alternative for `for (var i = 0; i < step; i++)`.\n while (size--) {\n / It is incorrect to use bytes exceeding the alphabet size.\n / The following mask reduces the random byte in the 0-255 value\n / range to the 0-63 value range. Therefore, adding hacks, such\n / as empty string fallback or magic numbers, is unneccessary because\n / the bitmask trims bytes down to the alphabet size.\n id += urlAlphabet[bytes[size] & 63]\n }\n return id\n}/Foo.txt.asc" "b/.tmp/(size = 21) => {\n let bytes = random(size)\n let id = ''\n / A compact alternative for `for (var i = 0; i < step; i++)`.\n while (size--) {\n / It is incorrect to use bytes exceeding the alphabet size.\n / The following mask reduces the random byte in the 0-255 value\n / range to the 0-63 value range. Therefore, adding hacks, such\n / as empty string fallback or magic numbers, is unneccessary because\n / the bitmask trims bytes down to the alphabet size.\n id += urlAlphabet[bytes[size] & 63]\n }\n return id\n}/Foo.txt.asc" new file mode 100644 index 0000000..1a166c1 --- /dev/null +++ "b/.tmp/(size = 21) => {\n let bytes = random(size)\n let id = ''\n / A compact alternative for `for (var i = 0; i < step; i++)`.\n while (size--) {\n / It is incorrect to use bytes exceeding the alphabet size.\n / The following mask reduces the random byte in the 0-255 value\n / range to the 0-63 value range. Therefore, adding hacks, such\n / as empty string fallback or magic numbers, is unneccessary because\n / the bitmask trims bytes down to the alphabet size.\n id += urlAlphabet[bytes[size] & 63]\n }\n return id\n}/Foo.txt.asc" @@ -0,0 +1,17 @@ +-----BEGIN PGP MESSAGE----- +Version: OpenPGP.js v4.10.7 +Comment: https://openpgpjs.org + +wcDMAwd2QSi0rCknAQv/TOSkfzJeI4QeOGhTnPPH1Dbc0lXfJJFO/7k+hEaU +nuj2ZETCJGBfTlktMdDq6pHcdXh1oLRW6mWxzBugspmJc1Hw7953+7oas0OF +jf4k8Jwg87AQcea38t8pJYvfhKQe7qXR3aqnXCzb0PYzTloBsM+/S3j+qYsT +TlDeN8LZfrGpBheGhiFI+XXIfbUSYNekIayj+u/HOiTNY4WCQKji44BC//oA +IGKKyMLTBNjr86qYZF6Cowph4XMs9HhDP7OowPShdvArk2gvdELGD23Ywp1w +2f6v6PUg8nSzleeETwnxLA3LKZZOz0/JYf30Q9gFr6uHf3tF510iO+KicjvS +Y+OQ7k800ZFsLKdEy0bWySNUYyb9lycaOofR8Xm5GP0bs8/T6IoS4x6ii342 +dP/GcfRqLPbhM5LK9hbLpHRgpWyZsi+Or8Oyky6sPEvhFuecCPBb25Qju8ul +VXfvIZqShw8pE1irbZlGQbFTq3yv8W2Ullu/QBwivDv1nL2bhocl0jsBFkSS +qNqruW5Pim0exfz3HcnPvWxRxaolalGSRebb/MPcOz+ypw8wl3yuU+tLtNFK +tfRdoo5leF334g== +=gbKf +-----END PGP MESSAGE----- diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..44c595c --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); + +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testEnvironment: path.join(__dirname, 'tests', 'env.js'), +}; diff --git a/package.json b/package.json index 8dfe07a..1f97e9f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "main": "index.js", "license": "MIT", "scripts": { - "build": "webpack" + "build": "webpack", + "test": "jest" }, "devDependencies": { "@ant-design/icons": "^4.2.2", @@ -13,7 +14,11 @@ "@babel/preset-react": "^7.10.4", "@babel/preset-typescript": "^7.10.4", "@hot-loader/react-dom": "^16.13.0", + "@types/express": "^4.17.11", + "@types/fs-extra": "^9.0.7", + "@types/get-port": "^4.2.0", "@types/html-webpack-plugin": "^3.2.3", + "@types/jest": "^26.0.20", "@types/jszip": "^3.4.1", "@types/openpgp": "^4.4.12", "@types/react": "^16.9.46", @@ -29,11 +34,17 @@ "babel-plugin-transform-inline-environment-variables": "^0.4.3", "css-loader": "^4.2.1", "dotenv": "^8.2.0", + "express": "^4.17.1", + "fs-extra": "^9.1.0", + "get-port": "^5.1.1", "html-webpack-plugin": "^4.3.0", + "jest": "^26.6.3", "offline-plugin": "^5.0.7", "parcel-bundler": "^1.12.4", + "puppeteer": "^7.1.0", "react-hot-loader": "^4.12.21", "style-loader": "^1.2.1", + "ts-jest": "^26.5.1", "ts-node": "^8.10.2", "typescript": "^3.9.7", "webpack": "^4.44.1", diff --git a/src/components/File.tsx b/src/components/File.tsx index 94a3f1c..ff44fd3 100644 --- a/src/components/File.tsx +++ b/src/components/File.tsx @@ -67,6 +67,7 @@ const FileView: React.FC = ({ actions.push( downloadLink(file.name, file.blob!)} @@ -77,6 +78,7 @@ const FileView: React.FC = ({ return ( { <> setType(evt.target.value)} defaultValue={DEFAULT_VALUE}> - Text - File + Text + File {type === 'text' && } diff --git a/src/components/encrypt/AddText.tsx b/src/components/encrypt/AddText.tsx index 424dba7..628af67 100644 --- a/src/components/encrypt/AddText.tsx +++ b/src/components/encrypt/AddText.tsx @@ -19,12 +19,14 @@ const AddText : React.FC = () => { setName(evt.target.value)} /> {