kopia lustrzana https://github.com/badgen/badgen.net
test: add e2e tests (#645)
rodzic
0ca768cf1f
commit
b44717c473
|
@ -0,0 +1,16 @@
|
||||||
|
name: E2E Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
deployment_status:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-e2es:
|
||||||
|
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Run e2e tests
|
||||||
|
run: node test/e2e.test.mjs
|
||||||
|
env:
|
||||||
|
BASE_URL: ${{ github.event.deployment_status.target_url }}
|
||||||
|
MEMO_BADGE_TOKEN: ${{ secrets.MEMO_BADGE_TOKEN }}
|
|
@ -1,10 +1,9 @@
|
||||||
name: lint and build
|
name: Lint and Build
|
||||||
|
|
||||||
on: pull_request
|
on: pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import test from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
|
||||||
|
import { execSync } from 'node:child_process'
|
||||||
|
|
||||||
|
const BASE_URL = process.env.BASE_URL || 'https://badgen.net'
|
||||||
|
|
||||||
|
|
||||||
|
test('/static: simple static badge', async (t) => {
|
||||||
|
const badgeURL = `${BASE_URL}/static/v1.2.3/blue`
|
||||||
|
const response = await fetch(badgeURL)
|
||||||
|
|
||||||
|
assert.strictEqual(response.status, 200)
|
||||||
|
assert.strictEqual(response.headers.get('content-type'), 'image/svg+xml;charset=utf-8')
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('/memo: update "depoyed" badge', async (t) => {
|
||||||
|
if (!process.env.MEMO_BADGE_TOKEN) {
|
||||||
|
throw new Error('MEMO_BADGE_TOKEN is required to run this test')
|
||||||
|
}
|
||||||
|
const status = getGitLastCommitDate()
|
||||||
|
const label = 'Deployed'
|
||||||
|
const color = getGitCurrentBranch() === 'main' ? 'green' : 'cyan'
|
||||||
|
|
||||||
|
const badgeURL = `${BASE_URL}/memo/deployed/${label}/${status}/${color}`
|
||||||
|
const fetchOptions = {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
authorization: `Bearer ${process.env.MEMO_BADGE_TOKEN}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(badgeURL, fetchOptions)
|
||||||
|
assert.strictEqual(response.status, 200)
|
||||||
|
|
||||||
|
const result = await response.json()
|
||||||
|
assert.deepEqual(result, { status, label, color })
|
||||||
|
})
|
||||||
|
|
||||||
|
function getGitLastCommitDate () {
|
||||||
|
const lastCommitDateString = execSync('git log -1 --format=%cI').toString().trim()
|
||||||
|
return extractBareDate(lastCommitDateString)
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractBareDate(dateString) {
|
||||||
|
return new Date(dateString).toISOString().substring(0, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGitCurrentBranch () {
|
||||||
|
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
|
||||||
|
}
|
Ładowanie…
Reference in New Issue