Skip to content

Commit

Permalink
chore: add mock license server
Browse files Browse the repository at this point in the history
  • Loading branch information
barinali committed Oct 6, 2023
1 parent 174240a commit f79fc29
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 9 deletions.
32 changes: 29 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ env:
POSTGRES_PASSWORD: automatisch_password
REDIS_HOST: localhost
APP_ENV: production
LICENSE_KEY: ${{ secrets.E2E_LICENSE_KEY }}
LICENSE_KEY: dummy_license_key

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on:
- ubuntu-latest
services:
postgres:
image: postgres:14.5-alpine
Expand Down Expand Up @@ -67,12 +68,37 @@ jobs:
- name: Seed user
working-directory: ./packages/backend
run: yarn db:seed:user &
- name: Install certutils
run: sudo apt install -y libnss3-tools
- name: Install mkcert
run: |
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" \
&& chmod +x mkcert-v*-linux-amd64 \
&& sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
- name: Install root certificate via mkcert
run: mkcert -install
- name: Create certificate
run: mkcert automatisch.io "*.automatisch.io" localhost 127.0.0.1 ::1
working-directory: ./packages/e2e-tests
- name: Set CAROOT environment variable
run: echo "NODE_EXTRA_CA_CERTS=$(mkcert -CAROOT)/rootCA.pem" >> "$GITHUB_ENV"
- name: Override license server with local server
run: sudo echo "127.0.0.1 license.automatisch.io" | sudo tee -a /etc/hosts
- name: Run local license server
working-directory: ./packages/e2e-tests
run: sudo yarn start-mock-license-server &
- name: Run Automatisch
run: yarn start &
working-directory: ./packages/backend
- name: Run Automatisch worker
run: node dist/src/worker.js &
working-directory: ./packages/backend
- name: Setup upterm session
if: false
uses: lhotari/action-upterm@v1
with:
limit-access-to-actor: true
limit-access-to-users: barinali
- name: Run Playwright tests
working-directory: ./packages/e2e-tests
env:
Expand All @@ -84,5 +110,5 @@ jobs:
if: always()
with:
name: playwright-report
path: ./packages/e2e-tests/test-results/**/*
path: packages/e2e-tests/test-results
retention-days: 30
28 changes: 28 additions & 0 deletions packages/e2e-tests/license-server-with-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('node:fs');
const https = require('node:https');
const path = require('node:path');
const { run, send } = require('micro');

const options = {
key: fs.readFileSync(path.join(__dirname, './automatisch.io+4-key.pem')),
cert: fs.readFileSync(path.join(__dirname, './automatisch.io+4.pem')),
};

const microHttps = (fn) =>
https.createServer(options, (req, res) => run(req, res, fn));

const server = microHttps(async (req, res) => {
const data = {
id: '7f22d7dd-1fda-4482-83fa-f35bf974a21f',
name: 'Mocked license',
expireAt: '2030-08-09T10:56:54.144Z',
};

send(res, 200, data);
});

server
.once('listening', () => {
console.log('The mock server is up.');
})
.listen(443);
4 changes: 3 additions & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"description": "The open source Zapier alternative. Build workflow automation without spending time and money.",
"scripts": {
"start-mock-license-server": "node ./license-server-with-mock.js",
"test": "playwright test",
"test:fast": "yarn test -j 90% --quiet --reporter null --ignore-snapshots -x"
},
Expand All @@ -26,6 +27,7 @@
"@playwright/test": "^1.36.2"
},
"dependencies": {
"dotenv": "^16.3.1"
"dotenv": "^16.3.1",
"micro": "^10.0.1"
}
}
9 changes: 5 additions & 4 deletions packages/e2e-tests/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ module.exports = defineConfig({
/* Timeout threshold for each test */
timeout: 30000,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'github' : 'html',
reporter: process.env.CI
? [['html', { open: 'never' }], ['github']]
: [['html', { open: 'never' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASE_URL
|| 'http://localhost:3001',
baseURL: process.env.BASE_URL || 'http://localhost:3001',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
trace: 'retain-on-failure',
testIdAttribute: 'data-test',
viewport: { width: 1280, height: 720 },
},
Expand Down
47 changes: 46 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5608,6 +5608,11 @@ are-we-there-yet@~1.1.2:
delegates "^1.0.0"
readable-stream "^2.0.6"

arg@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.0.tgz#583c518199419e0037abb74062c37f8519e575f0"
integrity sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz"
Expand Down Expand Up @@ -6341,6 +6346,11 @@ bytes@3.0.0:
resolved "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz"
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=

bytes@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==

bytes@3.1.1:
version "3.1.1"
resolved "https://registry.npmjs.org/bytes/-/bytes-3.1.1.tgz"
Expand Down Expand Up @@ -7025,7 +7035,7 @@ content-disposition@0.5.4:
dependencies:
safe-buffer "5.2.1"

content-type@^1.0.4, content-type@~1.0.4:
content-type@1.0.4, content-type@^1.0.4, content-type@~1.0.4:
version "1.0.4"
resolved "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz"
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==
Expand Down Expand Up @@ -10107,6 +10117,17 @@ http-deceiver@^1.2.7:
resolved "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz"
integrity sha1-+nFolEq5pRnTN8sL7HKE3D5yPYc=

http-errors@1.7.3:
version "1.7.3"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06"
integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==
dependencies:
depd "~1.1.2"
inherits "2.0.4"
setprototypeof "1.1.1"
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"

http-errors@1.8.0:
version "1.8.0"
resolved "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz"
Expand Down Expand Up @@ -12618,6 +12639,15 @@ methods@^1.1.2, methods@~1.1.2:
resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz"
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=

micro@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/micro/-/micro-10.0.1.tgz#2601e02b0dacd2eaee77e9de18f12b2e595c5951"
integrity sha512-9uwZSsUrqf6+4FLLpiPj5TRWQv5w5uJrJwsx1LR/TjqvQmKC1XnGQ9OHrFwR3cbZ46YqPqxO/XJCOpWnqMPw2Q==
dependencies:
arg "4.1.0"
content-type "1.0.4"
raw-body "2.4.1"

micromatch@^4.0.2, micromatch@^4.0.4:
version "4.0.4"
resolved "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz"
Expand Down Expand Up @@ -15134,6 +15164,16 @@ range-parser@^1.2.1, range-parser@~1.2.1:
resolved "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz"
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==

raw-body@2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.1.tgz#30ac82f98bb5ae8c152e67149dac8d55153b168c"
integrity sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==
dependencies:
bytes "3.1.0"
http-errors "1.7.3"
iconv-lite "0.4.24"
unpipe "1.0.0"

raw-body@2.4.3:
version "2.4.3"
resolved "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz"
Expand Down Expand Up @@ -16183,6 +16223,11 @@ setprototypeof@1.1.0:
resolved "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz"
integrity sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==

setprototypeof@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683"
integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==

setprototypeof@1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz"
Expand Down

0 comments on commit f79fc29

Please sign in to comment.