Skip to content

Commit b52a63c

Browse files
authored
test(repo): Add integration tests for NextJS quickstart guide (clerk#2888)
* test(repo): Add integration tests for NextJS quickstart guide * test(repo): Add more tests for NextJS quickstart * test(repo): Add more tests for NextJS quickstart * chore(repo): Add Changeset * chore(repo): Add integration/templates to .eslintignore * chore(repo): Apply prettier changes * chore(repo): Added NPM script for running quickstart integration suite * chore(repo): Update quickstart integration tests * chore(repo): Fix middleware match in next-app-router template for integration tests
1 parent d966cc9 commit b52a63c

29 files changed

Lines changed: 672 additions & 7 deletions

.changeset/rude-falcons-thank.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ packages/*/examples
1414
.cache
1515
.yalc
1616
package-lock.json
17+
**/integration/templates/**/*

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138

139139
strategy:
140140
matrix:
141-
test-name: [ 'generic', 'nextjs', 'express' ]
141+
test-name: [ 'generic', 'nextjs', 'express', 'quickstart']
142142

143143
steps:
144144
- name: Checkout Repo

integration/models/environment.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
export type EnvironmentConfig = ReturnType<typeof environmentConfig>;
1+
type EnvironmentVariables = {
2+
public: Map<string, string>;
3+
private: Map<string, string>;
4+
};
5+
6+
export type EnvironmentConfig = {
7+
get id(): string;
8+
setId(newId: string): EnvironmentConfig;
9+
setEnvVariable(type: keyof EnvironmentVariables, name: string, value: any): EnvironmentConfig;
10+
removeEnvVariable(type: keyof EnvironmentVariables, name: string): EnvironmentConfig;
11+
get publicVariables(): EnvironmentVariables['public'];
12+
get privateVariables(): EnvironmentVariables['private'];
13+
toJson(): { public: Record<string, string>; private: Record<string, string> };
14+
fromJson(json: ReturnType<EnvironmentConfig['toJson']>): EnvironmentConfig;
15+
clone(): EnvironmentConfig;
16+
};
217

318
export const environmentConfig = () => {
419
let id = '';
5-
const envVars = { public: new Map<string, string>(), private: new Map<string, string>() };
20+
const envVars: EnvironmentVariables = {
21+
public: new Map<string, string>(),
22+
private: new Map<string, string>(),
23+
};
624

7-
const self = {
25+
const self: EnvironmentConfig = {
826
setId: (newId: string) => {
927
id = newId;
1028
return self;
1129
},
1230
get id() {
1331
return id;
1432
},
15-
setEnvVariable: (type: keyof typeof envVars, name: string, value: string) => {
33+
setEnvVariable: (type, name, value) => {
1634
envVars[type].set(name, value);
1735
return self;
1836
},
37+
removeEnvVariable: (type, name) => {
38+
envVars[type].delete(name);
39+
return self;
40+
},
1941
get publicVariables() {
2042
return envVars.public;
2143
},
@@ -28,7 +50,7 @@ export const environmentConfig = () => {
2850
private: Object.fromEntries(envVars.private),
2951
};
3052
},
31-
fromJson: (json: ReturnType<typeof self.toJson>) => {
53+
fromJson: json => {
3254
Object.entries(json.public).forEach(([k, v]) => self.setEnvVariable('public', k, v));
3355
Object.entries(json.private).forEach(([k, v]) => self.setEnvVariable('private', k, v));
3456
return self;

integration/presets/envs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ const withCustomRoles = environmentConfig()
5151
.setEnvVariable('public', 'CLERK_SIGN_UP_URL', '/sign-up')
5252
.setEnvVariable('public', 'CLERK_JS_URL', constants.E2E_APP_CLERK_JS || 'http://localhost:18211/clerk.browser.js');
5353

54+
const withEmailCodesQuickstart = withEmailCodes
55+
.removeEnvVariable('public', 'CLERK_SIGN_IN_URL')
56+
.removeEnvVariable('public', 'CLERK_SIGN_UP_URL');
57+
5458
export const envs = {
5559
withEmailCodes,
5660
withEmailLinks,
5761
withCustomRoles,
62+
withEmailCodesQuickstart,
5863
} as const;

integration/presets/longRunningApps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const createLongRunningApps = () => {
1919
{ id: 'remix.node.withEmailCodes', config: remix.remixNode, env: envs.withEmailCodes },
2020
{ id: 'next.appRouter.withEmailCodes', config: next.appRouter, env: envs.withEmailCodes },
2121
{ id: 'next.appRouter.withCustomRoles', config: next.appRouter, env: envs.withCustomRoles },
22+
{ id: 'quickstart.next.appRouter', config: next.appRouterQuickstart, env: envs.withEmailCodesQuickstart },
2223
] as const;
2324

2425
const apps = configs.map(longRunningApplication);

integration/presets/next.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ const appRouterTurbo = appRouter
1919
.setName('next-app-router-turbopack')
2020
.addScript('dev', 'npm run dev -- --turbo');
2121

22+
const appRouterQuickstart = appRouter
23+
.clone()
24+
.setName('next-app-router-quickstart')
25+
.useTemplate(templates['next-app-router-quickstart']);
26+
2227
export const next = {
2328
appRouter,
2429
appRouterTurbo,
30+
appRouterQuickstart,
2531
} as const;

integration/templates/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const templates = {
55
// If /integration becomes a module in the future, use these helpers:
66
// 'next-app-router': fileURLToPath(new URL('./next-app-router', import.meta.url)),
77
'next-app-router': resolve(__dirname, './next-app-router'),
8+
'next-app-router-quickstart': resolve(__dirname, './next-app-router-quickstart'),
89
'react-cra': resolve(__dirname, './react-cra'),
910
'react-vite': resolve(__dirname, './react-vite'),
1011
'express-vite': resolve(__dirname, './express-vite'),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
root: true,
3+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

0 commit comments

Comments
 (0)