Skip to content

Commit

Permalink
Merge pull request #46 from fingerprintjs/test/INTER-568-mock-app-tests
Browse files Browse the repository at this point in the history
test: add mock e2e tests
  • Loading branch information
necipallef committed Apr 30, 2024
2 parents 84e8621 + 2065cc4 commit 522aa3d
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ on:
- closed

jobs:
cleanup-mock:
runs-on: ubuntu-20.04
if: github.event.pull_request.merged == true
steps:
- name: Extract Branch Name
id: extract-branch
run: |
echo SUBDOMAIN=mock-$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/[^a-zA-Z0-9]+/-/g and s/-+$//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}&tags=owner:akamai-integration-ci'
method: 'GET'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Delete Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count > 0 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records/${{ fromJson(steps.cloudflare-dns-check.outputs.response).result[0].id }}'
method: 'DELETE'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'

cleanup:
if: github.event.pull_request.merged == true
runs-on: ubuntu-20.04
Expand Down
82 changes: 80 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,86 @@ on:
- 'assets/**'
- 'generators/**'
- 'build.ts'

- 'scripts/mockTests.ts'
- '.github/workflows/ci.yml'
jobs:
ci-mock:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: 'Install pnpm'
uses: pnpm/action-setup@129abb77bf5884e578fcaf1f37628e41622cc371
with:
version: 8
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
- name: Install dependencies
run: yarn install
- name: Extract Branch Name
id: extract-branch
run: |
echo SUBDOMAIN=mock-$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/[^a-zA-Z0-9]+/-/g and s/-+$//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}'
method: 'GET'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Create Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count < 1 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records'
method: 'POST'
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
data: '{"content": "${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}.edgesuite.net", "name": "${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}", "proxied": false, "type": "CNAME", "comment": "Akamai CI run for ${{steps.extract-branch.outputs.SUBDOMAIN}}", "ttl": 3600, "tags": ["owner:akamai-integration-ci"]}'
- name: Check Akamai Property can be created
id: check-akamai-property
continue-on-error: true
env:
SUBDOMAIN: '${{steps.extract-branch.outputs.SUBDOMAIN}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: yarn ts-node scripts/checkPropertyCanBeCreated.ts
- name: Create Akamai Property
if: steps.check-akamai-property.outcome == 'success'
id: create-akamai-property
env:
SUBDOMAIN: '${{steps.extract-branch.outputs.SUBDOMAIN}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: yarn ts-node scripts/createProperty.ts
- name: Build Patch Body
run: pnpm build --type patchBody --proxy-secret secret --integration-path ${{secrets.INTEGRATION_PATH}} --agent-path ${{secrets.AGENT_PATH}} --result-path ${{secrets.RESULT_PATH}} --cdn-url ${{secrets.MOCK_FPCDN}} --ingress-url ${{secrets.MOCK_FPCDN}}
- name: Deploy Akamai Rules
id: deploy-rules
env:
SUBDOMAIN: '${{steps.extract-branch.outputs.SUBDOMAIN}}'
AK_HOST: '${{secrets.AK_HOST}}'
AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}'
AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}'
AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}'
AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}'
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
TEST_EDGE_WORKER_ID: ${{secrets.TEST_EDGE_WORKER_ID}}
NOTIFY_EMAIL_ADDRESS: ${{secrets.NOTIFY_EMAIL_ADDRESS}}
run: yarn ts-node scripts/deployRules.ts

ci:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -70,7 +148,7 @@ jobs:
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
run: pnpm ts-node scripts/createProperty.ts
- name: Build Patch Body
run: pnpm build --type patchBody --proxy-secret ${{secrets.FPJS_PROXY_SECRET}} --integration-path worker --agent-path pxdownload --result-path pxresult
run: pnpm build --type patchBody --proxy-secret ${{secrets.FPJS_PROXY_SECRET}} --integration-path ${{secrets.INTEGRATION_PATH}} --agent-path ${{secrets.AGENT_PATH}} --result-path ${{secrets.RESULT_PATH}}
- name: Deploy Akamai Rules
id: deploy-rules
env:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/e2eForPR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
if [[ ${changed_file} =~ ^build\.ts$ ]]; then
cantPassWithoutTests=true
fi
if [[ ${changed_file} =~ .*ci\.yml$ ]]; then
cantPassWithoutTests=true
fi
done
echo $cantPassWithoutTests
echo CANT_PASS_WITHOUT_TESTS=${cantPassWithoutTests} >> $GITHUB_OUTPUT
Expand All @@ -44,7 +47,7 @@ jobs:
- name: Install dependencies
run: pnpm install
- name: Install Playwright
run: npx playwright install
run: pnpm exec playwright install
- name: Extract Branch Name
id: extract-branch
run: |
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/mockE2EForPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test e2e for PR

