Skip to content

Commit 62a9425

Browse files
authored
chore: seed .dev.vars and .env.local if example files exist at test time (#846)
1 parent c907fc9 commit 62a9425

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

playwright-tests/utils/template-server.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { spawn, ChildProcess } from "child_process";
22
import { join } from "path";
3+
import { existsSync, copyFileSync } from "fs";
34
import fetch from "node-fetch";
45

56
// Helper function to kill process tree
@@ -167,6 +168,9 @@ export class TemplateServerManager {
167168
`Starting server for ${template.name} on port ${template.port}...`,
168169
);
169170

171+
// Copy example env files if they exist
172+
this.copyEnvFiles(template.path);
173+
170174
const server = spawn("npm", ["run", "dev"], {
171175
cwd: template.path,
172176
stdio: "pipe",
@@ -254,6 +258,23 @@ export class TemplateServerManager {
254258
await Promise.all(promises);
255259
}
256260

261+
private copyEnvFiles(templatePath: string): void {
262+
const envFileMappings = [
263+
{ example: ".dev.vars.example", target: ".dev.vars" },
264+
{ example: ".env.local.example", target: ".env.local" },
265+
];
266+
267+
for (const { example, target } of envFileMappings) {
268+
const examplePath = join(templatePath, example);
269+
const targetPath = join(templatePath, target);
270+
271+
if (existsSync(examplePath) && !existsSync(targetPath)) {
272+
copyFileSync(examplePath, targetPath);
273+
console.log(`Copied ${example} to ${target}`);
274+
}
275+
}
276+
}
277+
257278
private async waitForServer(url: string, timeout: number): Promise<void> {
258279
const start = Date.now();
259280

0 commit comments

Comments
 (0)