@akanjs/test 0.0.78 → 0.0.79

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/test",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,2 +1,3 @@
1
1
  import type { Config } from "@jest/types";
2
+ export declare function pathsToModuleNameMapper(paths: Record<string, string[]>, workspaceRoot: string): Record<string, string>;
2
3
  export declare const withBase: (name: string) => Config.InitialOptions;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,22 +16,57 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var jest_config_base_exports = {};
19
29
  __export(jest_config_base_exports, {
30
+ pathsToModuleNameMapper: () => pathsToModuleNameMapper,
20
31
  withBase: () => withBase
21
32
  });
22
33
  module.exports = __toCommonJS(jest_config_base_exports);
23
34
  var import_dotenv = require("dotenv");
35
+ var import_fs = __toESM(require("fs"));
36
+ function pathsToModuleNameMapper(paths, workspaceRoot) {
37
+ const moduleNameMapper = {};
38
+ const sortedPaths = Object.entries(paths).sort(([a], [b]) => {
39
+ const aHasWildcard = a.includes("*");
40
+ const bHasWildcard = b.includes("*");
41
+ if (aHasWildcard === bHasWildcard)
42
+ return 0;
43
+ return aHasWildcard ? -1 : 1;
44
+ });
45
+ for (const [tsPath, targetPaths] of sortedPaths) {
46
+ const targetPath = targetPaths[0];
47
+ const escapedPath = tsPath.replace(/[.*+?^${}()|[\]\\]/g, (match) => {
48
+ return match === "*" ? match : `\\${match}`;
49
+ });
50
+ const jestPattern = `^${escapedPath.replace(/\*/g, "(.*)")}$`;
51
+ const jestReplacement = `${workspaceRoot}/${targetPath.replace(/\*/g, "$1")}`;
52
+ moduleNameMapper[jestPattern] = jestReplacement;
53
+ }
54
+ return moduleNameMapper;
55
+ }
24
56
  const withBase = (name) => {
25
57
  (0, import_dotenv.config)();
26
58
  process.env.NEXT_PUBLIC_ENV = "testing";
27
59
  process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
28
60
  process.env.NEXT_PUBLIC_APP_NAME = name;
29
61
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
30
- const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
62
+ const workspaceRoot = process.env.AKAN_WORKSPACE_ROOT ?? process.cwd();
63
+ const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? `${workspaceRoot}/pkgs/` : "";
64
+ const tsconfigPath = `${workspaceRoot}/tsconfig.json`;
65
+ const tsconfig = JSON.parse(import_fs.default.readFileSync(tsconfigPath, "utf8"));
66
+ const paths = tsconfig.compilerOptions?.paths ?? {};
31
67
  return {
32
68
  displayName: name,
69
+ moduleNameMapper: pathsToModuleNameMapper(paths, workspaceRoot),
33
70
  globalSetup: `${akanjsPrefix}@akanjs/test/src/jest.globalSetup.ts`,
34
71
  setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/test/src/jest.setupFilesAfterEnv.ts`],
35
72
  globalTeardown: `${akanjsPrefix}@akanjs/test/src/jest.globalTeardown.ts`,
@@ -1,13 +1,39 @@
1
1
  import { config } from "dotenv";
2
+ import fs from "fs";
3
+ function pathsToModuleNameMapper(paths, workspaceRoot) {
4
+ const moduleNameMapper = {};
5
+ const sortedPaths = Object.entries(paths).sort(([a], [b]) => {
6
+ const aHasWildcard = a.includes("*");
7
+ const bHasWildcard = b.includes("*");
8
+ if (aHasWildcard === bHasWildcard)
9
+ return 0;
10
+ return aHasWildcard ? -1 : 1;
11
+ });
12
+ for (const [tsPath, targetPaths] of sortedPaths) {
13
+ const targetPath = targetPaths[0];
14
+ const escapedPath = tsPath.replace(/[.*+?^${}()|[\]\\]/g, (match) => {
15
+ return match === "*" ? match : `\\${match}`;
16
+ });
17
+ const jestPattern = `^${escapedPath.replace(/\*/g, "(.*)")}$`;
18
+ const jestReplacement = `${workspaceRoot}/${targetPath.replace(/\*/g, "$1")}`;
19
+ moduleNameMapper[jestPattern] = jestReplacement;
20
+ }
21
+ return moduleNameMapper;
22
+ }
2
23
  const withBase = (name) => {
3
24
  config();
4
25
  process.env.NEXT_PUBLIC_ENV = "testing";
5
26
  process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
6
27
  process.env.NEXT_PUBLIC_APP_NAME = name;
7
28
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
8
- const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
29
+ const workspaceRoot = process.env.AKAN_WORKSPACE_ROOT ?? process.cwd();
30
+ const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? `${workspaceRoot}/pkgs/` : "";
31
+ const tsconfigPath = `${workspaceRoot}/tsconfig.json`;
32
+ const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, "utf8"));
33
+ const paths = tsconfig.compilerOptions?.paths ?? {};
9
34
  return {
10
35
  displayName: name,
36
+ moduleNameMapper: pathsToModuleNameMapper(paths, workspaceRoot),
11
37
  globalSetup: `${akanjsPrefix}@akanjs/test/src/jest.globalSetup.ts`,
12
38
  setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/test/src/jest.setupFilesAfterEnv.ts`],
13
39
  globalTeardown: `${akanjsPrefix}@akanjs/test/src/jest.globalTeardown.ts`,
@@ -28,5 +54,6 @@ const withBase = (name) => {
28
54
  };
29
55
  };
30
56
  export {
57
+ pathsToModuleNameMapper,
31
58
  withBase
32
59
  };