@diagonal-hq/cli 0.21.3 → 0.22.0

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.
package/dist/cli.mjs CHANGED
@@ -324372,7 +324372,7 @@ function setupResultType(setupModule) {
324372
324372
  return `(typeof import('${setupModule}').default extends import('@diagonal/workflow').WorkflowDefinition<any, infer O> ? ${output} : never)`;
324373
324373
  }
324374
324374
  function testFunctionHeader(hasSetup) {
324375
- return `type Sdk = Omit<DiagonalTestSdk, 'setup'> & { readonly setup: ${setupResultType(hasSetup ? "./setup" : null)} }; export async function diagonalTest(Sdk: Sdk) {`;
324375
+ return `type Sdk = Omit<DiagonalTestSdk, 'setup'>; export async function diagonalTest(Sdk: Sdk, ctx: ${setupResultType(hasSetup ? "./setup" : null)}) {`;
324376
324376
  }
324377
324377
  function checkTestFunctions({ tests, appModules, resourceNames: resourceNames2, workspaceDeclarations, files }) {
324378
324378
  const resources = resourceNames2.map((name) => ` readonly ${JSON.stringify(name)}: string;
@@ -324497,7 +324497,7 @@ var TEST_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,99}$/;
324497
324497
  var SUITE_PROPERTIES = /* @__PURE__ */ new Set(["uid", "name", "description"]);
324498
324498
  var TEST_PROPERTIES = /* @__PURE__ */ new Set(["name", "description", "enabled", "timeoutSeconds"]);
324499
324499
  var HANDLERS = ["setup", "test", "assert"];
324500
- var TEST_FIXTURES = /* @__PURE__ */ new Set(["page", "context", "request", "browser", "expect", "Sdk"]);
324500
+ var TEST_FIXTURES = /* @__PURE__ */ new Set(["page", "context", "request", "browser", "expect", "Sdk", "ctx"]);
324501
324501
  var PHASE_DEFINE = "__diagonalTestPhase";
324502
324502
  var PHASE_IMPORT = `import { defineWorkflow as ${PHASE_DEFINE} } from '@diagonal-hq/workflows/test'; `;
324503
324503
  var SETUP_TYPE_MODULE = "setup.ts";
@@ -324627,10 +324627,15 @@ function readHandlers(node, report) {
324627
324627
  report(property, `"${key}" cannot be a generator`);
324628
324628
  continue;
324629
324629
  }
324630
+ if (key !== "test" && fn.params.length > 1) {
324631
+ valid = false;
324632
+ report(fn.params[1], `"${key}" takes one argument: async ${key}(ctx) { ... }`);
324633
+ continue;
324634
+ }
324630
324635
  handlers[key] = { node: property, fn, method: property.type === "ObjectMethod" };
324631
324636
  }
324632
324637
  if (valid && handlers.test === void 0) {
324633
- report(node, 'The test has no "test" function. Add async test({ page, expect, Sdk }) { ... }');
324638
+ report(node, 'The test has no "test" function. Add async test({ page, expect, ctx }) { ... }');
324634
324639
  return null;
324635
324640
  }
324636
324641
  return valid ? handlers : null;
@@ -324687,7 +324692,7 @@ function readTestFunction(handler, source, ast, enabled2, report) {
324687
324692
  report(node, message);
324688
324693
  };
324689
324694
  if (fn.params.length > 1) {
324690
- problem2(fn.params[1], "The test function takes one argument: { page, context, request, browser, expect, Sdk }");
324695
+ problem2(fn.params[1], "The test function takes one argument: { page, context, request, browser, expect, Sdk, ctx }");
324691
324696
  }
324692
324697
  const fixtures = fn.params[0];
324693
324698
  if (fixtures !== void 0 && fixtures.type !== "ObjectPattern") {
@@ -324722,7 +324727,7 @@ function readTestFunction(handler, source, ast, enabled2, report) {
324722
324727
  reported.add(reference.name);
324723
324728
  problem2(
324724
324729
  reference,
324725
- `The test function runs in the browser runner and cannot use "${reference.name}" from this file. Return the value from setup and read it as Sdk.setup`
324730
+ `The test function runs in the browser runner and cannot use "${reference.name}" from this file. Return the value from setup and read it as ctx.<name>`
324726
324731
  );
324727
324732
  }
324728
324733
  });
package/dist/index.d.ts CHANGED
@@ -1252,14 +1252,12 @@ type TestSignInTarget =
1252
1252
  | ({ id: string } & Record<string, unknown>)
1253
1253
  | { resource: string; id: string };
1254
1254
 
1255
- /** `Sdk` in the test function. `setup` is the object that the setup function returned. */
1256
- export type TestSdk<S> = {
1255
+ /** `Sdk` in the test function. */
1256
+ export type TestSdk = {
1257
1257
  /** The workspace that the run acts on. */
1258
1258
  readonly workspace: { readonly id: string; readonly name: string; readonly baseUrl: string };
1259
1259
  /** An absolute URL on the run's workspace. */
1260
1260
  url(path?: string): string;
1261
- /** The object that setup returned, or `{}` without a setup function. */
1262
- readonly setup: S;
1263
1261
  /** Signs `page` in as a record that setup returned, or as `{ resource, id }`, then opens `redirectTo` (default `/`). */
1264
1262
  loginAs(record: TestSignInTarget, options?: { redirectTo?: string }): Promise<void>;
1265
1263
  /** Opens a second browser signed in as another record and returns its page. */
@@ -1293,39 +1291,40 @@ export type TestSdk<S> = {
1293
1291
  };
1294
1292
 
1295
1293
  /** The values that the runner gives the test function. */
1296
- export type TestFixtures<S> = {
1294
+ export type TestFixtures<C> = {
1297
1295
  page: import('@playwright/test').Page;
1298
1296
  context: import('@playwright/test').BrowserContext;
1299
1297
  request: import('@playwright/test').APIRequestContext;
1300
1298
  browser: import('@playwright/test').Browser;
1301
1299
  expect: import('@playwright/test').Expect;
1302
- Sdk: TestSdk<S>;
1300
+ Sdk: TestSdk;
1301
+ /** The object that setup returned, or `{}` without a setup function. A change to it reaches assert. */
1302
+ ctx: C;
1303
1303
  };
1304
1304
 
1305
1305
  /**
1306
- * The functions of a test. `setup` and `assert` are workflow handlers without a config: the build
1307
- * compiles each one as `defineWorkflow(handler)` of `@diagonal-hq/workflows/test`, and the run
1308
- * executes it once in the test workspace as an embedded script. It runs as the acting account,
1309
- * with no trigger, no `runAs`, and no `input` schema, so its input is fixed. To act as another
1310
- * identity, call `workflow.run` with a workflow that sets Run As. `test` runs in the browser runner
1311
- * as the body of a Playwright test, so it can use only its fixtures: no import or helper of its file.
1306
+ * The functions of a test. They share one ctx: setup gets it empty, and the object that setup
1307
+ * returns is the ctx of the test function and of assert. A change that the test function makes to
1308
+ * ctx reaches assert. The run sends ctx between them as JSON.
1309
+ *
1310
+ * `setup` and `assert` run once in the test workspace as embedded scripts, as the acting account,
1311
+ * with the `test` script profile. To act as another identity, call `workflow.run` with a workflow
1312
+ * that sets Run As. `test` runs in the browser runner as the body of a Playwright test, so it can
1313
+ * use only its fixtures: no import or helper of its file.
1312
1314
  */
1313
- export type TestHandlers<S> = {
1314
- /** Creates the records that the test needs and returns them. Its input is `{}`. */
1315
- setup?: (input: Record<string, never>, ctx: WorkflowContext) => S | Promise<S>;
1316
- test: (fixtures: TestFixtures<Awaited<S>>) => Promise<void>;
1317
- /**
1318
- * Reads the records after the test, and calls `fail(...)` when a value is wrong. Its input is
1319
- * the object that `setup` returned, or `{}` without a setup.
1320
- */
1321
- assert?: (setup: Awaited<S>, ctx: WorkflowContext) => void | Promise<void>;
1315
+ export type TestHandlers<C> = {
1316
+ /** Creates the records that the test needs and returns them. They become ctx. */
1317
+ setup?: (ctx: Record<string, unknown>) => C | Promise<C>;
1318
+ test: (fixtures: TestFixtures<Awaited<C>>) => Promise<void>;
1319
+ /** Reads the records after the test, and calls `fail(...)` when a value is wrong. */
1320
+ assert?: (ctx: Awaited<C>) => void | Promise<void>;
1322
1321
  };
1323
1322
 
1324
1323
  /**
1325
1324
  * The default export of `tests/<suite>/<key>.ts`, one E2E test of the suite in the folder. The
1326
1325
  * file name is the test key.
1327
1326
  */
1328
- export declare function defineTest<S = Record<string, never>>(
1327
+ export declare function defineTest<C = {}>(
1329
1328
  config: TestConfig,
1330
- handlers: TestHandlers<S>
1331
- ): { readonly config: TestConfig } & TestHandlers<S>;
1329
+ handlers: TestHandlers<C>
1330
+ ): { readonly config: TestConfig } & TestHandlers<C>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.21.3",
3
+ "version": "0.22.0",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {