@cedarjs/testing 7.0.0-canary.2985 → 7.0.0-canary.2991

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.
Files changed (65) hide show
  1. package/package.json +21 -52
  2. package/dist/cjs/api/apiFunction.d.ts +0 -37
  3. package/dist/cjs/api/apiFunction.d.ts.map +0 -1
  4. package/dist/cjs/api/apiFunction.js +0 -89
  5. package/dist/cjs/api/checkTestDatabase.d.ts +0 -23
  6. package/dist/cjs/api/checkTestDatabase.d.ts.map +0 -1
  7. package/dist/cjs/api/checkTestDatabase.js +0 -69
  8. package/dist/cjs/api/directive.d.ts +0 -51
  9. package/dist/cjs/api/directive.d.ts.map +0 -1
  10. package/dist/cjs/api/directive.js +0 -77
  11. package/dist/cjs/api/index.d.ts +0 -4
  12. package/dist/cjs/api/index.d.ts.map +0 -1
  13. package/dist/cjs/api/index.js +0 -26
  14. package/dist/cjs/api/mockContext.d.ts +0 -5
  15. package/dist/cjs/api/mockContext.d.ts.map +0 -1
  16. package/dist/cjs/api/mockContext.js +0 -58
  17. package/dist/cjs/api/scenario.d.ts +0 -108
  18. package/dist/cjs/api/scenario.d.ts.map +0 -1
  19. package/dist/cjs/api/scenario.js +0 -30
  20. package/dist/cjs/api/vitest/CedarApiVitestEnv.js +0 -75
  21. package/dist/cjs/api/vitest/index.js +0 -34
  22. package/dist/cjs/api/vitest/vite-plugin-auto-import.js +0 -71
  23. package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +0 -69
  24. package/dist/cjs/api/vitest/vite-plugin-track-db-imports.js +0 -47
  25. package/dist/cjs/api/vitest/vitest-api.setup.js +0 -270
  26. package/dist/cjs/cache/index.d.ts +0 -50
  27. package/dist/cjs/cache/index.d.ts.map +0 -1
  28. package/dist/cjs/cache/index.js +0 -104
  29. package/dist/cjs/package.json +0 -1
  30. package/dist/cjs/web/MockParamsProvider.d.ts +0 -7
  31. package/dist/cjs/web/MockParamsProvider.d.ts.map +0 -1
  32. package/dist/cjs/web/MockParamsProvider.js +0 -44
  33. package/dist/cjs/web/MockProviders.d.ts +0 -5
  34. package/dist/cjs/web/MockProviders.d.ts.map +0 -1
  35. package/dist/cjs/web/MockProviders.js +0 -66
  36. package/dist/cjs/web/MockRouter.d.ts +0 -11
  37. package/dist/cjs/web/MockRouter.d.ts.map +0 -1
  38. package/dist/cjs/web/MockRouter.js +0 -48
  39. package/dist/cjs/web/customRender.d.ts +0 -6
  40. package/dist/cjs/web/customRender.d.ts.map +0 -1
  41. package/dist/cjs/web/customRender.js +0 -54
  42. package/dist/cjs/web/findCellMocks.d.ts +0 -2
  43. package/dist/cjs/web/findCellMocks.d.ts.map +0 -1
  44. package/dist/cjs/web/findCellMocks.js +0 -45
  45. package/dist/cjs/web/globRoutesImporter.d.ts +0 -13
  46. package/dist/cjs/web/globRoutesImporter.d.ts.map +0 -1
  47. package/dist/cjs/web/globRoutesImporter.js +0 -46
  48. package/dist/cjs/web/global.d.ts +0 -6
  49. package/dist/cjs/web/global.d.ts.map +0 -1
  50. package/dist/cjs/web/global.js +0 -1
  51. package/dist/cjs/web/index.d.ts +0 -6
  52. package/dist/cjs/web/index.d.ts.map +0 -1
  53. package/dist/cjs/web/index.js +0 -41
  54. package/dist/cjs/web/mockAuth.d.ts +0 -29
  55. package/dist/cjs/web/mockAuth.d.ts.map +0 -1
  56. package/dist/cjs/web/mockAuth.js +0 -89
  57. package/dist/cjs/web/mockRequests.d.ts +0 -72
  58. package/dist/cjs/web/mockRequests.d.ts.map +0 -1
  59. package/dist/cjs/web/mockRequests.js +0 -210
  60. package/dist/cjs/web/vitest/index.js +0 -37
  61. package/dist/cjs/web/vitest/vite-plugin-auto-import.js +0 -60
  62. package/dist/cjs/web/vitest/vite-plugin-cedar-vitest-web-config.js +0 -51
  63. package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.js +0 -42
  64. package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.js +0 -43
  65. package/dist/cjs/web/vitest/vitest-web.setup.js +0 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/testing",
