Skip to content

Commit

Permalink
ci: add test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Apr 4, 2024
1 parent 5ce7a61 commit f28fad0
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: test

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Dependencies
run: npm ci

- name: Build Registry
run: npm run build

- name: Run Test
env:
R2_HOSTNAME: ${{ secrets.TEST_R2_HOSTNAME }}
S3_ACCESS_KEY_ID: ${{ secrets.TEST_S3_ACCESS_KEY_ID }}
S3_BUCKET: ${{ secrets.TEST_S3_BUCKET }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
S3_SECRET_ACCESS_KEY: ${{ secrets.TEST_S3_SECRET_ACCESS_KEY }}
run: npm test
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"scripts": {
"dev": "astro dev",
"start": "node build/index.cjs",
"build": "astro build && esbuild registry/index.ts --bundle --format=cjs --loader:.html=text --loader:.svg=text --external:esbuild --platform=node --outfile=build/index.cjs"
"build": "astro build && esbuild registry/index.ts --bundle --format=cjs --loader:.html=text --loader:.svg=text --external:esbuild --platform=node --outfile=build/index.cjs",
"pretest": "node build/index.cjs &",
"test": "node --test",
"posttest": "kill $(lsof -t -i:3000)"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.540.0",
Expand Down
67 changes: 67 additions & 0 deletions test/registry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import assert from 'node:assert'
import test from 'node:test'

async function fetchStr(url) {
const res = await fetch(url)

if (!res.ok) {
await res.body.cancel()

return null
}

return await res.text()
}

async function fetchJson(url) {
const res = await fetch(url)

if (!res.ok) {
await res.body.cancel()

return null
}

return await res.json()
}

test('latest tag', async () => {
const latestTag = (await fetchJson('https://api.github.com/repos/esbuild/deno-esbuild/tags'))[0].name

const res = await fetch('http://localhost:3000/esbuild/deno-esbuild/mod.js', {
redirect: 'manual'
})

await res.body.cancel()

assert.strictEqual(res.headers.get('location', `https://deno.re/esbuild/deno-esbuild@${latestTag}/mod.js`), expected)
})

test('specific commit', async () => {
const actual = await fetchStr('http://localhost:3000/esbuild/deno-esbuild@d4ebc0f33d39d5b8cc94eec4b1a94ce5b388cd6f/mod.js')
const expected = await fetchStr('https://raw.githubusercontent.com/esbuild/deno-esbuild/d4ebc0f33d39d5b8cc94eec4b1a94ce5b388cd6f/mod.js')

assert.strictEqual(actual, expected)
})

test('specific tag', async () => {
const actual = await fetchStr('http://localhost:3000/esbuild/[email protected]/mod.js')
const expected = await fetchStr('https://raw.githubusercontent.com/esbuild/deno-esbuild/v0.19.0/mod.js')

assert.strictEqual(actual, expected)
})

test('omit entry point', async () => {
const actual = await fetchStr('http://localhost:3000/esbuild/[email protected]')
const expected = await fetchStr('https://raw.githubusercontent.com/esbuild/deno-esbuild/v0.20.0/mod.js')

assert.strictEqual(actual, expected)
})

test('type header', async () => {
const res = await fetch('http://localhost:3000/esbuild/[email protected]/mod.js')

await res.body.cancel()

assert.strictEqual(res.headers.get('x-typescript-types'), `https://deno.re/esbuild/[email protected]/mod.d.ts`)
})

0 comments on commit f28fad0

Please sign in to comment.