Skip to content

Commit 48d658f

Browse files
committed
Added Lifecycle Command line args
It will first try to find it in the lifecycle folder, and if not found will treat it like a path. --prerun="my/path/to.yaml" or --prerun="my_prerun"
1 parent 82d380a commit 48d658f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

agent/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class TestDriverAgent extends EventEmitter2 {
6868
this.healMode = flags.healMode || flags.heal || false;
6969
this.sandboxId = flags.sandboxId || null;
7070
this.workingDir = flags.workingDir || process.cwd();
71+
this.postrun = flags.postrun || null;
72+
this.provision = flags.provision || null;
7173

7274
// Resolve thisFile to absolute path with proper extension
7375
if (this.thisFile) {
@@ -167,8 +169,8 @@ class TestDriverAgent extends EventEmitter2 {
167169

168170
this.analytics.track("exit", { failed });
169171

170-
if (shouldRunLifecycle) {
171-
await this.runLifecycle("postrun");
172+
if (shouldRunLifecycle && this.postrun) {
173+
await this.runLifecycle(this.postrun);
172174
}
173175

174176
// Emit exit event with exit code and close readline interface
@@ -1473,7 +1475,10 @@ ${regression}
14731475
this.instance = instance;
14741476
await this.renderSandbox(instance, headless);
14751477
await this.newSession();
1476-
await this.runLifecycle("provision");
1478+
1479+
if (this.provision) {
1480+
await this.runLifecycle(this.provision);
1481+
}
14771482
}
14781483

14791484
async start() {
@@ -1741,6 +1746,12 @@ ${regression}
17411746
}
17421747
}
17431748
}
1749+
1750+
// If lifecycleName is a filepath
1751+
if (fs.existsSync(path.resolve(lifecycleName))) {
1752+
lifecycleFile = path.resolve(lifecycleName);
1753+
}
1754+
17441755
if (lifecycleFile) {
17451756
await this.run(lifecycleFile, false, false);
17461757
}

agent/interface.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,27 @@ function createCommandDefinitions(agent) {
5151
summary: Flags.string({
5252
description: "Specify output file for summarize results",
5353
}),
54+
prerun: Flags.string({
55+
description: "File to run before the main test file. Can be the name of a file in the lifecycle folder, or an absolute path",
56+
default: "prerun",
57+
}),
58+
postrun: Flags.string({
59+
description:
60+
"File to after before the main test file. This will run regardless of if the test passes. can be the name of a file in the lifecycle folder, or an absolute path",
61+
default: "postrun",
62+
}),
63+
provision: Flags.string({
64+
description:
65+
"File to run when a new sandbox is provisioned. Can be the name of a file in the lifecycle folder, or an absolute path",
66+
default: "provision",
67+
}),
5468
},
5569
handler: async (args, flags) => {
5670
// Use --path flag if provided, otherwise fall back to args.file
5771
const file = normalizeFilePath(args.file);
5872

59-
await agent.runLifecycle("prerun");
73+
await agent.runLifecycle(flags.prerun);
74+
6075
// When run() is called through run.js CLI command, shouldExit should be true
6176
const shouldExit = agent.cliArgs?.command === "run";
6277
await agent.run(file, flags.write, shouldExit);

0 commit comments

Comments
 (0)