Skip to content

Commit ad1266b

Browse files
committed
feat(integration): switch long-running test apps from dev to build+serve
1 parent 1a6d92a commit ad1266b

3 files changed

Lines changed: 45 additions & 18 deletions

File tree

integration/models/application.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,48 @@ export const application = (
144144
get serveOutput() {
145145
return serveOutput;
146146
},
147-
serve: async (opts: { port?: number; manualStart?: boolean } = {}) => {
147+
serve: async (opts: { port?: number; manualStart?: boolean; detached?: boolean; serverUrl?: string } = {}) => {
148148
const log = logger.child({ prefix: 'serve' }).info;
149149
const port = opts.port || (await getPort());
150-
// TODO: get serverUrl as in dev()
151-
const serverUrl = `http://localhost:${port}`;
152-
// If this is ever used as a background process, we need to make sure
153-
// it's not using the log function. See the dev() method above
150+
const getServerUrl = () => {
151+
if (opts.serverUrl) {
152+
return opts.serverUrl.includes(':') ? opts.serverUrl : `${opts.serverUrl}:${port}`;
153+
}
154+
return serverUrl || `http://localhost:${port}`;
155+
};
156+
const runtimeServerUrl = getServerUrl();
157+
log(`Will try to serve app at ${runtimeServerUrl}`);
158+
159+
if (opts.manualStart) {
160+
state.serverUrl = runtimeServerUrl;
161+
return { port, serverUrl: runtimeServerUrl };
162+
}
163+
154164
const proc = run(scripts.serve, {
155165
cwd: appDirPath,
156166
env: { PORT: port.toString() },
157-
log: (msg: string) => {
158-
serveOutput += `\n${msg}`;
159-
log(msg);
160-
},
167+
detached: opts.detached,
168+
stdout: opts.detached ? fs.openSync(stdoutFilePath, 'a') : undefined,
169+
stderr: opts.detached ? fs.openSync(stderrFilePath, 'a') : undefined,
170+
log: opts.detached
171+
? undefined
172+
: (msg: string) => {
173+
serveOutput += `\n${msg}`;
174+
log(msg);
175+
},
161176
});
177+
178+
if (opts.detached) {
179+
const shouldExit = () => !!proc.exitCode && proc.exitCode !== 0;
180+
await waitForServer(runtimeServerUrl, { log, maxAttempts: Infinity, shouldExit });
181+
} else {
182+
await waitForIdleProcess(proc);
183+
}
184+
185+
log(`Server started at ${runtimeServerUrl}, pid: ${proc.pid}`);
162186
cleanupFns.push(() => awaitableTreekill(proc.pid, 'SIGKILL'));
163-
await waitForIdleProcess(proc);
164-
state.serverUrl = serverUrl;
165-
return { port, serverUrl, pid: proc };
187+
state.serverUrl = runtimeServerUrl;
188+
return { port, serverUrl: runtimeServerUrl, pid: proc.pid };
166189
},
167190
stop: async () => {
168191
logger.info('Stopping...');

integration/models/longRunningApplication.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
100100
throw error;
101101
}
102102
try {
103-
const { port, serverUrl, pid } = await app.dev({ detached: true });
103+
await app.build();
104+
} catch (error) {
105+
console.error('Error during app build:', error);
106+
throw error;
107+
}
108+
try {
109+
const { port, serverUrl, pid } = await app.serve({ detached: true });
104110
stateFile.addLongRunningApp({ port, serverUrl, pid, id, appDir: app.appDir, env: params.env.toJson() });
105111
} catch (error) {
106-
console.error('Error during app dev:', error);
112+
console.error('Error during app serve:', error);
107113
throw error;
108114
}
109115
},
@@ -126,9 +132,7 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
126132
setup: () => Promise.resolve(),
127133
withEnv: () => Promise.resolve(),
128134
teardown: () => Promise.resolve(),
129-
build: () => {
130-
throw new Error('build for long running apps is not supported yet');
131-
},
135+
build: () => Promise.resolve(),
132136
get name() {
133137
return name;
134138
},

integration/tests/global.setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { appConfigs } from '../presets';
55
import { fs, parseEnvOptions, startClerkJsHttpServer, startClerkUiHttpServer } from '../scripts';
66

77
setup('start long running apps', async () => {
8-
setup.setTimeout(90_000);
8+
setup.setTimeout(300_000);
99

1010
await fs.ensureDir(constants.TMP_DIR);
1111

0 commit comments

Comments
 (0)