-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(repo): Introduce integration test for vite with sdk-node (#1921)
* feat(repo): Add integration test for express + vite * feat(repo): Enable express tests in CICD * fix(repo): Copy integration tests to OS temp path This change will help us avoid accidentally using top-level node_modules/ from the current monorepo and will allow us to run tests isolated from the monorepo related dependencies. We had to use a folder outside the monorepo for the integration tests to avoid having the npm module resolution algorithm find unrelated dependencies. * fix(repo): Exit integration tests on application error exit code * fix(repo): Link local clerk packages when version is missing * fix(repo): Fix `npm run nuke` yalc cleanup
- Loading branch information
Showing
26 changed files
with
322 additions
and
24 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
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
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,18 @@ | ||
import { constants } from '../constants'; | ||
import { applicationConfig } from '../models/applicationConfig'; | ||
import { templates } from '../templates'; | ||
|
||
const clerkNodeLocal = `file:${process.cwd()}/packages/sdk-node`; | ||
const vite = applicationConfig() | ||
.setName('express-vite') | ||
.useTemplate(templates['express-vite']) | ||
.setEnvFormatter('public', key => `VITE_${key}`) | ||
.addScript('setup', 'npm i --prefer-offline') | ||
.addScript('dev', 'npm run dev') | ||
.addScript('build', 'npm run build') | ||
.addScript('serve', 'npm run start') | ||
.addDependency('@clerk/clerk-sdk-node', constants.E2E_CLERK_VERSION || clerkNodeLocal); | ||
|
||
export const express = { | ||
vite, | ||
} as const; |
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
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
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
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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,26 @@ | ||
{ | ||
"name": "express-vite", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "vite build", | ||
"dev": "PORT=$PORT ts-node src/server/main.ts", | ||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview --port $PORT --no-open", | ||
"start": "PORT=$PORT ts-node src/server/main.ts" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.3.1", | ||
"ejs": "^3.1.6", | ||
"express": "^4.18.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.3", | ||
"vite-express": "^0.11.0" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.15", | ||
"@types/node": "^18.11.18", | ||
"nodemon": "^2.0.20", | ||
"vite": "^4.0.4" | ||
} | ||
} |
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,60 @@ | ||
// Should be at the top of the file - used to load clerk secret key | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
import { clerkClient } from '@clerk/clerk-sdk-node'; | ||
import express from 'express'; | ||
import ViteExpress from 'vite-express'; | ||
|
||
const app = express(); | ||
|
||
app.set('view engine', 'ejs'); | ||
app.set('views', 'src/views'); | ||
|
||
app.get('/api/protected', [clerkClient.expressRequireAuth() as any], (_req: any, res: any) => { | ||
res.send('Protected API response').end(); | ||
}); | ||
|
||
app.get('/sign-in', (_req: any, res: any) => { | ||
return res.render('sign-in.ejs', { | ||
publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY, | ||
signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
}); | ||
}); | ||
|
||
app.get('/', (_req: any, res: any) => { | ||
return res.render('index.ejs', { | ||
publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY, | ||
signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
}); | ||
}); | ||
|
||
app.get('/sign-up', (_req: any, res: any) => { | ||
return res.render('sign-up.ejs', { | ||
publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY, | ||
signUpUrl: process.env.CLERK_SIGN_UP_URL, | ||
}); | ||
}); | ||
|
||
app.get('/protected', (_req: any, res: any) => { | ||
return res.render('protected.ejs', { | ||
publishableKey: process.env.VITE_CLERK_PUBLISHABLE_KEY, | ||
signInUrl: process.env.CLERK_SIGN_IN_URL, | ||
signUpUrl: process.env.CLERK_SIGN_UP_URL, | ||
}); | ||
}); | ||
|
||
// Handle authentication error, otherwise application will crash | ||
// @ts-ignore | ||
app.use((err, req, res, next) => { | ||
if (err) { | ||
console.error(err); | ||
res.status(401).end(); | ||
return; | ||
} | ||
|
||
return next(); | ||
}); | ||
|
||
const port = parseInt(process.env.PORT as string) || 3002; | ||
ViteExpress.listen(app, port, () => console.log(`Server is listening on port ${port}...`)); |
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,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<script | ||
data-clerk-publishable-key="<%= publishableKey %>" | ||
onLoad="startClerk()" | ||
crossorigin="anonymous" | ||
async="" | ||
src="https://clerk.clerk.com/npm/@clerk/clerk-js@4/dist/clerk.browser.js" | ||
></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<div id="user-state"></div> | ||
|
||
<script> | ||
window.startClerk = async () => { | ||
await Clerk.load({ signInUrl: '<%= signInUrl %>' }); | ||
const appEl = document.querySelector('#app'); | ||
const controlStateEl = document.querySelector('#user-state'); | ||
if (Clerk.user) { | ||
Clerk.mountUserButton(appEl); | ||
controlStateEl.innerHTML = 'SignedIn'; | ||
} else { | ||
controlStateEl.innerHTML = 'SignedOut'; | ||
} | ||
}; | ||
</script> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
integration/templates/express-vite/src/views/protected.ejs
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,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<script | ||
data-clerk-publishable-key="<%= publishableKey %>" | ||
onLoad="startClerk()" | ||
crossorigin="anonymous" | ||
async="" | ||
src="https://clerk.clerk.com/npm/@clerk/clerk-js@4/dist/clerk.browser.js" | ||
></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<div id="user-state"></div> | ||
|
||
<script> | ||
window.startClerk = async () => { | ||
await Clerk.load({ signInUrl: '<%= signInUrl %>' }); | ||
if (Clerk.user) { | ||
const apiResponse = await fetch('/api/protected').then(res => res.text()); | ||
const div = document.createElement('div'); | ||
div.setAttribute('data-test-id', 'protected-api-response'); | ||
div.innerText = apiResponse; | ||
document.body.appendChild(div); | ||
} | ||
}; | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.