@gitlab/frontend-tests 0.1.0 → 0.1.2

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/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var server = require('./server-otsK-xxA.cjs');
3
+ var server = require('./server-hzT7AwDi.cjs');
4
4
  require('msw/node');
5
5
  require('msw');
6
6
  require('node:fs');
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as activateVariant, b as baseMetadata, c as buildHandlers, d as captureMissingOperation, e as captureRequest, f as capturedRequests, g as clearMissingOperations, h as createFixturePaginator, i as createServer, j as defineFixtureVariants, k as defineRestFixtureVariants, l as dumpRegistry, m as expectGraphQLCalls, n as getActiveVariant, o as getVariant, p as isValidGraphqlFixture, q as lastRequestVariables, r as loadFixturesMap, s as matchFixture, t as missingOperations, u as normaliseGraphqlFixture, v as resetAllVariants, w as resetCapturedRequests, x as setFixtureData, y as setFixtureErrors, z as setFixtureItemsCount, A as setQueryVariant, B as snapshotRequests } from './server-Ds9SYBSn.js';
1
+ export { a as activateVariant, b as baseMetadata, c as buildHandlers, d as captureMissingOperation, e as captureRequest, f as capturedRequests, g as clearMissingOperations, h as createFixturePaginator, i as createServer, j as defineFixtureVariants, k as defineRestFixtureVariants, l as dumpRegistry, m as expectGraphQLCalls, n as getActiveVariant, o as getVariant, p as isValidGraphqlFixture, q as lastRequestVariables, r as loadFixturesMap, s as matchFixture, t as missingOperations, u as normaliseGraphqlFixture, v as resetAllVariants, w as resetCapturedRequests, x as setFixtureData, y as setFixtureErrors, z as setFixtureItemsCount, A as setQueryVariant, B as snapshotRequests } from './server-C2Drh977.js';
2
2
  import 'msw/node';
3
3
  import 'msw';
4
4
  import 'node:fs';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var server = require('./server-otsK-xxA.cjs');
3
+ var server = require('./server-hzT7AwDi.cjs');
4
4
  require('msw/node');
5
5
  require('msw');
6
6
  require('node:fs');
@@ -1,4 +1,4 @@
1
- export { a as activateVariant, b as baseMetadata, c as buildHandlers, d as captureMissingOperation, e as captureRequest, f as capturedRequests, g as clearMissingOperations, h as createFixturePaginator, i as createServer, j as defineFixtureVariants, k as defineRestFixtureVariants, l as dumpRegistry, m as expectGraphQLCalls, n as getActiveVariant, o as getVariant, p as isValidGraphqlFixture, q as lastRequestVariables, r as loadFixturesMap, s as matchFixture, t as missingOperations, u as normaliseGraphqlFixture, v as resetAllVariants, w as resetCapturedRequests, x as setFixtureData, y as setFixtureErrors, z as setFixtureItemsCount, A as setQueryVariant, B as snapshotRequests } from './server-Ds9SYBSn.js';
1
+ export { a as activateVariant, b as baseMetadata, c as buildHandlers, d as captureMissingOperation, e as captureRequest, f as capturedRequests, g as clearMissingOperations, h as createFixturePaginator, i as createServer, j as defineFixtureVariants, k as defineRestFixtureVariants, l as dumpRegistry, m as expectGraphQLCalls, n as getActiveVariant, o as getVariant, p as isValidGraphqlFixture, q as lastRequestVariables, r as loadFixturesMap, s as matchFixture, t as missingOperations, u as normaliseGraphqlFixture, v as resetAllVariants, w as resetCapturedRequests, x as setFixtureData, y as setFixtureErrors, z as setFixtureItemsCount, A as setQueryVariant, B as snapshotRequests } from './server-C2Drh977.js';
2
2
  import 'msw/node';
3
3
  import 'msw';
4
4
  import 'node:fs';
@@ -3491,11 +3491,21 @@ const DEFAULT_VARIABLE_NAMES = {
3491
3491
  };
