intellitester 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { loadTestDefinition } from './chunk-A3UKMKXR.js';
1
+ import { loadTestDefinition } from './chunk-YEB47TDJ.js';
2
2
  import { track } from './chunk-XINWSJFM.js';
3
3
  import { loadCleanupHandlers, executeCleanup, saveFailedCleanup } from './chunk-4P2XW7LQ.js';
4
4
  import { init_esm_shims } from './chunk-TM6IHTOK.js';
@@ -2193,6 +2193,27 @@ async function evaluate(options) {
2193
2193
 
2194
2194
  // src/executors/web/playwrightExecutor.ts
2195
2195
  var defaultScreenshotDir = path4__default.join(process.cwd(), "artifacts", "screenshots");
2196
+ var resolveStorageStatePath = (value, baseDir) => {
2197
+ if (typeof value !== "string") return value;
2198
+ return path4__default.isAbsolute(value) ? value : path4__default.resolve(baseDir, value);
2199
+ };
2200
+ var interpolateTrackMetadata = (value, variables) => {
2201
+ if (typeof value === "string") {
2202
+ return interpolateVariables(value, variables);
2203
+ }
2204
+ if (Array.isArray(value)) {
2205
+ return value.map((entry) => interpolateTrackMetadata(entry, variables));
2206
+ }
2207
+ if (value && typeof value === "object") {
2208
+ return Object.fromEntries(
2209
+ Object.entries(value).map(([key, entry]) => [
2210
+ key,
2211
+ interpolateTrackMetadata(entry, variables)
2212
+ ])
2213
+ );
2214
+ }
2215
+ return value;
2216
+ };
2196
2217
  var resolveUrl = (value, baseUrl) => {
2197
2218
  if (!baseUrl) return value;
2198
2219
  try {
@@ -2445,8 +2466,9 @@ async function executeActionWithRetry(page, action, index, options) {
2445
2466
  const extras = {};
2446
2467
  const buildTrackPayload = (stepExtras) => {
2447
2468
  if (!("track" in action)) return null;
2448
- const track2 = action.track;
2449
- if (!track2 || typeof track2 !== "object") return null;
2469
+ const rawTrack = action.track;
2470
+ if (!rawTrack || typeof rawTrack !== "object") return null;
2471
+ const track2 = interpolateTrackMetadata(rawTrack, context.variables);
2450
2472
  if (typeof track2.type !== "string" || typeof track2.id !== "string") return null;
2451
2473
  const { includeStepContext, ...rest } = track2;
2452
2474
  const payload = {
@@ -2970,7 +2992,7 @@ async function executeActionWithRetry(page, action, index, options) {
2970
2992
  });
2971
2993
  }
2972
2994
  } else {
2973
- const { loadWorkflowDefinition, loadTestDefinition: loadTestDefinition2 } = await import('./loader-GDI65KW7.js');
2995
+ const { loadWorkflowDefinition, loadTestDefinition: loadTestDefinition2 } = await import('./loader-JTBS7GW4.js');
2974
2996
  const workflowPath = path4__default.resolve(process.cwd(), branchToExecute.workflow);
2975
2997
  const workflowDir = path4__default.dirname(workflowPath);
2976
2998
  if (debugMode) {
@@ -3173,7 +3195,8 @@ var runWebTest = async (test, options = {}) => {
3173
3195
  console.log(`Testing at viewport: ${size} (${viewport.width}x${viewport.height})`);
3174
3196
  }
3175
3197
  const browserContext = await browser.newContext({
3176
- viewport: { width: viewport.width, height: viewport.height }
3198
+ viewport: { width: viewport.width, height: viewport.height },
3199
+ ...options.storageState ? { storageState: options.storageState } : {}
3177
3200
  });
3178
3201
  const page = await browserContext.newPage();
3179
3202
  page.setDefaultTimeout(defaultTimeout);
@@ -3371,8 +3394,9 @@ var runWebTest = async (test, options = {}) => {
3371
3394
  const sizeResults = [];
3372
3395
  const buildTrackPayload = (action, index, stepExtras) => {
3373
3396
  if (!("track" in action)) return null;
3374
- const track2 = action.track;
3375
- if (!track2 || typeof track2 !== "object") return null;
3397
+ const rawTrack = action.track;
3398
+ if (!rawTrack || typeof rawTrack !== "object") return null;
3399
+ const track2 = interpolateTrackMetadata(rawTrack, executionContext.variables);
3376
3400
  if (typeof track2.type !== "string" || typeof track2.id !== "string") return null;
3377
3401
  const { includeStepContext, ...rest } = track2;
3378
3402
  const payload = {
@@ -3482,6 +3506,60 @@ var runWebTest = async (test, options = {}) => {
3482
3506
  options.onStepComplete?.(sizeResults[sizeResults.length - 1], index, test.steps.length);
3483
3507
  continue;
3484
3508
  }
3509
+ if (action.type === "saveStorageState") {
3510
+ const saveAction = action;
3511
+ try {
3512
+ if (saveAction.path) {
3513
+ const resolvedPath = interpolateVariables(saveAction.path, executionContext.variables);
3514
+ const baseDir = options.testFilePath ? path4__default.dirname(options.testFilePath) : process.cwd();
3515
+ const absPath = path4__default.isAbsolute(resolvedPath) ? resolvedPath : path4__default.resolve(baseDir, resolvedPath);
3516
+ await page.context().storageState({ path: absPath });
3517
+ if (debugMode) {
3518
+ console.log(`[DEBUG] Saved storage state to ${absPath}`);
3519
+ }
3520
+ } else if (saveAction.handler) {
3521
+ const resolvedHandler = interpolateVariables(saveAction.handler, executionContext.variables);
3522
+ const baseDir = options.testFilePath ? path4__default.dirname(options.testFilePath) : process.cwd();
3523
+ const absPath = path4__default.isAbsolute(resolvedHandler) ? resolvedHandler : path4__default.resolve(baseDir, resolvedHandler);
3524
+ let loadPath = absPath;
3525
+ if (absPath.endsWith(".ts")) {
3526
+ const jsPath = absPath.replace(/\.ts$/, ".js");
3527
+ try {
3528
+ await fs__default.access(jsPath);
3529
+ loadPath = jsPath;
3530
+ } catch {
3531
+ }
3532
+ }
3533
+ const mod = await import(`${loadPath}?t=${Date.now()}`);
3534
+ const fn = mod.default ?? mod;
3535
+ if (typeof fn !== "function") {
3536
+ throw new Error(`saveStorageState handler at ${resolvedHandler} did not export a default function`);
3537
+ }
3538
+ await fn({
3539
+ page,
3540
+ context: page.context(),
3541
+ variables: executionContext.variables
3542
+ });
3543
+ if (debugMode) {
3544
+ console.log(`[DEBUG] Ran custom saveStorageState handler: ${resolvedHandler}`);
3545
+ }
3546
+ } else {
3547
+ throw new Error("saveStorageState requires either `path` or `handler` (schema should have caught this)");
3548
+ }
3549
+ sizeResults.push({ action, status: "passed" });
3550
+ options.onStepComplete?.(sizeResults[sizeResults.length - 1], index, test.steps.length);
3551
+ const trackedPayload = buildTrackPayload(action, index);
3552
+ if (trackedPayload) {
3553
+ await track(trackedPayload);
3554
+ }
3555
+ } catch (e) {
3556
+ const errMsg = e instanceof Error ? e.message : String(e);
3557
+ sizeResults.push({ action, status: "failed", error: errMsg });
3558
+ options.onStepComplete?.(sizeResults[sizeResults.length - 1], index, test.steps.length);
3559
+ throw e;
3560
+ }
3561
+ continue;
3562
+ }
3485
3563
  const actionExtras = await executeActionWithRetry(page, action, index, {
3486
3564
  baseUrl: options.baseUrl ?? test.config?.web?.baseUrl,
3487
3565
  context: executionContext,
@@ -3568,6 +3646,23 @@ var runWebTest = async (test, options = {}) => {
3568
3646
  // src/executors/web/workflowExecutor.ts
3569
3647
  init_esm_shims();
3570
3648
  var defaultScreenshotDir2 = path4__default.join(process.cwd(), "artifacts", "screenshots");
3649
+ var interpolateTrackMetadata2 = (value, variables) => {
3650
+ if (typeof value === "string") {
3651
+ return interpolateVariables(value, variables);
3652
+ }
3653
+ if (Array.isArray(value)) {
3654
+ return value.map((entry) => interpolateTrackMetadata2(entry, variables));
3655
+ }
3656
+ if (value && typeof value === "object") {
3657
+ return Object.fromEntries(
3658
+ Object.entries(value).map(([key, entry]) => [
3659
+ key,
3660
+ interpolateTrackMetadata2(entry, variables)
3661
+ ])
3662
+ );
3663
+ }
3664
+ return value;
3665
+ };
3571
3666
  var getBrowser2 = (browser) => {
3572
3667
  switch (browser) {
3573
3668
  case "firefox":
@@ -3590,7 +3685,7 @@ function interpolateWorkflowVariables(value, currentVariables, testResults) {
3590
3685
  return result;
3591
3686
  });
3592
3687
  }
3593
- async function runTestInWorkflow(test, page, context, options, _workflowDir, workflowBaseUrl) {
3688
+ async function runTestInWorkflow(test, page, context, options, workflowDir, testFilePath, workflowBaseUrl) {
3594
3689
  const results = [];
3595
3690
  const debugMode = options.debug ?? false;
3596
3691
  const screenshotDir = defaultScreenshotDir2;
@@ -3621,8 +3716,9 @@ async function runTestInWorkflow(test, page, context, options, _workflowDir, wor
3621
3716
  };
3622
3717
  const buildTrackPayload = (action, index, stepExtras) => {
3623
3718
  if (!("track" in action)) return null;
3624
- const track2 = action.track;
3625
- if (!track2 || typeof track2 !== "object") return null;
3719
+ const rawTrack = action.track;
3720
+ if (!rawTrack || typeof rawTrack !== "object") return null;
3721
+ const track2 = interpolateTrackMetadata2(rawTrack, context.variables);
3626
3722
  if (typeof track2.type !== "string" || typeof track2.id !== "string") return null;
3627
3723
  const { includeStepContext, ...rest } = track2;
3628
3724
  const payload = {
@@ -3778,6 +3874,52 @@ async function runTestInWorkflow(test, page, context, options, _workflowDir, wor
3778
3874
  }
3779
3875
  continue;
3780
3876
  }
3877
+ case "saveStorageState": {
3878
+ const saveAction = action;
3879
+ if (saveAction.path) {
3880
+ const resolvedPath = interpolate(saveAction.path);
3881
+ const baseDir = path4__default.dirname(testFilePath);
3882
+ const absPath = path4__default.isAbsolute(resolvedPath) ? resolvedPath : path4__default.resolve(baseDir, resolvedPath);
3883
+ await page.context().storageState({ path: absPath });
3884
+ if (debugMode) {
3885
+ console.log(` [DEBUG] Saved storage state to ${absPath}`);
3886
+ }
3887
+ } else if (saveAction.handler) {
3888
+ const resolvedHandler = interpolate(saveAction.handler);
3889
+ const baseDir = path4__default.dirname(testFilePath);
3890
+ const absPath = path4__default.isAbsolute(resolvedHandler) ? resolvedHandler : path4__default.resolve(baseDir, resolvedHandler);
3891
+ let loadPath = absPath;
3892
+ if (absPath.endsWith(".ts")) {
3893
+ const jsPath = absPath.replace(/\.ts$/, ".js");
3894
+ try {
3895
+ await fs__default.access(jsPath);
3896
+ loadPath = jsPath;
3897
+ } catch {
3898
+ }
3899
+ }
3900
+ const mod = await import(`${loadPath}?t=${Date.now()}`);
3901
+ const fn = mod.default ?? mod;
3902
+ if (typeof fn !== "function") {
3903
+ throw new Error(`saveStorageState handler at ${resolvedHandler} did not export a default function`);
3904
+ }
3905
+ await fn({
3906
+ page,
3907
+ context: page.context(),
3908
+ variables: context.variables
3909
+ });
3910
+ if (debugMode) {
3911
+ console.log(` [DEBUG] Ran custom saveStorageState handler: ${resolvedHandler}`);
3912
+ }
3913
+ } else {
3914
+ throw new Error("saveStorageState requires either `path` or `handler` (schema should have caught this)");
3915
+ }
3916
+ results.push({ action, status: "passed" });
3917
+ const trackedPayload2 = buildTrackPayload(action, index);
3918
+ if (trackedPayload2) {
3919
+ await track(trackedPayload2);
3920
+ }
3921
+ break;
3922
+ }
3781
3923
  case "setVar": {
3782
3924
  let value;
3783
3925
  if (action.value) {
@@ -4149,11 +4291,11 @@ async function runTestInWorkflow(test, page, context, options, _workflowDir, wor
4149
4291
  results.push({ action: nestedAction, status: "passed" });
4150
4292
  }
4151
4293
  } else if (typeof branch === "object" && "workflow" in branch) {
4152
- const workflowPath = path4__default.resolve(_workflowDir, branch.workflow);
4294
+ const workflowPath = path4__default.resolve(workflowDir, branch.workflow);
4153
4295
  if (debugMode) {
4154
4296
  console.log(` [DEBUG] waitForBranch: loading workflow from ${workflowPath}`);
4155
4297
  }
4156
- const { loadWorkflowDefinition } = await import('./loader-GDI65KW7.js');
4298
+ const { loadWorkflowDefinition } = await import('./loader-JTBS7GW4.js');
4157
4299
  const nestedWorkflow = await loadWorkflowDefinition(workflowPath);
4158
4300
  if (branch.variables) {
4159
4301
  for (const [key, value] of Object.entries(branch.variables)) {
@@ -4162,8 +4304,8 @@ async function runTestInWorkflow(test, page, context, options, _workflowDir, wor
4162
4304
  }
4163
4305
  }
4164
4306
  for (const testRef of nestedWorkflow.tests) {
4165
- const testFilePath = path4__default.resolve(path4__default.dirname(workflowPath), testRef.file);
4166
- const nestedTest = await loadTestDefinition(testFilePath);
4307
+ const testFilePath2 = path4__default.resolve(path4__default.dirname(workflowPath), testRef.file);
4308
+ const nestedTest = await loadTestDefinition(testFilePath2);
4167
4309
  if (nestedTest.variables) {
4168
4310
  for (const [key, value] of Object.entries(nestedTest.variables)) {
4169
4311
  const interpolated = interpolateVariables(value, context.variables);
@@ -4176,6 +4318,7 @@ async function runTestInWorkflow(test, page, context, options, _workflowDir, wor
4176
4318
  context,
4177
4319
  options,
4178
4320
  path4__default.dirname(workflowPath),
4321
+ testFilePath2,
4179
4322
  nestedWorkflow.config?.web?.baseUrl ?? workflowBaseUrl
4180
4323
  );
4181
4324
  results.push(...nestedResult.steps);
@@ -4459,7 +4602,7 @@ Starting workflow: ${workflow.name}`);
4459
4602
  console.log(` [DEBUG] - workflow.config?.web?.baseUrl: ${workflow.config?.web?.baseUrl ?? "(undefined)"}`);
4460
4603
  console.log(` [DEBUG] - options.baseUrl: ${options.baseUrl ?? "(undefined)"}`);
4461
4604
  }
4462
- const result = await runTestInWorkflow(test, page, executionContext, options, workflowDir, effectiveBaseUrl);
4605
+ const result = await runTestInWorkflow(test, page, executionContext, options, workflowDir, testFilePath, effectiveBaseUrl);
4463
4606
  const testResult = {
4464
4607
  id: testRef.id,
4465
4608
  file: testRef.file,
@@ -4686,8 +4829,14 @@ async function runWorkflow(workflow, workflowFilePath, options = {}) {
4686
4829
  }
4687
4830
  const allTestResults = [];
4688
4831
  let anyFailed = false;
4832
+ const cliStorageState = typeof options.storageState === "string" ? path4__default.isAbsolute(options.storageState) ? options.storageState : path4__default.resolve(process.cwd(), options.storageState) : options.storageState;
4833
+ const storageState = cliStorageState ?? resolveStorageStatePath(
4834
+ workflow.config?.web?.storageState,
4835
+ workflowDir
4836
+ );
4689
4837
  let browserContext = await browser.newContext({
4690
- viewport: viewportSizes[0].viewport
4838
+ viewport: viewportSizes[0].viewport,
4839
+ ...storageState ? { storageState } : {}
4691
4840
  });
4692
4841
  let page = await browserContext.newPage();
4693
4842
  page.setDefaultTimeout(3e4);
@@ -4713,7 +4862,10 @@ async function runWorkflow(workflow, workflowFilePath, options = {}) {
4713
4862
  const { size, viewport } = viewportSizes[sizeIndex];
4714
4863
  if (sizeIndex > 0) {
4715
4864
  await browserContext.close();
4716
- browserContext = await browser.newContext({ viewport });
4865
+ browserContext = await browser.newContext({
4866
+ viewport,
4867
+ ...storageState ? { storageState } : {}
4868
+ });
4717
4869
  page = await browserContext.newPage();
4718
4870
  page.setDefaultTimeout(3e4);
4719
4871
  if (workflow.config?.appwrite) {
@@ -4870,6 +5022,6 @@ Collected ${serverResources.length} server-tracked resources`);
4870
5022
  // src/executors/web/index.ts
4871
5023
  init_esm_shims();
4872
5024
 
4873
- export { createAIProvider, createTestContext, generateFillerText, generateRandomEmail, generateRandomPhone, generateRandomPhoto, generateRandomUsername, getBrowserLaunchOptions, initFileTracking, interpolateVariables, mergeFileTrackedResources, parseViewportSize, runWebTest, runWorkflow, runWorkflowWithContext, setupAppwriteTracking, startTrackingServer, webServerManager };
4874
- //# sourceMappingURL=chunk-J7357E4Q.js.map
4875
- //# sourceMappingURL=chunk-J7357E4Q.js.map
5025
+ export { createAIProvider, createTestContext, generateFillerText, generateRandomEmail, generateRandomPhone, generateRandomPhoto, generateRandomUsername, getBrowserLaunchOptions, initFileTracking, interpolateVariables, mergeFileTrackedResources, parseViewportSize, resolveStorageStatePath, runWebTest, runWorkflow, runWorkflowWithContext, setupAppwriteTracking, startTrackingServer, webServerManager };
5026
+ //# sourceMappingURL=chunk-7OBDMLJ3.js.map
5027
+ //# sourceMappingURL=chunk-7OBDMLJ3.js.map