Skip to content

Commit

Permalink
Merge pull request #29 from filipedeschamps/actions
Browse files Browse the repository at this point in the history
tests: adiciona suite de testes com Jest e Github Actions
  • Loading branch information
filipedeschamps committed Mar 4, 2020
2 parents 1dbbd58 + 72d6710 commit 050bcd6
Show file tree
Hide file tree
Showing 7 changed files with 4,345 additions and 174 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/e2e-tests.yml
@@ -0,0 +1,77 @@
name: Testes E2E

on: [deployment_status]

jobs:
mark-commit-status-pending:
name: Marcar "status" do commit como "pending"
if: github.event.deployment_status.state == 'pending'
runs-on: ubuntu-latest

steps:
- name: Fazer request contra API do Github com status "pending"
run: |
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "pending",
"context": "e2e-tests",
"description": "Aguardando a Preview URL da Zeit"
}'
e2e-tests:
name: Rodar testes E2E contra a Preview URL da Zeit
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest

steps:
- name: Atualizar o status "pending" com o "Workflow URL"
run: |
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "pending",
"context": "e2e-tests",
"description": "Realizando testes E2E contra a Preview URL",
"target_url": "'${GITHUB_WORKFLOW_URL}'"
}'
- name: Puxar o código do commit
uses: actions/checkout@v2

- name: Instalar o Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'

- name: Instalar as dependências do npm
run: npm install

- name: Rodar testes utilizando a Preview URL da Zeit
run: npm test
env:
NODE_ENV: 'ci'
PREVIEW_URL: ${{ github.event.deployment_status.target_url }}

- name: Fazer request contra API do Github status final
if: always()
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: |
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
JOB_STATUS=$(echo ${JOB_CONTEXT} | jq --raw-output '.status | ascii_downcase')
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "'${JOB_STATUS}'",
"context": "e2e-tests",
"description": "Finalizados os testes E2E contra a Preview URL.",
"target_url": "'${GITHUB_WORKFLOW_URL}'"
}'
3 changes: 3 additions & 0 deletions jest.config.js
@@ -0,0 +1,3 @@
module.exports = {
testTimeout: 30000
}

1 comment on commit 050bcd6

@vercel
Copy link

@vercel vercel bot commented on 050bcd6 Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.