3
- "version": "7.0.0-canary.2985",
3
+ "version": "7.0.0-canary.2991",
4
4
  "description": "Tools, wrappers and configuration for testing a Cedar project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,58 +11,28 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  "./auth": {
14
- "import": {
15
- "types": "./dist/web/mockAuth.d.ts",
16
- "default": "./dist/web/mockAuth.js"
17
- },
18
- "require": {
19
- "types": "./dist/cjs/web/index.d.ts",
20
- "default": "./dist/cjs/web/mockAuth.js"
21
- }
14
+ "types": "./dist/web/mockAuth.d.ts",
15
+ "default": "./dist/web/mockAuth.js"
22
16
  },
23
17
  "./api": {
24
- "import": {
25
- "types": "./dist/api/index.d.ts",
26
- "default": "./dist/api/index.js"
27
- },
28
- "require": {
29
- "types": "./dist/cjs/api/index.d.ts",
30
- "default": "./dist/cjs/api/index.js"
31
- }
18
+ "types": "./dist/api/index.d.ts",
19
+ "default": "./dist/api/index.js"
32
20
  },
33
21
  "./api/vitest": {
34
22
  "types": "./dist/api/vitest/index.d.ts",
35
23
  "default": "./dist/api/vitest/index.js"
36
24
  },
37
25
  "./cache": {
38
- "import": {
39
- "types": "./dist/cache/index.d.ts",
40
- "default": "./dist/cache/index.js"
41
- },
42
- "require": {
43
- "types": "./dist/cjs/cache/index.d.ts",
44
- "default": "./dist/cjs/cache/index.js"
45
- }
26
+ "types": "./dist/cache/index.d.ts",
27
+ "default": "./dist/cache/index.js"
46
28
  },
47
29
  "./web": {
48
- "import": {
49
- "types": "./dist/web/index.d.ts",
50
- "default": "./dist/web/index.js"
51
- },
52
- "require": {
53
- "types": "./dist/cjs/web/index.d.ts",
54
- "default": "./dist/cjs/web/index.js"
55
- }
30
+ "types": "./dist/web/index.d.ts",
31
+ "default": "./dist/web/index.js"
56
32
  },
57
33
  "./web/MockRouter.js": {
58
- "import": {
59
- "types": "./dist/web/MockRouter.d.ts",
60
- "default": "./dist/web/MockRouter.js"
61
- },
62
- "require": {
63
- "types": "./dist/cjs/web/MockRouter.d.ts",
64
- "default": "./dist/cjs/web/MockRouter.js"
65
- }
34
+ "types": "./dist/web/MockRouter.d.ts",
35
+ "default": "./dist/web/MockRouter.js"
66
36
  },
67
37
  "./web/vitest": {
68
38
  "types": "./dist/web/vitest/index.d.ts",
@@ -76,7 +46,6 @@
76
46
  "build": "node ./build.mts && yarn build:types",
77
47
  "build:pack": "yarn pack -o cedarjs-testing.tgz",
78
48
  "build:types": "tsc --build --verbose ./tsconfig.build.json",
79
- "build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
80
49
  "build:watch": "nodemon --watch src --ext 'js,jsx,ts,tsx' --ignore dist --exec 'yarn build'",
81
50
  "check:attw": "yarn cedar-fwtools-attw",
82
51
  "check:package": "concurrently npm:check:attw yarn:publint",
@@ -85,9 +54,9 @@
85
54
  "test:watch": "vitest watch"
86
55
  },
87
56
  "dependencies": {
88
- "@cedarjs/context": "7.0.0-canary.2985",
89
- "@cedarjs/graphql-server": "7.0.0-canary.2985",
90
- "@cedarjs/project-config": "7.0.0-canary.2985",
57
+ "@cedarjs/context": "7.0.0-canary.2991",
58
+ "@cedarjs/graphql-server": "7.0.0-canary.2991",
59
+ "@cedarjs/project-config": "7.0.0-canary.2991",
91
60
  "@testing-library/dom": "10.4.1",
92
61
  "@testing-library/jest-dom": "6.9.1",
93
62
  "@testing-library/react": "16.3.2",
@@ -105,19 +74,19 @@
105
74
  },
