@diagonal-hq/cli 0.31.0 → 0.32.1

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
@@ -289115,6 +289115,13 @@ function packageName(specifier) {
289115
289115
  const parts = specifier.split("/");
289116
289116
  return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
289117
289117
  }
289118
+ var TEST_SOURCE_PREFIX = "tests/";
289119
+ function testSourceImportMessage(from, target) {
289120
+ if (!target.startsWith(TEST_SOURCE_PREFIX) || from.startsWith(TEST_SOURCE_PREFIX)) {
289121
+ return null;
289122
+ }
289123
+ return `${from} imports ${target}. Only a file of tests/ can import a file of tests/. Move the shared code to another folder, such as lib/`;
289124
+ }
289118
289125
  function resolveLocalSpecifier(root, from, specifier) {
289119
289126
  return localCandidates(from, specifier).find((candidate) => isExactFile(join(root, candidate))) ?? null;
289120
289127
  }
@@ -313309,6 +313316,12 @@ function checkModuleImports(root, path, ast, packages) {
313309
313316
  blocksUnitBuild ||= importType === "app" && !found2.dynamic;
313310
313317
  continue;
313311
313318
  }
313319
+ const testSource = testSourceImportMessage(path, target);
313320
+ if (testSource !== null) {
313321
+ diagnostics.push(diagnosticAt(path, found2.node, testSource));
313322
+ blocksUnitBuild = true;
313323
+ continue;
313324
+ }
313312
313325
  if (GENERATED_IMPORT_KINDS.has(target)) {
313313
313326
  imports.push({
313314
313327
  specifier: found2.specifier,
@@ -313589,6 +313602,10 @@ function appImportsOf(root, path, ast, { ui = false } = {}) {
313589
313602
  statement2.source
313590
313603
  );
313591
313604
  }
313605
+ const testSource = testSourceImportMessage(path, target);
313606
+ if (testSource !== null) {
313607
+ throw new SourceError(testSource, statement2.source);
313608
+ }
313592
313609
  imports.push({ statement: statement2, specifier: statement2.source.value, path: target, from: path });
313593
313610
  }
313594
313611
  return imports;
@@ -313676,6 +313693,10 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
313676
313693
  statement2.source
313677
313694
  );
313678
313695
  }
313696
+ const testSource = testSourceImportMessage(path, target);
313697
+ if (testSource !== null) {
313698
+ throw new SourceError(testSource, statement2.source);
313699
+ }
313679
313700
  requires[specifier] = target;
313680
313701
  pending.push(target);
313681
313702
  }
@@ -319859,17 +319880,18 @@ function hasResolver(value) {
319859
319880
  }
319860
319881
  return isResolver(value) || Object.values(value).some(hasResolver);
319861
319882
  }
319862
- function tipTapText(content, oneLine) {
319883
+ function tipTapText(content, oneLine, inlineSeparator = null) {
319863
319884
  if (typeof content === "string") {
319864
319885
  return content;
319865
319886
  }
319866
319887
  const separator = oneLine ? "" : "\n\n";
319888
+ const inline = inlineSeparator ?? separator;
319867
319889
  const render = (node) => {
319868
319890
  if (!isPlainObject2(node)) {
319869
319891
  return "";
319870
319892
  }
319871
319893
  if (node.content !== void 0 && node.content !== null) {
319872
- return Array.isArray(node.content) ? node.content.map(render).join(separator) : "";
319894
+ return Array.isArray(node.content) ? node.content.map(render).join(inline) : "";
319873
319895
  }
319874
319896
  return typeof node.text === "string" ? node.text : "";
319875
319897
  };
@@ -321500,7 +321522,7 @@ var TEST_DEFINE = "defineTest";
321500
321522
  var TEST_FILE_PATTERN = /^tests\/[^/]+\/([^/]+)\.ts$/;
321501
321523
  var SPLIT_TEST_FILE_PATTERN = /\.(browser|setup|assert)$/;
321502
321524
  var TEST_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,99}$/;
321503
- var SUITE_PROPERTIES = /* @__PURE__ */ new Set(["uid", "name", "description"]);
321525
+ var SUITE_PROPERTIES = /* @__PURE__ */ new Set(["uid", "name", "description", "order"]);
321504
321526
  var TEST_PROPERTIES = /* @__PURE__ */ new Set(["name", "description", "enabled", "timeoutSeconds"]);
321505
321527
  var HANDLERS = ["setup", "test", "assert"];
321506
321528
  var TEST_FIXTURES = /* @__PURE__ */ new Set(["page", "context", "request", "browser", "expect", "Sdk", "ctx"]);
@@ -321605,7 +321627,50 @@ function readSuite(file2, report) {
321605
321627
  { allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename13(dirname8(file2.path)) },
321606
321628
  report
321607
321629
  );
321608
- return read2 === null ? null : { name: read2.name, description: read2.description };
321630
+ if (read2 === null) {
321631
+ return null;
321632
+ }
321633
+ const order = read2.value.order ?? null;
321634
+ if (order !== null && (!Array.isArray(order) || order.some((key) => typeof key !== "string" || !TEST_KEY_PATTERN.test(key)))) {
321635
+ read2.problem(read2.at("order"), '"order" must list test keys, the file names of the tests without .ts');
321636
+ return null;
321637
+ }
321638
+ if (order !== null && order.length > MAX_TESTS_PER_SUITE) {
321639
+ read2.problem(read2.at("order"), `"order" can list at most ${MAX_TESTS_PER_SUITE} tests`);
321640
+ return null;
321641
+ }
321642
+ const seen = /* @__PURE__ */ new Set();
321643
+ const repeated = order?.find((key) => seen.has(key) || !seen.add(key));
321644
+ if (repeated !== void 0) {
321645
+ read2.problem(read2.at("order"), `"order" lists the test "${repeated}" more than once`);
321646
+ return null;
321647
+ }
321648
+ return { name: read2.name, description: read2.description, order, value: read2.value };
321649
+ }
321650
+ function testSettings({ value, at, problem: problem2 }) {
321651
+ if (value.enabled !== void 0 && typeof value.enabled !== "boolean") {
321652
+ problem2(at("enabled"), '"enabled" must be true or false');
321653
+ return null;
321654
+ }
321655
+ const timeout = value.timeoutSeconds ?? null;
321656
+ if (timeout !== null && (!Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)) {
321657
+ problem2(at("timeoutSeconds"), `"timeoutSeconds" must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`);
321658
+ return null;
321659
+ }
321660
+ return { enabled: value.enabled ?? true, timeout_seconds: timeout };
321661
+ }
321662
+ function orderedTests(files, order, report) {
321663
+ const byName = files.toSorted((left, right) => left.path < right.path ? -1 : 1);
321664
+ if (order === null) {
321665
+ return byName;
321666
+ }
321667
+ const byKey = new Map(byName.map((file2) => [TEST_FILE_PATTERN.exec(file2.path)[1], file2]));
321668
+ const missing = order.filter((key) => !byKey.has(key));
321669
+ if (missing.length > 0) {
321670
+ report(null, `"order" lists ${missing.map((key) => `"${key}"`).join(", ")}, which this folder has no test file for`);
321671
+ }
321672
+ const listed = order.filter((key) => byKey.has(key)).map((key) => byKey.get(key));
321673
+ return [...listed, ...byName.filter((file2) => !listed.includes(file2))];
321609
321674
  }