on:
pull_request:

jobs:
check-changed-files:
runs-on: ubuntu-20.04
name: Check changed files
outputs:
CANT_PASS_WITHOUT_TESTS: ${{ steps.decision.outputs.CANT_PASS_WITHOUT_TESTS }}
steps:
- id: files
uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42
- name: Make decision based on changed files
id: decision
run: |
cantPassWithoutTests=false
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ ${changed_file} =~ ^(assets|generators)\/.+$ ]]; then
cantPassWithoutTests=true
fi
if [[ ${changed_file} =~ ^build\.ts$ ]]; then
cantPassWithoutTests=true
fi
if [[ ${changed_file} =~ scripts\/mockTests\.ts$ ]]; then
cantPassWithoutTests=true
fi
if [[ ${changed_file} =~ .*ci\.yml$ ]]; then
cantPassWithoutTests=true
fi
done
echo $cantPassWithoutTests
echo CANT_PASS_WITHOUT_TESTS=${cantPassWithoutTests} >> $GITHUB_OUTPUT
build-and-test-e2e-mock:
runs-on: ubuntu-20.04
name: Test e2e for PR using mock app
needs: check-changed-files
if: needs['check-changed-files'].outputs.CANT_PASS_WITHOUT_TESTS == 'true'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: 'Install pnpm'
uses: pnpm/action-setup@129abb77bf5884e578fcaf1f37628e41622cc371
with:
version: 8
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
- name: Install dependencies
run: pnpm install
- name: Install Playwright
run: pnpm exec playwright install
- name: Extract Branch Name
id: extract-branch
run: |
echo SUBDOMAIN=mock-$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/[^a-zA-Z0-9]+/-/g and s/-+$//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
- name: Run test
run: pnpm test:mock-e2e
env:
TEST_DOMAIN: 'https://${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}'
INTEGRATION_PATH: ${{secrets.INTEGRATION_PATH}}
RESULT_PATH: ${{secrets.RESULT_PATH}}
AGENT_PATH: ${{secrets.AGENT_PATH}}
API_URL: ${{secrets.MOCK_FPCDN}}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint:fix": "pnpm lint --fix",
"build": "ts-node build.ts",
"test:e2e": "pnpm playwright test --workers=8 --max-failures=1",
"test:mock-e2e": "ts-node scripts/mockTests.ts",
"prepare": "husky install"
},
"devDependencies": {
Expand Down
42 changes: 42 additions & 0 deletions scripts/mockTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { execSync } from 'child_process'
import pkg from '../package.json'

function getEnv(name: string) {
const value = process.env[name]
if (!value) {
throw new Error(`${name} is not set`)
}
return value
}

async function main() {
const apiUrl = getEnv('API_URL')
const agentPath = `${getEnv('INTEGRATION_PATH')}/${getEnv('AGENT_PATH')}`
const resultPath = `${getEnv('INTEGRATION_PATH')}/${getEnv('RESULT_PATH')}`
const host = getEnv('TEST_DOMAIN')

const agentUrl = new URL(host)
agentUrl.pathname = agentPath

const resultUrl = new URL(host)
resultUrl.pathname = resultPath

console.info('Agent download path:', agentPath)
console.info('Get result path:', resultPath)

console.info(`Running mock e2e tests for`, host)

execSync(
`npm exec -y "git+https://github.com/fingerprintjs/dx-team-mock-for-proxy-integrations-e2e-tests.git" -- --api-url="https://${apiUrl}" --cdn-proxy-url="${agentUrl.toString()}" --ingress-proxy-url="${resultUrl.toString()}" --traffic-name=fingerprint-pro-akamai --integration-version=${
pkg.version
}`,
{
stdio: 'inherit',
}
)
}

main().catch((error) => {
console.error(error)
process.exit(1)
})

0 comments on commit 522aa3d

Please sign in to comment.