106
75
  "devDependencies": {
107
76
  "@arethetypeswrong/cli": "0.18.5",
108
- "@cedarjs/auth": "7.0.0-canary.2985",
109
- "@cedarjs/framework-tools": "7.0.0-canary.2985",
110
- "@cedarjs/router": "7.0.0-canary.2985",
111
- "@cedarjs/web": "7.0.0-canary.2985",
77
+ "@cedarjs/auth": "7.0.0-canary.2991",
78
+ "@cedarjs/framework-tools": "7.0.0-canary.2991",
79
+ "@cedarjs/router": "7.0.0-canary.2991",
80
+ "@cedarjs/web": "7.0.0-canary.2991",
112
81
  "concurrently": "9.2.4",
113
82
  "publint": "0.3.23",
114
83
  "typescript": "5.9.3",
115
84
  "vitest": "4.1.10"
116
85
  },
117
86
  "peerDependencies": {
118
- "@cedarjs/auth": "7.0.0-canary.2985",
119
- "@cedarjs/router": "7.0.0-canary.2985",
120
- "@cedarjs/web": "7.0.0-canary.2985",
87
+ "@cedarjs/auth": "7.0.0-canary.2991",
88
+ "@cedarjs/router": "7.0.0-canary.2991",
89
+ "@cedarjs/web": "7.0.0-canary.2991",
121
90
  "vitest": "4.1.10"
122
91
  },
