@cedarjs/testing 0.7.2-next.2 → 0.7.2-next.50
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/config/jest/api/package.json +8 -0
- package/config/jest/web/package.json +8 -0
- package/dist/api/mockContext.d.ts +5 -0
- package/dist/api/mockContext.d.ts.map +1 -0
- package/dist/api/mockContext.js +33 -0
- package/dist/api/vitest/CedarApiVitestEnv.d.ts +5 -0
- package/dist/api/vitest/CedarApiVitestEnv.d.ts.map +1 -0
- package/dist/api/vitest/CedarApiVitestEnv.js +41 -0
- package/dist/api/vitest/index.d.ts +4 -0
- package/dist/api/vitest/index.d.ts.map +1 -0
- package/dist/api/vitest/index.js +8 -0
- package/dist/api/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/api/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-auto-import.js +37 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts +3 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +34 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.d.ts +3 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.js +23 -0
- package/dist/api/vitest/vitest-api.setup.d.ts +9 -0
- package/dist/api/vitest/vitest-api.setup.d.ts.map +1 -0
- package/dist/api/vitest/vitest-api.setup.js +247 -0
- package/dist/cjs/api/mockContext.d.ts +5 -0
- package/dist/cjs/api/mockContext.d.ts.map +1 -0
- package/dist/cjs/api/mockContext.js +58 -0
- package/dist/cjs/api/vitest/CedarApiVitestEnv.js +71 -0
- package/dist/cjs/api/vitest/index.js +34 -0
- package/dist/cjs/api/vitest/vite-plugin-auto-import.js +71 -0
- package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +69 -0
- package/dist/cjs/api/vitest/vite-plugin-track-db-imports.js +47 -0
- package/dist/cjs/api/vitest/vitest-api.setup.js +270 -0
- package/dist/cjs/web/MockProviders.d.ts +0 -4
- package/dist/cjs/web/MockProviders.d.ts.map +1 -1
- package/dist/cjs/web/MockProviders.js +2 -1
- package/dist/cjs/web/MockRouter.d.ts +0 -3
- package/dist/cjs/web/MockRouter.d.ts.map +1 -1
- package/dist/cjs/web/globRoutesImporter.d.ts +13 -0
- package/dist/cjs/web/globRoutesImporter.d.ts.map +1 -0
- package/dist/cjs/web/globRoutesImporter.js +46 -0
- package/dist/cjs/web/vitest/index.d.ts +4 -0
- package/dist/cjs/web/vitest/index.d.ts.map +1 -0
- package/dist/cjs/web/vitest/index.js +34 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.js +60 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts +7 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.js +42 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts +3 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.js +43 -0
- package/dist/web/MockProviders.d.ts +0 -4
- package/dist/web/MockProviders.d.ts.map +1 -1
- package/dist/web/MockProviders.js +2 -1
- package/dist/web/MockRouter.d.ts +0 -3
- package/dist/web/MockRouter.d.ts.map +1 -1
- package/dist/web/globRoutesImporter.d.ts +13 -0
- package/dist/web/globRoutesImporter.d.ts.map +1 -0
- package/dist/web/globRoutesImporter.js +21 -0
- package/dist/web/vitest/index.d.ts +4 -0
- package/dist/web/vitest/index.d.ts.map +1 -0
- package/dist/web/vitest/index.js +8 -0
- package/dist/web/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/web/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-auto-import.js +26 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts +7 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.js +18 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.d.ts +3 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.js +19 -0
- package/package.json +39 -12
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vite_plugin_auto_import_exports = {};
|
|
30
|
+
__export(vite_plugin_auto_import_exports, {
|
|
31
|
+
autoImportsPlugin: () => autoImportsPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_auto_import_exports);
|
|
34
|
+
var import_vite = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
35
|
+
function autoImportsPlugin() {
|
|
36
|
+
return (0, import_vite.default)({
|
|
37
|
+
// targets to transform
|
|
38
|
+
include: [
|
|
39
|
+
/\.[tj]sx?$/
|
|
40
|
+
// .ts, .tsx, .js, .jsx
|
|
41
|
+
],
|
|
42
|
+
// global imports to register
|
|
43
|
+
imports: [
|
|
44
|
+
{
|
|
45
|
+
"@cedarjs/testing/web": [
|
|
46
|
+
"mockGraphQLQuery",
|
|
47
|
+
"mockGraphQLMutation",
|
|
48
|
+
"mockCurrentUser"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
// We provide our mocking types elsewhere and so don't need this plugin to
|
|
53
|
+
// generate them.
|
|
54
|
+
dts: false
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
autoImportsPlugin
|
|
60
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Replace `@cedarjs/router` imports with imports of
|
|
4
|
+
* `@cedarjs/testing/web/MockRouter.js` instead
|
|
5
|
+
*/
|
|
6
|
+
export declare function cedarJsRouterImportTransformPlugin(): PluginOption;
|
|
7
|
+
//# sourceMappingURL=vite-plugin-cedarjs-router-import-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedarjs-router-import-transform.d.ts","sourceRoot":"","sources":["../../../../src/web/vitest/vite-plugin-cedarjs-router-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,YAAY,CAejE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 vite_plugin_cedarjs_router_import_transform_exports = {};
|
|
20
|
+
__export(vite_plugin_cedarjs_router_import_transform_exports, {
|
|
21
|
+
cedarJsRouterImportTransformPlugin: () => cedarJsRouterImportTransformPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(vite_plugin_cedarjs_router_import_transform_exports);
|
|
24
|
+
function cedarJsRouterImportTransformPlugin() {
|
|
25
|
+
return {
|
|
26
|
+
name: "cedarjs-router-import-transform",
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
transform(code, id) {
|
|
29
|
+
if (id.includes("/web/src")) {
|
|
30
|
+
code = code.replace(
|
|
31
|
+
/['"]@cedarjs\/router['"]/,
|
|
32
|
+
"'@cedarjs/testing/web/MockRouter.js'"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return code;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
cedarJsRouterImportTransformPlugin
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-create-auth-import-transform.d.ts","sourceRoot":"","sources":["../../../../src/web/vitest/vite-plugin-create-auth-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC,wBAAgB,+BAA+B,IAAI,YAAY,CAuB9D"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 vite_plugin_create_auth_import_transform_exports = {};
|
|
20
|
+
__export(vite_plugin_create_auth_import_transform_exports, {
|
|
21
|
+
createAuthImportTransformPlugin: () => createAuthImportTransformPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(vite_plugin_create_auth_import_transform_exports);
|
|
24
|
+
function createAuthImportTransformPlugin() {
|
|
25
|
+
return {
|
|
26
|
+
name: "create-auth-import-transform",
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
transform(code, id) {
|
|
29
|
+
if (id.endsWith("/web/src/auth.ts") || id.endsWith("/web/src/auth.js")) {
|
|
30
|
+
code = code.replace(
|
|
31
|
+
/(^\s*import\s*{[^}]*?)(\bcreateAuth\b)(,?)([^}]*})/m,
|
|
32
|
+
"$1$4"
|
|
33
|
+
);
|
|
34
|
+
code = "import { createAuthentication as createAuth } from '@cedarjs/testing/auth'\n" + code;
|
|
35
|
+
}
|
|
36
|
+
return code;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
createAuthImportTransformPlugin
|
|
43
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA+BzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAYA,CAAA"}
|
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { LocationProvider } from "@cedarjs/router";
|
|
3
3
|
import { RedwoodProvider } from "@cedarjs/web";
|
|
4
4
|
import { RedwoodApolloProvider } from "@cedarjs/web/apollo";
|
|
5
|
+
import { UserRoutes as VitestUserRoutes } from "./globRoutesImporter.js";
|
|
5
6
|
import { useAuth } from "./mockAuth.js";
|
|
6
7
|
import { MockParamsProvider } from "./MockParamsProvider.js";
|
|
7
8
|
let UserRoutes;
|
|
@@ -15,7 +16,7 @@ try {
|
|
|
15
16
|
UserRoutes = () => /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
16
17
|
}
|
|
17
18
|
const MockProviders = ({ children }) => {
|
|
18
|
-
return /* @__PURE__ */ React.createElement(RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(RedwoodApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
|
|
19
|
+
return /* @__PURE__ */ React.createElement(RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(RedwoodApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(VitestUserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
|
|
19
20
|
};
|
|
20
21
|
function isModuleNotFoundError(error, module) {
|
|
21
22
|
return !!error && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND" && "moduleName" in error && error.moduleName === module;
|
package/dist/web/MockRouter.d.ts
CHANGED
|
@@ -5,9 +5,6 @@ export declare const routes: {
|
|
|
5
5
|
[routeName: string]: () => string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* We overwrite the default `Router` export (see jest-preset). So every import
|
|
9
|
-
* of @cedarjs/router will import this Router instead
|
|
10
|
-
*
|
|
11
8
|
* This router populates the `routes.<pageName>()` utility object.
|
|
12
9
|
*/
|
|
13
10
|
export declare const Router: React.FC<RouterProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../src/web/MockRouter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../src/web/MockRouter.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG9D,cAAc,4BAA4B,CAAA;AAE1C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,MAAM,CAAA;CAAO,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAcxC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All the routes the user has defined
|
|
3
|
+
*
|
|
4
|
+
* We render this in the `<MockProviders>` component to populate the `routes`
|
|
5
|
+
* import from `@cedarjs/router` to make sure code like
|
|
6
|
+
* `<Link to={routes.home()}>Home</Link>` works in tests
|
|
7
|
+
*
|
|
8
|
+
* The final piece to this puzzle is to realize that the user's Routes file
|
|
9
|
+
* imports `@cedarjs/router`, which we replace to import from '@cedarjs/testing'
|
|
10
|
+
* instead using a vite plugin that we only run for vitest and storybook
|
|
11
|
+
*/
|
|
12
|
+
export declare const UserRoutes: React.FC;
|
|
13
|
+
//# sourceMappingURL=globRoutesImporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globRoutesImporter.d.ts","sourceRoot":"","sources":["../../src/web/globRoutesImporter.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAqB,KAAK,CAAC,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const defaultExports = import.meta.glob(
|
|
2
|
+
["/src/Routes.{tsx,jsx}", "/Routes.{tsx,jsx}"],
|
|
3
|
+
{
|
|
4
|
+
import: "default",
|
|
5
|
+
eager: true
|
|
6
|
+
}
|
|
7
|
+
);
|
|
8
|
+
const routesFileName = Object.keys(defaultExports)[0];
|
|
9
|
+
if (!routesFileName) {
|
|
10
|
+
throw new Error("@cedarjs/testing: No routes found");
|
|
11
|
+
}
|
|
12
|
+
const routesFunction = defaultExports[routesFileName];
|
|
13
|
+
if (typeof routesFunction !== "function") {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"@cedarjs/testing: Routes file does not export a React component"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const UserRoutes = routesFunction;
|
|
19
|
+
export {
|
|
20
|
+
UserRoutes
|
|
21
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { cedarJsRouterImportTransformPlugin } from './vite-plugin-cedarjs-router-import-transform.js';
|
|
2
|
+
export { createAuthImportTransformPlugin } from './vite-plugin-create-auth-import-transform.js';
|
|
3
|
+
export { autoImportsPlugin } from './vite-plugin-auto-import.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,kDAAkD,CAAA;AACrG,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { cedarJsRouterImportTransformPlugin } from "./vite-plugin-cedarjs-router-import-transform.js";
|
|
2
|
+
import { createAuthImportTransformPlugin } from "./vite-plugin-create-auth-import-transform.js";
|
|
3
|
+
import { autoImportsPlugin } from "./vite-plugin-auto-import.js";
|
|
4
|
+
export {
|
|
5
|
+
autoImportsPlugin,
|
|
6
|
+
cedarJsRouterImportTransformPlugin,
|
|
7
|
+
createAuthImportTransformPlugin
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-auto-import.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-auto-import.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,8DAsBhC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import autoImport from "unplugin-auto-import/vite";
|
|
2
|
+
function autoImportsPlugin() {
|
|
3
|
+
return autoImport({
|
|
4
|
+
// targets to transform
|
|
5
|
+
include: [
|
|
6
|
+
/\.[tj]sx?$/
|
|
7
|
+
// .ts, .tsx, .js, .jsx
|
|
8
|
+
],
|
|
9
|
+
// global imports to register
|
|
10
|
+
imports: [
|
|
11
|
+
{
|
|
12
|
+
"@cedarjs/testing/web": [
|
|
13
|
+
"mockGraphQLQuery",
|
|
14
|
+
"mockGraphQLMutation",
|
|
15
|
+
"mockCurrentUser"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
// We provide our mocking types elsewhere and so don't need this plugin to
|
|
20
|
+
// generate them.
|
|
21
|
+
dts: false
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
autoImportsPlugin
|
|
26
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Replace `@cedarjs/router` imports with imports of
|
|
4
|
+
* `@cedarjs/testing/web/MockRouter.js` instead
|
|
5
|
+
*/
|
|
6
|
+
export declare function cedarJsRouterImportTransformPlugin(): PluginOption;
|
|
7
|
+
//# sourceMappingURL=vite-plugin-cedarjs-router-import-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedarjs-router-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-cedarjs-router-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,YAAY,CAejE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function cedarJsRouterImportTransformPlugin() {
|
|
2
|
+
return {
|
|
3
|
+
name: "cedarjs-router-import-transform",
|
|
4
|
+
enforce: "pre",
|
|
5
|
+
transform(code, id) {
|
|
6
|
+
if (id.includes("/web/src")) {
|
|
7
|
+
code = code.replace(
|
|
8
|
+
/['"]@cedarjs\/router['"]/,
|
|
9
|
+
"'@cedarjs/testing/web/MockRouter.js'"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return code;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
cedarJsRouterImportTransformPlugin
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-create-auth-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-create-auth-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC,wBAAgB,+BAA+B,IAAI,YAAY,CAuB9D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function createAuthImportTransformPlugin() {
|
|
2
|
+
return {
|
|
3
|
+
name: "create-auth-import-transform",
|
|
4
|
+
enforce: "pre",
|
|
5
|
+
transform(code, id) {
|
|
6
|
+
if (id.endsWith("/web/src/auth.ts") || id.endsWith("/web/src/auth.js")) {
|
|
7
|
+
code = code.replace(
|
|
8
|
+
/(^\s*import\s*{[^}]*?)(\bcreateAuth\b)(,?)([^}]*})/m,
|
|
9
|
+
"$1$4"
|
|
10
|
+
);
|
|
11
|
+
code = "import { createAuthentication as createAuth } from '@cedarjs/testing/auth'\n" + code;
|
|
12
|
+
}
|
|
13
|
+
return code;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
createAuthImportTransformPlugin
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/testing",
|
|
3
|
-
"version": "0.7.2-next.
|
|
3
|
+
"version": "0.7.2-next.50+a096cc0c6",
|
|
4
4
|
"description": "Tools, wrappers and configuration for testing a CedarJS project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,6 +63,10 @@
|
|
|
63
63
|
"default": "./dist/cjs/api/index.js"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
+
"./api/vitest": {
|
|
67
|
+
"types": "./dist/api/vitest/index.d.ts",
|
|
68
|
+
"default": "./dist/api/vitest/index.js"
|
|
69
|
+
},
|
|
66
70
|
"./cache": {
|
|
67
71
|
"import": {
|
|
68
72
|
"types": "./dist/cache/index.d.ts",
|
|
@@ -82,6 +86,20 @@
|
|
|
82
86
|
"types": "./dist/cjs/web/index.d.ts",
|
|
83
87
|
"default": "./dist/cjs/web/index.js"
|
|
84
88
|
}
|
|
89
|
+
},
|
|
90
|
+
"./web/MockRouter.js": {
|
|
91
|
+
"import": {
|
|
92
|
+
"types": "./dist/web/MockRouter.d.ts",
|
|
93
|
+
"default": "./dist/web/MockRouter.js"
|
|
94
|
+
},
|
|
95
|
+
"require": {
|
|
96
|
+
"types": "./dist/cjs/web/MockRouter.d.ts",
|
|
97
|
+
"default": "./dist/cjs/web/MockRouter.js"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"./web/vitest": {
|
|
101
|
+
"types": "./dist/web/vitest/index.d.ts",
|
|
102
|
+
"default": "./dist/web/vitest/index.js"
|
|
85
103
|
}
|
|
86
104
|
},
|
|
87
105
|
"files": [
|
|
@@ -95,7 +113,7 @@
|
|
|
95
113
|
"build": "tsx ./build.mts && yarn build:types",
|
|
96
114
|
"build:pack": "yarn pack -o cedarjs-testing.tgz",
|
|
97
115
|
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
98
|
-
"build:types-cjs": "tsc --build --verbose tsconfig.cjs.json",
|
|
116
|
+
"build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
|
|
99
117
|
"build:watch": "nodemon --watch src --ext 'js,jsx,ts,tsx' --ignore dist --exec 'yarn build'",
|
|
100
118
|
"check:attw": "yarn rw-fwtools-attw",
|
|
101
119
|
"check:package": "concurrently npm:check:attw yarn:publint",
|
|
@@ -104,13 +122,13 @@
|
|
|
104
122
|
"test:watch": "vitest watch"
|
|
105
123
|
},
|
|
106
124
|
"dependencies": {
|
|
107
|
-
"@cedarjs/auth": "0.7.2-next.
|
|
108
|
-
"@cedarjs/babel-config": "0.7.2-next.
|
|
109
|
-
"@cedarjs/context": "0.7.2-next.
|
|
110
|
-
"@cedarjs/graphql-server": "0.7.2-next.
|
|
111
|
-
"@cedarjs/project-config": "0.7.2-next.
|
|
112
|
-
"@cedarjs/router": "0.7.2-next.
|
|
113
|
-
"@cedarjs/web": "0.7.2-next.
|
|
125
|
+
"@cedarjs/auth": "0.7.2-next.50+a096cc0c6",
|
|
126
|
+
"@cedarjs/babel-config": "0.7.2-next.50+a096cc0c6",
|
|
127
|
+
"@cedarjs/context": "0.7.2-next.50+a096cc0c6",
|
|
128
|
+
"@cedarjs/graphql-server": "0.7.2-next.50+a096cc0c6",
|
|
129
|
+
"@cedarjs/project-config": "0.7.2-next.50+a096cc0c6",
|
|
130
|
+
"@cedarjs/router": "0.7.2-next.50+a096cc0c6",
|
|
131
|
+
"@cedarjs/web": "0.7.2-next.50+a096cc0c6",
|
|
114
132
|
"@testing-library/jest-dom": "6.5.0",
|
|
115
133
|
"@testing-library/react": "14.3.1",
|
|
116
134
|
"@testing-library/user-event": "14.5.2",
|
|
@@ -125,19 +143,28 @@
|
|
|
125
143
|
"jest-watch-typeahead": "2.2.2",
|
|
126
144
|
"msw": "1.3.5",
|
|
127
145
|
"ts-toolbelt": "9.6.0",
|
|
146
|
+
"unplugin-auto-import": "19.3.0",
|
|
128
147
|
"whatwg-fetch": "3.6.20"
|
|
129
148
|
},
|
|
130
149
|
"devDependencies": {
|
|
131
|
-
"@cedarjs/framework-tools": "0.7.2-next.
|
|
150
|
+
"@cedarjs/framework-tools": "0.7.2-next.50",
|
|
132
151
|
"concurrently": "8.2.2",
|
|
133
152
|
"jsdom": "24.1.3",
|
|
134
153
|
"publint": "0.3.12",
|
|
135
|
-
"tsx": "4.20.
|
|
154
|
+
"tsx": "4.20.4",
|
|
136
155
|
"typescript": "5.6.2",
|
|
137
156
|
"vitest": "3.2.4"
|
|
138
157
|
},
|
|
158
|
+
"peerDependencies": {
|
|
159
|
+
"vitest": "3.2.4"
|
|
160
|
+
},
|
|
161
|
+
"peerDependenciesMeta": {
|
|
162
|
+
"vitest": {
|
|
163
|
+
"optional": true
|
|
164
|
+
}
|
|
165
|
+
},
|
|
139
166
|
"publishConfig": {
|
|
140
167
|
"access": "public"
|
|
141
168
|
},
|
|
142
|
-
"gitHead": "
|
|
169
|
+
"gitHead": "a096cc0c68ba5371661ed5ea0e11a0ad10f61a21"
|
|
143
170
|
}
|