-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: fastify server for static html cdn testing * test: playwright ui test to validate cdn api reference * chore: resolve lockfile * chore: run testing server in background * test: remove failing expect * chore: clear request cache headers * chore: move playwright test folder * chore: only run playwright e2e tests * chore: resolve lockfile
- Loading branch information
Showing
11 changed files
with
433 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Playwright Tests | ||
|
||
on: | ||
schedule: | ||
# every hour | ||
- cron: '0 * * * *' | ||
push: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
node-version: [20] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'pnpm' | ||
- name: Install dependencies | ||
run: pnpm --filter cdn-api-reference install | ||
- name: Turborepo cache | ||
uses: dtinth/setup-github-actions-caching-for-turbo@v1 | ||
- name: Start static html server | ||
run: pnpm --filter cdn-api-reference dev & | ||
- name: Get installed Playwright version | ||
id: playwright-version | ||
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package.json').devDependencies['@playwright/test'])")" >> $GITHUB_ENV | ||
# TODO doesn't work | ||
- name: Cache playwright binaries | ||
uses: actions/cache@v4 | ||
id: playwright-cache | ||
with: | ||
path: '~/.cache/ms-playwright' | ||
key: '${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}' | ||
restore-keys: ${{ runner.os }}-playwright- | ||
- name: Install Playwright browser binaries & OS dependencies | ||
run: pnpm exec playwright install --with-deps | ||
- name: Run e2e tests | ||
run: CI=1 pnpm test:e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@scalar-examples/cdn-api-reference", | ||
"license": "MIT", | ||
"author": "Scalar (https://github.com/scalar)", | ||
"homepage": "https://github.com/scalar/scalar", | ||
"bugs": "https://github.com/scalar/scalar/issues/new/choose", | ||
"version": "0.0.1", | ||
"private": true, | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"scripts": { | ||
"dev": "nodemon --exec \"vite-node src/index.ts\" --ext ts --quiet --watch ./", | ||
"types:check": "tsc --noEmit --skipLibCheck" | ||
}, | ||
"type": "module", | ||
"dependencies": { | ||
"@fastify/static": "^7.0.1", | ||
"fastify": "^4.23.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.6.3", | ||
"nodemon": "^3.0.1", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.1.1", | ||
"vite-node": "^1.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import fastifyStatic from '@fastify/static' | ||
import fastify from 'fastify' | ||
import { join } from 'node:path' | ||
|
||
const app = await fastify({ logger: true }) | ||
|
||
await app.register(fastifyStatic, { | ||
root: join(__dirname, 'public'), | ||
prefix: '/', | ||
}) | ||
|
||
app.get('/', (_request, reply) => { | ||
reply.sendFile('api-reference-cdn.html', { cacheControl: false }) // overriding the options disabling cache-control headers) // serving path.join(__dirname, 'public', 'myHtml.html') directly | ||
}) | ||
|
||
// Run the server! | ||
try { | ||
await app.listen({ port: 3173 }) | ||
} catch (err) { | ||
app.log.error(err) | ||
process.exit(1) | ||
} |
35 changes: 35 additions & 0 deletions
35
examples/cdn-api-reference/src/public/api-reference-cdn.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>API Reference</title> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1" /> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<!-- Add your own OpenAPI/Swagger spec file URL here: --> | ||
<!-- Note: this includes our proxy, you can remove the following line if you do not need it --> | ||
<!-- data-proxy-url="https://api.scalar.com/request-proxy" --> | ||
<script | ||
id="api-reference" | ||
data-url="https://petstore3.swagger.io/api/v3/openapi.json" | ||
data-proxy-url="https://api.scalar.com/request-proxy"></script> | ||
<!-- You can also set a full configuration object like this --> | ||
<!-- easier for nested objects --> | ||
<script> | ||
var configuration = { | ||
theme: 'purple', | ||
} | ||
|
||
var apiReference = document.getElementById('api-reference') | ||
apiReference.dataset.configuration = JSON.stringify(configuration) | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["vite/client"] | ||
}, | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'path' | ||
import { defineConfig } from 'vite' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
resolve: { | ||
alias: [ | ||
{ | ||
// Resolve the uncompiled source code for all @scalar packages | ||
// @scalar/* -> packages/*/ | ||
// (not @scalar/*/style.css) | ||
find: /^@scalar\/(?!(snippetz|components\/style\.css|components\b))(.+)/, | ||
replacement: path.resolve(__dirname, '../../packages/$2/src/index.ts'), | ||
}, | ||
], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
// { | ||
// name: 'webkit', | ||
// use: { ...devices['Desktop Safari'] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
{ | ||
name: 'Mobile Chrome', | ||
use: { ...devices['Pixel 5'] }, | ||
}, | ||
{ | ||
name: 'Mobile Safari', | ||
use: { ...devices['iPhone 12'] }, | ||
}, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}) |
Oops, something went wrong.