123
92
  "peerDependenciesMeta": {
@@ -1,37 +0,0 @@
1
- import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, Context } from 'aws-lambda';
2
- import type { SupportedVerifierTypes } from '@cedarjs/api/webhooks';
3
- interface BuildEventParams extends Partial<APIGatewayProxyEvent> {
4
- payload?: string | null | Record<any, any>;
5
- signature?: string;
6
- signatureHeader?: string;
7
- headers?: APIGatewayProxyEventHeaders;
8
- }
9
- /**
10
- * @description Use this to mock out the http request event that is received by your function in unit tests
11
- *
12
- * @example Mocking sending headers
13
- * mockHttpEvent({header: {'X-Custom-Header': 'bazinga'}})
14
- *
15
- * @example Adding a JSON payload
16
- * mockHttpEvent({payload: JSON.stringify(mockedRequestBody)})
17
- *
18
- * @returns APIGatewayProxyEvent
19
- */
20
- export declare const mockHttpEvent: ({ payload, signature, signatureHeader, queryStringParameters, httpMethod, headers, path, isBase64Encoded, ...others }: BuildEventParams) => APIGatewayProxyEvent;
21
- /**
22
- * @description Use this function to mock the http event's context
23
- * @see: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
24
- **/
25
- export declare const mockContext: () => Context;
26
- interface MockedSignedWebhookParams extends Omit<BuildEventParams, 'signature' | 'signatureHeader'> {
27
- signatureType: Exclude<SupportedVerifierTypes, 'skipVerifier'>;
28
- signatureHeader: string;
29
- secret: string;
30
- }
31
- /**
32
- * @description Use this function to mock a signed webhook
33
- * @see https://cedarjs.com/docs/webhooks#webhooks
34
- **/
35
- export declare const mockSignedWebhook: ({ payload, signatureType, signatureHeader, secret, ...others }: MockedSignedWebhookParams) => APIGatewayProxyEvent;
36
- export {};
37
- //# sourceMappingURL=apiFunction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apiFunction.d.ts","sourceRoot":"","sources":["../../../src/api/apiFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAGnE,UAAU,gBAAiB,SAAQ,OAAO,CAAC,oBAAoB,CAAC;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,2BAA2B,CAAA;CACtC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,uHAU3B,gBAAgB,KAAG,oBAgCrB,CAAA;AAED;;;IAGI;AACJ,eAAO,MAAM,WAAW,QAAO,OAI9B,CAAA;AAED,UAAU,yBAA0B,SAAQ,IAAI,CAC9C,gBAAgB,EAChB,WAAW,GAAG,iBAAiB,CAChC;IACC,aAAa,EAAE,OAAO,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAA;IAC9D,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;IAGI;AACJ,eAAO,MAAM,iBAAiB,GAAI,gEAM/B,yBAAyB,yBAe3B,CAAA"}
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var apiFunction_exports = {};
20
- __export(apiFunction_exports, {
21
- mockContext: () => mockContext,
22
- mockHttpEvent: () => mockHttpEvent,
23
- mockSignedWebhook: () => mockSignedWebhook
24
- });
25
- module.exports = __toCommonJS(apiFunction_exports);
26
- var import_webhooks = require("@cedarjs/api/webhooks");
27
- const mockHttpEvent = ({
28
- payload = null,
29
- signature,
30
- signatureHeader,
31
- queryStringParameters = null,
32
- httpMethod = "GET",
33
- headers = {},
34
- path = "",
35
- isBase64Encoded = false,
36
- ...others
37
- }) => {
38
- if (signature && signatureHeader) {
39
- headers[signatureHeader.toLocaleLowerCase()] = signature;
40
- }
41
- const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
42
- const body = payload === null ? null : isBase64Encoded ? Buffer.from(payloadAsString || "").toString("base64") : payloadAsString;
43
- return {
44
- body,
45
- headers,
46
- multiValueHeaders: {},
47
- isBase64Encoded,
48
- path,
49
- pathParameters: null,
50
- stageVariables: null,
51
- httpMethod,
52
- queryStringParameters,
53
- // @ts-expect-error not required for mocks
54
- requestContext: null,
55
- // @ts-expect-error not required for mocks
56
- resource: null,
57
- multiValueQueryStringParameters: null,
58
- ...others
59
- };
60
- };
61
- const mockContext = () => {
62
- const context = {};
63
- return context;
64
- };
65
- const mockSignedWebhook = ({
66
- payload = null,
67
- signatureType,
68
- signatureHeader,
69
- secret,
70
- ...others
71
- }) => {
72
- const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
73
- const signature = (0, import_webhooks.signPayload)(signatureType, {
74
- payload: payloadAsString,
75
- secret
76
- });
77
- return mockHttpEvent({
78
- payload,
79
- signature,
80
- signatureHeader,
81
- ...others
82
- });
83
- };
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- mockContext,
87
- mockHttpEvent,
88
- mockSignedWebhook
89
- });
@@ -1,23 +0,0 @@
1
- /**
2
- * Redacts credentials from a database connection string so it's safe to
3
- * print. Handles both URI-style authority credentials, e.g.
4
- * `postgres://user:pass@host/db` -> `postgres://user:***@host/db`, and
5
- * semicolon-delimited key/value credentials used by SQL Server connection
6
- * strings, e.g. `Server=host;Password=secret;` -> `Server=host;Password=***;`.
7
- */
8
- export declare function redactDatabaseUrl(url: string): string;
9
- /**
10
- * Checks that the `DATABASE_URL` about to be used for tests matches the
11
- * datasource provider configured in `schema.prisma`, and throws an
12
- * actionable error if they don't match.
13
- *
14
- * Without this check, running `prisma db push`/`migrate reset` against a
15
- * mismatched provider/URL combination (e.g. a leftover sqlite fallback URL
16
- * with a `postgresql` schema) can hang indefinitely with no output, instead
17
- * of failing fast. See https://github.com/cedarjs/cedar/issues/2284.
18
- *
19
- * If the provider can't be determined (e.g. `schema.prisma` doesn't exist
20
- * yet), this is a no-op — Prisma itself will surface the problem.
21
- */
22
- export declare function checkTestDatabaseUrlMatchesProvider(databaseUrl: string, usedFallback: boolean): Promise<void>;
23
- //# sourceMappingURL=checkTestDatabase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkTestDatabase.d.ts","sourceRoot":"","sources":["../../../src/api/checkTestDatabase.ts"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mCAAmC,CACvD,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,iBAmCtB"}
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var checkTestDatabase_exports = {};
20
- __export(checkTestDatabase_exports, {
21
- checkTestDatabaseUrlMatchesProvider: () => checkTestDatabaseUrlMatchesProvider,
22
- redactDatabaseUrl: () => redactDatabaseUrl
23
- });
24
- module.exports = __toCommonJS(checkTestDatabase_exports);
25
- var import_project_config = require("@cedarjs/project-config");
26
- const PROVIDER_URL_SCHEMES = {
27
- sqlite: ["file:"],
28
- postgresql: ["postgres:", "postgresql:"],
29
- postgres: ["postgres:", "postgresql:"],
30
- cockroachdb: ["postgres:", "postgresql:"],
31
- mysql: ["mysql:"],
32
- sqlserver: ["sqlserver:"],
33
- mongodb: ["mongodb:", "mongodb+srv:"]
34
- };
35
- function getUrlScheme(url) {
36
- const match = url.match(/^([a-z][a-z0-9+.-]*:)/i);
37
- return match?.[1]?.toLowerCase();
38
- }
39
- function redactDatabaseUrl(url) {
40
- return url.replace(/:\/\/([^:/?#]+):([^@/?#]+)@/, "://$1:***@").replace(/((?:^|;)\s*password\s*=)[^;]*/gi, "$1***");
41
- }
42
- async function checkTestDatabaseUrlMatchesProvider(databaseUrl, usedFallback) {
43
- let provider;
44
- try {
45
- provider = await (0, import_project_config.getPrismaDatasourceProvider)();
46
- } catch {
47
- return;
48
- }
49
- const expectedSchemes = PROVIDER_URL_SCHEMES[provider];
50
- if (!expectedSchemes) {
51
- return;
52
- }
53
- const actualScheme = getUrlScheme(databaseUrl);
54
- if (actualScheme && expectedSchemes.includes(actualScheme)) {
55
- return;
56
- }
57
- const redactedUrl = redactDatabaseUrl(databaseUrl);
58
- const reason = usedFallback ? `TEST_DATABASE_URL is not set, so the default sqlite test database was used (${redactedUrl}), but your schema.prisma is configured for "${provider}". Set TEST_DATABASE_URL to a "${provider}" connection string to run tests.` : `TEST_DATABASE_URL (${redactedUrl}) does not match the "${provider}" provider configured in schema.prisma. Update TEST_DATABASE_URL to a "${provider}" connection string.`;
59
- throw new Error(
60
- `Test database URL does not match your Prisma schema's provider.
61
-
62
- ${reason}`
63
- );
64
- }
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- checkTestDatabaseUrlMatchesProvider,
68
- redactDatabaseUrl
69
- });
@@ -1,51 +0,0 @@
1
- import type { A } from 'ts-toolbelt';
2
- import type { DirectiveParams, ValidatorDirective, TransformerDirective } from '@cedarjs/graphql-server';
3
- export { getDirectiveName } from '@cedarjs/graphql-server';
4
- interface DirectiveMocker {
5
- (directive: ValidatorDirective, executionMock: A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>>): any;
6
- }
7
- type TransformerMock = A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>> & {
8
- mockedResolvedValue: any;
9
- };
10
- interface DirectiveMocker {
11
- (directive: TransformerDirective, executionMock: TransformerMock): any;
12
- }
13
- /**
14
- * @description
15
- *
16
- * Used for writing both synchronous and asynchronous directive tests e.g.
17
- *
18
- * - Transformer directives can be passed mockedResolvedValue
19
- * - Validator directives should check for errors thrown in certain situations
20
- * - Can provide args, directiveArgs and context to mock directive execution
21
- *
22
- * @example
23
- *
24
- * Synchronous transformer directive:
25
- *
26
- * ```ts
27
- * const mockExecution = mockRedwoodDirective(myTransformer, {
28
- * context: currentUser,
29
- * mockedResolvedValue: 'Original Value',
30
- * })
31
- *
32
- * expect(mockExecution).not.toThrow()
33
- * expect(mockExecution()).toEqual('Transformed Value')
34
- * ```ts
35
- *
36
- * @example
37
- *
38
- * Asynchronous transformer directive:
39
- *
40
- * ```ts
41
- * const mockExecution = mockRedwoodDirective(myTransformer, {
42
- * context: currentUser,
43
- * mockedResolvedValue: 'Original Value',
44
- * })
45
- *
46
- * await expect(mockExecution).resolves.not.toThrow()
47
- * await expect(mockExecution()).resolves.toEqual('Transformed Value')
48
- * ```
49
- */
50
- export declare const mockRedwoodDirective: DirectiveMocker;
51
- //# sourceMappingURL=directive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directive.d.ts","sourceRoot":"","sources":["../../../src/api/directive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG1D,UAAU,eAAe;IACvB,CACE,SAAS,EAAE,kBAAkB,EAC7B,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,GACxE,GAAG,CAAA;CACP;AAED,KAAK,eAAe,GAAG,CAAC,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAChD,GAAG;IACF,mBAAmB,EAAE,GAAG,CAAA;CACzB,CAAA;AAGD,UAAU,eAAe;IACvB,CAAC,SAAS,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,GAAG,GAAG,CAAA;CACvE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB,EAAE,eAmDlC,CAAA"}
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var directive_exports = {};
20
- __export(directive_exports, {
21
- getDirectiveName: () => import_graphql_server2.getDirectiveName,
22
- mockRedwoodDirective: () => mockRedwoodDirective
23
- });
24
- module.exports = __toCommonJS(directive_exports);
25
- var import_context = require("@cedarjs/context");
26
- var import_graphql_server = require("@cedarjs/graphql-server");
27
- var import_graphql_server2 = require("@cedarjs/graphql-server");
28
- const mockRedwoodDirective = (directive, executionMock) => {
29
- const { directiveArgs, context, ...others } = executionMock;
30
- if (directive.onResolvedValue.constructor.name === "AsyncFunction") {
31
- return async () => {
32
- if (context !== void 0) {
33
- (0, import_context.setContext)(context);
34
- }
35
- if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
36
- const { mockedResolvedValue } = others;
37
- return directive.onResolvedValue({
38
- resolvedValue: mockedResolvedValue,
39
- directiveArgs: directiveArgs ?? {},
40
- context: import_context.context,
41
- ...others
42
- });
43
- } else {
44
- await directive.onResolvedValue({
45
- directiveArgs: directiveArgs ?? {},
46
- context: import_context.context,
47
- ...others
48
- });
49
- }
50
- };
51
- }
52
- return () => {
53
- if (context !== void 0) {
54
- (0, import_context.setContext)(context);
55
- }
56
- if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
57
- const { mockedResolvedValue } = others;
58
- return directive.onResolvedValue({
59
- resolvedValue: mockedResolvedValue,
60
- directiveArgs: directiveArgs ?? {},
61
- context: import_context.context,
62
- ...others
63
- });
64
- } else {
65
- directive.onResolvedValue({
66
- directiveArgs: directiveArgs ?? {},
67
- context: import_context.context,
68
- ...others
69
- });
70
- }
71
- };
72
- };
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- getDirectiveName,
76
- mockRedwoodDirective
77
- });
@@ -1,4 +0,0 @@
1
- export * from './apiFunction.js';
2
- export * from './scenario.js';
3
- export * from './directive.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var api_exports = {};
17
- module.exports = __toCommonJS(api_exports);
18
- __reExport(api_exports, require("./apiFunction.js"), module.exports);
19
- __reExport(api_exports, require("./scenario.js"), module.exports);
20
- __reExport(api_exports, require("./directive.js"), module.exports);
21
- // Annotate the CommonJS export names for ESM import in node:
22
- 0 && (module.exports = {
23
- ...require("./apiFunction.js"),
24
- ...require("./scenario.js"),
25
- ...require("./directive.js")
26
- });
@@ -1,5 +0,0 @@
1
- export interface GlobalContext extends Record<string, unknown> {
2
- }
3
- export declare const context: {};
4
- export declare const setContext: (newContext: GlobalContext) => GlobalContext;
5
- //# sourceMappingURL=mockContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockContext.d.ts","sourceRoot":"","sources":["../../../src/api/mockContext.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,OAAO,IAAc,CAAA;AAElC,eAAO,MAAM,UAAU,GAAI,YAAY,aAAa,KAAG,aAKtD,CAAA"}
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var mockContext_exports = {};
20
- __export(mockContext_exports, {
21
- context: () => context,
22
- setContext: () => setContext
23
- });
24
- module.exports = __toCommonJS(mockContext_exports);
25
- const mockContextStore = /* @__PURE__ */ new Map();
26
- const mockContext = new Proxy(
27
- {},
28
- {
29
- get: (_target, prop) => {
30
- if (prop === "toJSON") {
31
- return () => mockContextStore.get("context");
32
- }
33
- const ctx = mockContextStore.get("context");
34
- if (!ctx) {
35
- return void 0;
36
- }
37
- return ctx[prop];
38
- },
39
- set: (_target, prop, value) => {
40
- const ctx = mockContextStore.get("context");
41
- if (!ctx) {
42
- return false;
43
- }
44
- ctx[prop] = value;
45
- return true;
46
- }
47
- }
48
- );
49
- const context = mockContext;
50
- const setContext = (newContext) => {
51
- mockContextStore.set("context", newContext);
52
- return mockContext;
53
- };
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- context,
57
- setContext
58
- });