321610
321675
  function readHandlers(node, report) {
321611
321676
  if (node.type !== "ObjectExpression") {
@@ -321862,17 +321927,11 @@ function buildTest(file2, context, diagnostics) {
321862
321927
  if (config === null || handlers === null) {
321863
321928
  return null;
321864
321929
  }
321865
- const { value, at, problem: problem2 } = config;
321866
- if (value.enabled !== void 0 && typeof value.enabled !== "boolean") {
321867
- problem2(at("enabled"), '"enabled" must be true or false');
321868
- return null;
321869
- }
321870
- const timeout = value.timeoutSeconds ?? null;
321871
- if (timeout !== null && (!Number.isInteger(timeout) || timeout < 1 || timeout > MAX_TIMEOUT_SECONDS)) {
321872
- problem2(at("timeoutSeconds"), `"timeoutSeconds" must be an integer from 1 to ${MAX_TIMEOUT_SECONDS}`);
321930
+ const settings = testSettings(config);
321931
+ if (settings === null) {
321873
321932
  return null;
321874
321933
  }
321875
- const enabled2 = value.enabled ?? true;
321934
+ const { enabled: enabled2, timeout_seconds: timeout } = settings;
321876
321935
  const code2 = readTestFunction(handlers.test, file2.source, file2.ast, enabled2, report);
321877
321936
  if (code2 === null) {
321878
321937
  return null;
@@ -321950,7 +322009,7 @@ function buildTestSuites({
321950
322009
  for (const suite of suites) {
321951
322010
  const directory = dirname8(suite.path);
321952
322011
  const read2 = readSuite(suite, report(suite.path));
321953
- const files = (testsByDirectory.get(directory) ?? []).toSorted((left, right) => left.path < right.path ? -1 : 1);
322012
+ const files = orderedTests(testsByDirectory.get(directory) ?? [], read2?.order ?? null, report(suite.path));
321954
322013
  if (files.length > MAX_TESTS_PER_SUITE) {
321955
322014
  report(suite.path)(null, `A suite can hold at most ${MAX_TESTS_PER_SUITE} tests`);
321956
322015
  continue;
package/dist/index.d.ts CHANGED
@@ -1236,6 +1236,11 @@ export type TestSuiteDefinition = UidOption & {
1236
1236
  name?: string;
1237
1237
  /** Up to 5,000 characters. */
1238
1238
  description?: string | null;
1239
+ /**
1240
+ * The run order of the tests, by test key: the file name without `.ts`. The tests that the list
1241
+ * leaves out run after the listed tests, in the order of their file names. Default: file name order.
1242
+ */
1243
+ order?: readonly string[];
1239
1244
  };
1240
1245
 
1241
1246
  export declare function defineTestSuite<const T extends TestSuiteDefinition>(suite: T): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.31.0",
3
+ "version": "0.32.1",
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": {