Skip to content

Commit

Permalink
test: add setup for Vercel / Netlify tests (#7716)
Browse files Browse the repository at this point in the history
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
  • Loading branch information
Princesseuh and yanthomasdev authored Jul 21, 2023
1 parent e5e5cc8 commit 471324b
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 19 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/test-hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Hosted tests

on:
schedule:
- cron: '0 0 * * 0'

env:
ASTRO_TELEMETRY_DISABLED: true
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_TEST_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_TEST_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_TEST_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TEST_AUTH_TOKEN }}
FORCE_COLOR: true

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Setup PNPM
uses: pnpm/action-setup@v2

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Install Hosts CLIs
run: pnpm install --global netlify-cli vercel

- name: Deploy Vercel
working-directory: ./packages/integrations/vercel/test/hosted/hosted-astro-project
run:
pnpm run build
vercel --prod --prebuilt

- name: Deploy Netlify
working-directory: ./packages/integrations/netlify/test/hosted/hosted-astro-project
run:
pnpm run build
netlify deploy --prod

- name: Test both hosts
run:
pnpm run test:e2e:hosts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist/
*.tsbuildinfo
.DS_Store
.vercel
.netlify
_site/
scripts/smoke/*-main/
scripts/memory/project/src/pages/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:vite-ci": "turbo run test --filter=astro",
"test:e2e": "cd packages/astro && pnpm playwright install && pnpm run test:e2e",
"test:e2e:match": "cd packages/astro && pnpm playwright install && pnpm run test:e2e:match",
"test:e2e:hosts": "turbo run test:hosted",
"benchmark": "astro-benchmark",
"lint": "eslint . --report-unused-disable-directives",
"version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format",
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test-fn": "mocha --exit --timeout 20000 --file \"./test/setup.js\" test/functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net --allow-env --allow-write ./test/edge-functions/",
"test": "pnpm test-fn"
"test": "pnpm test-fn",
"test:hosted": "mocha --exit --timeout 30000 test/hosted"
},
"dependencies": {
"@astrojs/underscore-redirects": "^0.2.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/netlify/test/hosted/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The tests in this folder are done directly on a deployed Netlify website (hosted at https://curious-boba-495d6d.netlify.app) and are not run by the test suite. They instead run every week through a GitHub action.

The purpose of those tests is to make sure that everything works as expected while deployed. In a way, they're as E2E as it gets.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import netlify from '@astrojs/netlify';
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
output: 'server',
adapter: netlify(),
experimental: {
assets: true,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "netlify-hosted-astro-project",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "astro build"
},
"dependencies": {
"@astrojs/netlify": "file:../../..",
"astro": "file:../../../../../astro"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="astro/client-image" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
import { Image } from 'astro:assets';
import penguin from '../assets/penguin.png';
---

<Image src={penguin} width={300} alt="" />
13 changes: 13 additions & 0 deletions packages/integrations/netlify/test/hosted/hosted.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from 'chai';

const NETLIFY_TEST_URL = 'https://curious-boba-495d6d.netlify.app';

describe('Hosted Netlify Tests', () => {
it('Image endpoint works', async () => {
const image = await fetch(
NETLIFY_TEST_URL + '/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp'
);

expect(image.status).to.equal(200);
});
});
3 changes: 2 additions & 1 deletion packages/integrations/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "mocha --exit --timeout 20000 --file \"./test/setup.js\" test/"
"test": "mocha --exit --timeout 20000 --file \"./test/setup.js\" test/ --ignore test/hosted",
"test:hosted": "mocha --exit --timeout 30000 test/hosted"
},
"dependencies": {
"@astrojs/internal-helpers": "^0.1.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/vercel/test/hosted/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The tests in this folder are done directly on a deployed Vercel website (hosted at https://astro-vercel-image-test.vercel.app) and are not run by the test suite. They instead run every week through a GitHub action.

The purpose of those tests is to make sure that everything works as expected while deployed. In a way, they're as E2E as it gets.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import vercel from '@astrojs/vercel/serverless';
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
output: 'server',
adapter: vercel(),
experimental: {
assets: true,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "vercel-hosted-astro-project",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "astro build"
},
"dependencies": {
"@astrojs/vercel": "file:../../..",
"astro": "file:../../../../../astro"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="astro/client-image" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
import { Image } from 'astro:assets';
import penguin from '../assets/penguin.png';
---

<Image src={penguin} width={300} alt="" />
13 changes: 13 additions & 0 deletions packages/integrations/vercel/test/hosted/hosted.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from 'chai';

const VERCEL_TEST_URL = 'https://astro-vercel-image-test.vercel.app';

describe('Hosted Vercel Tests', () => {
it('Image endpoint works', async () => {
const image = await fetch(
VERCEL_TEST_URL + '/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp'
);

expect(image.status).to.equal(200);
});
});
Loading

0 comments on commit 471324b

Please sign in to comment.