3492
3492
  function splitGraphqlId(id) {
3493
3493
  const match = String(id).match(/^(.*\/)(\d+)$/);
3494
- if (!match) {
3495
- throw new Error(`Cannot synthesize a new id from "${id}": expected a "prefix/number" format`);
3494
+ return match ? { prefix: match[1], number: Number(match[2]) } : null;
3495
+ }
3496
+ // Opaque ids (e.g. a finding `uuid`) have no number to count up from, so they get a suffix.
3497
+ function idSynthesizer(ids) {
3498
+ const parsed = ids.map(splitGraphqlId);
3499
+ if (parsed.some((entry) => entry === null)) {
3500
+ const templateId = ids[ids.length - 1];
3501
+ return (index) => `${templateId}-${index + 1}`;
3496
3502
  }
3497
- const [, prefix, numericPart] = match;
3498
- return { prefix, number: Number(numericPart) };
3503
+ const numeric = parsed;
3504
+ const { prefix } = numeric[numeric.length - 1];
3505
+ // Recorded lists are often sorted DESC, so count up from the highest id rather than
3506
+ // the last one, or the new ids collide with recorded nodes.
3507
+ const highestId = Math.max(...numeric.map(({ number }) => number));
3508
+ return (index) => `${prefix}${highestId + index + 1}`;
3499
3509
  }
3500
3510
  // A connection lists its items as `nodes`, as Relay-style `edges` wrapping each node, or both.
3501
3511
  const ITEM_LISTS = [
@@ -3513,14 +3523,11 @@ function resizeItems(items, itemCount, nodeOf) {
3513
3523
  return items.slice(0, itemCount);
3514
3524
  }
3515
3525
  const template = items[items.length - 1];
3516
- const { prefix } = splitGraphqlId(nodeOf(template).id);
3517
- // Recorded lists are often sorted DESC, so count up from the highest id rather than
3518
- // the last one, or the new ids collide with recorded nodes.
3519
- const highestId = Math.max(...items.map((item) => splitGraphqlId(nodeOf(item).id).number));
3526
+ const nextId = idSynthesizer(items.map((item) => nodeOf(item).id));
3520
3527
  const filled = Array.from({ length: itemCount - items.length }, (_, index) => {
3521
3528
  const clone = cloneDeep(template);
3522
3529
  const node = nodeOf(clone);
3523
- node.id = `${prefix}${highestId + index + 1}`;
3530
+ node.id = nextId(index);
3524
3531
  return clone;
3525
3532
  });
3526
3533
  return [...items, ...filled];
@@ -3493,11 +3493,21 @@ const DEFAULT_VARIABLE_NAMES = {
3493
3493
  };
3494
3494
  function splitGraphqlId(id) {
3495
3495
  const match = String(id).match(/^(.*\/)(\d+)$/);
3496
- if (!match) {
3497
- throw new Error(`Cannot synthesize a new id from "${id}": expected a "prefix/number" format`);
3496
+ return match ? { prefix: match[1], number: Number(match[2]) } : null;
3497
+ }
3498
+ // Opaque ids (e.g. a finding `uuid`) have no number to count up from, so they get a suffix.
3499
+ function idSynthesizer(ids) {
3500
+ const parsed = ids.map(splitGraphqlId);
3501
+ if (parsed.some((entry) => entry === null)) {
3502
+ const templateId = ids[ids.length - 1];
3503
+ return (index) => `${templateId}-${index + 1}`;
3498
3504
  }
3499
- const [, prefix, numericPart] = match;
3500
- return { prefix, number: Number(numericPart) };
3505
+ const numeric = parsed;
3506
+ const { prefix } = numeric[numeric.length - 1];
3507
+ // Recorded lists are often sorted DESC, so count up from the highest id rather than
3508
+ // the last one, or the new ids collide with recorded nodes.
3509
+ const highestId = Math.max(...numeric.map(({ number }) => number));
3510
+ return (index) => `${prefix}${highestId + index + 1}`;
3501
3511
  }
3502
3512
  // A connection lists its items as `nodes`, as Relay-style `edges` wrapping each node, or both.
3503
3513
  const ITEM_LISTS = [
@@ -3515,14 +3525,11 @@ function resizeItems(items, itemCount, nodeOf) {
3515
3525
  return items.slice(0, itemCount);
3516
3526
  }
3517
3527
  const template = items[items.length - 1];
3518
- const { prefix } = splitGraphqlId(nodeOf(template).id);
3519
- // Recorded lists are often sorted DESC, so count up from the highest id rather than
3520
- // the last one, or the new ids collide with recorded nodes.
3521
- const highestId = Math.max(...items.map((item) => splitGraphqlId(nodeOf(item).id).number));
3528
+ const nextId = idSynthesizer(items.map((item) => nodeOf(item).id));
3522
3529
  const filled = Array.from({ length: itemCount - items.length }, (_, index) => {
3523
3530
  const clone = cloneDeep(template);
3524
3531
  const node = nodeOf(clone);
3525
- node.id = `${prefix}${highestId + index + 1}`;
3532
+ node.id = nextId(index);
3526
3533
  return clone;
3527
3534
  });
3528
3535
  return [...items, ...filled];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/frontend-tests",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Reusable test infrastructure for GitLab frontend packages",
5
5
  "license": "MIT",
6
6
  "type": "module",