@gitlab/frontend-tests 0.1.2 → 0.1.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.
package/README.md CHANGED
@@ -93,11 +93,12 @@ The `publish` job runs only on git tags that match `v<digits>`, for example `v0.
93
93
 
94
94
  To release:
95
95
 
96
- 1. Bump `version` in `package.json` in a merge request.
97
- 2. Merge the merge request.
98
- 3. Create and push a tag `vX.Y.Z` on `main`. The tag must match the version.
96
+ 1. Merge your changes to `main`.
97
+ 2. Create and push a tag `vX.Y.Z` on `main`.
99
98
 
100
- The tag pipeline publishes the package.
99
+ The tag pipeline publishes the package. The `publish` job sets `version` in `package.json` from the tag before publishing, so no version-bump merge request is needed. Releases do not update the committed `version`; the tag is authoritative.
100
+
101
+ Tags must be `vMAJOR.MINOR.PATCH`, with an optional prerelease suffix (for example `v1.0.0-rc.1`), or the `publish` job fails. Stable versions are published with the `latest` dist-tag; prerelease versions (those containing `-`) use the `next` dist-tag so they do not replace the stable release for consumers installing without a version or tag.
101
102
 
102
103
  ### One-time setup
103
104
 
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var server = require('./server-hzT7AwDi.cjs');
3
+ var server = require('./server-erJjAkSH.cjs');
4
4
  require('msw/node');
5
5
  require('msw');
6
6
  require('node:fs');
@@ -26,6 +26,7 @@ exports.getVariant = server.getVariant;
26
26
  exports.isValidGraphqlFixture = server.isValidGraphqlFixture;
27
27
  exports.lastRequestVariables = server.lastRequestVariables;
28
28
  exports.loadFixturesMap = server.loadFixturesMap;
29
+ exports.mapStaticOperationHandlers = server.mapStaticOperationHandlers;
29
30
  exports.matchFixture = server.matchFixture;
30
31
  exports.missingOperations = server.missingOperations;
31
32
  exports.normaliseGraphqlFixture = server.normaliseGraphqlFixture;
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-C2Drh977.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 mapStaticOperationHandlers, t as matchFixture, u as missingOperations, v as normaliseGraphqlFixture, w as resetAllVariants, x as resetCapturedRequests, y as setFixtureData, z as setFixtureErrors, A as setFixtureItemsCount, B as setQueryVariant, C as snapshotRequests } from './server-BOfJGLQi.js';
2
2
  import 'msw/node';
3
3
  import 'msw';
4
4
  import 'node:fs';
@@ -1,10 +1,24 @@
1
1
  import { type RequestHandler } from 'msw';
2
2
  import type { FeatureHandler, RestEndpoint } from './types.cjs';
3
+ /**
4
+ * Turns a fixtures map into the static handlers a feature's `OPERATION_HANDLERS`
5
+ * starts from: one per operation, serving the active variant when a spec has set
6
+ * one and the recorded fixture otherwise. Spread the result first, so handlers
7
+ * that read request variables can override the static entry for their operation.
8
+ *
9
+ * @example
10
+ * const OPERATION_HANDLERS = {
11
+ * ...mapStaticOperationHandlers(fixtures),
12
+ * getWorkItemsFull: ({ variables }) => listResponse(variables),
13
+ * };
14
+ */
15
+ export declare function mapStaticOperationHandlers<Fixture>(fixtures: Record<string, Fixture>): Record<string, () => Fixture>;
3
16
  /**
4
17
  * Assembles the MSW handlers for a test run from the feature handlers and REST
5
18
  * endpoints a consumer registers. Every answered request is captured for
6
- * assertions. A GraphQL operation nobody answers is recorded as missing and fails
7
- * with a 400, and an unknown REST URL is logged and fails the same way, so a gap in
8
- * the handlers surfaces as a loud test failure instead of a silent empty response.
19
+ * assertions. A GraphQL operation or REST GET that nothing answers gets a 400 and
20
+ * is recorded in `missingOperations`. Consumers report that set after the suite,
21
+ * so a missing handler fails the run even when the app swallows the 400. Other
22
+ * REST methods with no endpoint fall through to the consumer's `onUnhandledRequest`.
9
23
  */
10
24
  export declare function buildHandlers(allFeatureHandlers: FeatureHandler[], allRestEndpoints: RestEndpoint[]): RequestHandler[];
@@ -1,10 +1,24 @@
1
1
  import { type RequestHandler } from 'msw';
2
2
  import type { FeatureHandler, RestEndpoint } from './types.js';
3
+ /**
4
+ * Turns a fixtures map into the static handlers a feature's `OPERATION_HANDLERS`
5
+ * starts from: one per operation, serving the active variant when a spec has set
6
+ * one and the recorded fixture otherwise. Spread the result first, so handlers
7
+ * that read request variables can override the static entry for their operation.
8
+ *
9
+ * @example
10
+ * const OPERATION_HANDLERS = {
11
+ * ...mapStaticOperationHandlers(fixtures),
12
+ * getWorkItemsFull: ({ variables }) => listResponse(variables),
13
+ * };
14
+ */
15
+ export declare function mapStaticOperationHandlers<Fixture>(fixtures: Record<string, Fixture>): Record<string, () => Fixture>;
3
16
  /**
4
17
  * Assembles the MSW handlers for a test run from the feature handlers and REST
5
18
  * endpoints a consumer registers. Every answered request is captured for
6
- * assertions. A GraphQL operation nobody answers is recorded as missing and fails
7
- * with a 400, and an unknown REST URL is logged and fails the same way, so a gap in
8
- * the handlers surfaces as a loud test failure instead of a silent empty response.
19
+ * assertions. A GraphQL operation or REST GET that nothing answers gets a 400 and
20
+ * is recorded in `missingOperations`. Consumers report that set after the suite,
21
+ * so a missing handler fails the run even when the app swallows the 400. Other
22
+ * REST methods with no endpoint fall through to the consumer's `onUnhandledRequest`.
9
23
  */
10
24
  export declare function buildHandlers(allFeatureHandlers: FeatureHandler[], allRestEndpoints: RestEndpoint[]): RequestHandler[];
@@ -1,7 +1,8 @@
1
1
  import type { CapturedRequest, GraphqlVariables, RequestCounts } from './types.cjs';
2
2
  /**
3
- * Every GraphQL operation a test triggered that no handler answered, collected across
4
- * the run so a new suite shows all the handlers it still needs in one go.
3
+ * Every GraphQL operation ("opname") and REST GET ("GET xyz") a test triggered
4
+ * that no handler answered, collected across the run so a new suite shows all
5
+ * the handlers it still needs in one go.
5
6
  */
6
7
  export declare const missingOperations: Set<string>;
7
8
  /** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
@@ -1,7 +1,8 @@
1
1
  import type { CapturedRequest, GraphqlVariables, RequestCounts } from './types.js';
2
2
  /**
3
- * Every GraphQL operation a test triggered that no handler answered, collected across
4
- * the run so a new suite shows all the handlers it still needs in one go.
3
+ * Every GraphQL operation ("opname") and REST GET ("GET xyz") a test triggered
4
+ * that no handler answered, collected across the run so a new suite shows all
5
+ * the handlers it still needs in one go.
5
6
  */
6
7
  export declare const missingOperations: Set<string>;
7
8
  /** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var server = require('./server-hzT7AwDi.cjs');
3
+ var server = require('./server-erJjAkSH.cjs');
4
4
  require('msw/node');
5
5
  require('msw');
6
6
  require('node:fs');
@@ -26,6 +26,7 @@ exports.getVariant = server.getVariant;
26
26
  exports.isValidGraphqlFixture = server.isValidGraphqlFixture;
27
27
  exports.lastRequestVariables = server.lastRequestVariables;
28
28
  exports.loadFixturesMap = server.loadFixturesMap;
29
+ exports.mapStaticOperationHandlers = server.mapStaticOperationHandlers;
29
30
  exports.matchFixture = server.matchFixture;
30
31
  exports.missingOperations = server.missingOperations;
31
32
  exports.normaliseGraphqlFixture = server.normaliseGraphqlFixture;
@@ -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-C2Drh977.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 mapStaticOperationHandlers, t as matchFixture, u as missingOperations, v as normaliseGraphqlFixture, w as resetAllVariants, x as resetCapturedRequests, y as setFixtureData, z as setFixtureErrors, A as setFixtureItemsCount, B as setQueryVariant, C as snapshotRequests } from './server-BOfJGLQi.js';
2
2
  import 'msw/node';
3
3
  import 'msw';
4
4
  import 'node:fs';
@@ -3277,8 +3277,9 @@ function set(object, path, value) {
3277
3277
  }
3278
3278
 
3279
3279
  /**
3280
- * Every GraphQL operation a test triggered that no handler answered, collected across
3281
- * the run so a new suite shows all the handlers it still needs in one go.
3280
+ * Every GraphQL operation ("opname") and REST GET ("GET xyz") a test triggered
3281
+ * that no handler answered, collected across the run so a new suite shows all
3282
+ * the handlers it still needs in one go.
3282
3283
  */
3283
3284
  const missingOperations = new Set();
3284
3285
  /** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
@@ -3927,12 +3928,31 @@ function dumpRegistry() {
3927
3928
  return out;
3928
3929
  }
3929
3930
 
3931
+ /**
3932
+ * Turns a fixtures map into the static handlers a feature's `OPERATION_HANDLERS`
3933
+ * starts from: one per operation, serving the active variant when a spec has set
3934
+ * one and the recorded fixture otherwise. Spread the result first, so handlers
3935
+ * that read request variables can override the static entry for their operation.
3936
+ *
3937
+ * @example
3938
+ * const OPERATION_HANDLERS = {
3939
+ * ...mapStaticOperationHandlers(fixtures),
3940
+ * getWorkItemsFull: ({ variables }) => listResponse(variables),
3941
+ * };
3942
+ */
3943
+ function mapStaticOperationHandlers(fixtures) {
3944
+ return Object.fromEntries(Object.entries(fixtures).map(([operationName, fixture]) => [
3945
+ operationName,
3946
+ () => getActiveVariant(operationName) ?? fixture,
3947
+ ]));
3948
+ }
3930
3949
  /**
3931
3950
  * Assembles the MSW handlers for a test run from the feature handlers and REST
3932
3951
  * endpoints a consumer registers. Every answered request is captured for
3933
- * assertions. A GraphQL operation nobody answers is recorded as missing and fails
3934
- * with a 400, and an unknown REST URL is logged and fails the same way, so a gap in
3935
- * the handlers surfaces as a loud test failure instead of a silent empty response.
3952
+ * assertions. A GraphQL operation or REST GET that nothing answers gets a 400 and
3953
+ * is recorded in `missingOperations`. Consumers report that set after the suite,
3954
+ * so a missing handler fails the run even when the app swallows the 400. Other
3955
+ * REST methods with no endpoint fall through to the consumer's `onUnhandledRequest`.
3936
3956
  */
3937
3957
  function buildHandlers(allFeatureHandlers, allRestEndpoints) {
3938
3958
  const restEndpointsHandlers = allRestEndpoints.map((endpoint) => http[endpoint.method](endpoint.path, ({ request }) => {
@@ -3957,8 +3977,7 @@ function buildHandlers(allFeatureHandlers, allRestEndpoints) {
3957
3977
  }),
3958
3978
  ...restEndpointsHandlers,
3959
3979
  http.get('*', ({ request }) => {
3960
- // eslint-disable-next-line no-console
3961
- console.log(`Unhandled url for REST endpoint: ${request.url}`);
3980
+ captureMissingOperation(`GET ${new URL(request.url).pathname}`);
3962
3981
  return new HttpResponse(null, { status: 400 });
3963
3982
  }),
3964
3983
  ];
@@ -3967,4 +3986,4 @@ function buildHandlers(allFeatureHandlers, allRestEndpoints) {
3967
3986
  /** Builds the MSW node server for a test run from the consumer's feature handlers and REST endpoints. */
3968
3987
  const createServer = (featureHandlers, restEndpoints) => setupServer(...buildHandlers(featureHandlers, restEndpoints));
3969
3988
 
3970
- export { setQueryVariant as A, snapshotRequests as B, activateVariant as a, baseMetadata as b, buildHandlers as c, captureMissingOperation as d, captureRequest as e, capturedRequests as f, clearMissingOperations as g, createFixturePaginator as h, createServer as i, defineFixtureVariants as j, defineRestFixtureVariants as k, dumpRegistry as l, expectGraphQLCalls as m, getActiveVariant as n, getVariant as o, isValidGraphqlFixture as p, lastRequestVariables as q, loadFixturesMap as r, matchFixture as s, missingOperations as t, normaliseGraphqlFixture as u, resetAllVariants as v, resetCapturedRequests as w, setFixtureData as x, setFixtureErrors as y, setFixtureItemsCount as z };
3989
+ export { setFixtureItemsCount as A, setQueryVariant as B, snapshotRequests as C, activateVariant as a, baseMetadata as b, buildHandlers as c, captureMissingOperation as d, captureRequest as e, capturedRequests as f, clearMissingOperations as g, createFixturePaginator as h, createServer as i, defineFixtureVariants as j, defineRestFixtureVariants as k, dumpRegistry as l, expectGraphQLCalls as m, getActiveVariant as n, getVariant as o, isValidGraphqlFixture as p, lastRequestVariables as q, loadFixturesMap as r, mapStaticOperationHandlers as s, matchFixture as t, missingOperations as u, normaliseGraphqlFixture as v, resetAllVariants as w, resetCapturedRequests as x, setFixtureData as y, setFixtureErrors as z };
@@ -3279,8 +3279,9 @@ function set(object, path, value) {
3279
3279
  }
3280
3280
 
3281
3281
  /**
3282
- * Every GraphQL operation a test triggered that no handler answered, collected across
3283
- * the run so a new suite shows all the handlers it still needs in one go.
3282
+ * Every GraphQL operation ("opname") and REST GET ("GET xyz") a test triggered
3283
+ * that no handler answered, collected across the run so a new suite shows all
3284
+ * the handlers it still needs in one go.
3284
3285
  */
3285
3286
  const missingOperations = new Set();
3286
3287
  /** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
@@ -3929,12 +3930,31 @@ function dumpRegistry() {
3929
3930
  return out;
3930
3931
  }
3931
3932
 
3933
+ /**
3934
+ * Turns a fixtures map into the static handlers a feature's `OPERATION_HANDLERS`
3935
+ * starts from: one per operation, serving the active variant when a spec has set
3936
+ * one and the recorded fixture otherwise. Spread the result first, so handlers
3937
+ * that read request variables can override the static entry for their operation.
3938
+ *
3939
+ * @example
3940
+ * const OPERATION_HANDLERS = {
3941
+ * ...mapStaticOperationHandlers(fixtures),
3942
+ * getWorkItemsFull: ({ variables }) => listResponse(variables),
3943
+ * };
3944
+ */
3945
+ function mapStaticOperationHandlers(fixtures) {
3946
+ return Object.fromEntries(Object.entries(fixtures).map(([operationName, fixture]) => [
3947
+ operationName,
3948
+ () => getActiveVariant(operationName) ?? fixture,
3949
+ ]));
3950
+ }
3932
3951
  /**
3933
3952
  * Assembles the MSW handlers for a test run from the feature handlers and REST
3934
3953
  * endpoints a consumer registers. Every answered request is captured for
3935
- * assertions. A GraphQL operation nobody answers is recorded as missing and fails
3936
- * with a 400, and an unknown REST URL is logged and fails the same way, so a gap in
3937
- * the handlers surfaces as a loud test failure instead of a silent empty response.
3954
+ * assertions. A GraphQL operation or REST GET that nothing answers gets a 400 and
3955
+ * is recorded in `missingOperations`. Consumers report that set after the suite,
3956
+ * so a missing handler fails the run even when the app swallows the 400. Other
3957
+ * REST methods with no endpoint fall through to the consumer's `onUnhandledRequest`.
3938
3958
  */
3939
3959
  function buildHandlers(allFeatureHandlers, allRestEndpoints) {
3940
3960
  const restEndpointsHandlers = allRestEndpoints.map((endpoint) => msw.http[endpoint.method](endpoint.path, ({ request }) => {
@@ -3959,8 +3979,7 @@ function buildHandlers(allFeatureHandlers, allRestEndpoints) {
3959
3979
  }),
3960
3980
  ...restEndpointsHandlers,
3961
3981
  msw.http.get('*', ({ request }) => {
3962
- // eslint-disable-next-line no-console
3963
- console.log(`Unhandled url for REST endpoint: ${request.url}`);
3982
+ captureMissingOperation(`GET ${new URL(request.url).pathname}`);
3964
3983
  return new msw.HttpResponse(null, { status: 400 });
3965
3984
  }),
3966
3985
  ];
@@ -3987,6 +4006,7 @@ exports.getVariant = getVariant;
3987
4006
  exports.isValidGraphqlFixture = isValidGraphqlFixture;
3988
4007
  exports.lastRequestVariables = lastRequestVariables;
3989
4008
  exports.loadFixturesMap = loadFixturesMap;
4009
+ exports.mapStaticOperationHandlers = mapStaticOperationHandlers;
3990
4010
  exports.matchFixture = matchFixture;
3991
4011
  exports.missingOperations = missingOperations;
3992
4012
  exports.normaliseGraphqlFixture = normaliseGraphqlFixture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/frontend-tests",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Reusable test infrastructure for GitLab frontend packages",
5
5
  "license": "MIT",
6
6
  "type": "module",