@dloizides/frontend-devtools 2.5.0 → 2.6.0
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/CHANGELOG.md +10 -0
- package/README.md +16 -0
- package/dist/babel/index.d.mts +19 -0
- package/dist/babel/index.d.ts +19 -0
- package/dist/babel/index.js +24 -0
- package/dist/babel/index.js.map +1 -0
- package/dist/babel/index.mjs +22 -0
- package/dist/babel/index.mjs.map +1 -0
- package/dist/eslint/index.d.mts +47 -2
- package/dist/eslint/index.d.ts +47 -2
- package/dist/eslint/index.js +734 -41
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +734 -42
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/jest/index.d.mts +20 -0
- package/dist/jest/index.d.ts +20 -0
- package/dist/jest/index.js +63 -0
- package/dist/jest/index.js.map +1 -0
- package/dist/jest/index.mjs +60 -0
- package/dist/jest/index.mjs.map +1 -0
- package/dist/jest/setup.d.mts +2 -0
- package/dist/jest/setup.d.ts +2 -0
- package/dist/jest/setup.js +74 -0
- package/dist/jest/setup.js.map +1 -0
- package/dist/jest/setup.mjs +72 -0
- package/dist/jest/setup.mjs.map +1 -0
- package/dist/metro/index.d.mts +24 -0
- package/dist/metro/index.d.ts +24 -0
- package/dist/metro/index.js +72 -0
- package/dist/metro/index.js.map +1 -0
- package/dist/metro/index.mjs +47 -0
- package/dist/metro/index.mjs.map +1 -0
- package/dist/test-results/index.d.mts +2 -2
- package/dist/test-results/index.d.ts +2 -2
- package/dist/test-results/jestReporter.d.mts +1 -1
- package/dist/test-results/jestReporter.d.ts +1 -1
- package/dist/test-results/vitestReporter.d.mts +1 -1
- package/dist/test-results/vitestReporter.d.ts +1 -1
- package/dist/{types-9BQtbdcF.d.mts → types-DQiTmmgP.d.mts} +1 -1
- package/dist/{types-9BQtbdcF.d.ts → types-DQiTmmgP.d.ts} +1 -1
- package/package.json +42 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface CoverageThreshold {
|
|
2
|
+
branches: number;
|
|
3
|
+
functions: number;
|
|
4
|
+
lines: number;
|
|
5
|
+
statements: number;
|
|
6
|
+
}
|
|
7
|
+
interface SharedJestOptions {
|
|
8
|
+
setupFilesAfterEnv?: string[];
|
|
9
|
+
collectCoverageFrom?: string[];
|
|
10
|
+
coverageThreshold?: CoverageThreshold;
|
|
11
|
+
extraTransformModules?: string[];
|
|
12
|
+
moduleNameMapper?: Record<string, string>;
|
|
13
|
+
testEnvironment?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The `transformIgnorePatterns` entry that lets Jest compile RN/Expo packages (plus `extra`). */
|
|
16
|
+
declare function transformIgnorePattern(extra?: readonly string[]): string;
|
|
17
|
+
/** The house jest-expo config; app-specific paths and thresholds come from `options`. */
|
|
18
|
+
declare function createJestConfig(options?: SharedJestOptions): Record<string, unknown>;
|
|
19
|
+
|
|
20
|
+
export { type CoverageThreshold, type SharedJestOptions, createJestConfig, transformIgnorePattern };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface CoverageThreshold {
|
|
2
|
+
branches: number;
|
|
3
|
+
functions: number;
|
|
4
|
+
lines: number;
|
|
5
|
+
statements: number;
|
|
6
|
+
}
|
|
7
|
+
interface SharedJestOptions {
|
|
8
|
+
setupFilesAfterEnv?: string[];
|
|
9
|
+
collectCoverageFrom?: string[];
|
|
10
|
+
coverageThreshold?: CoverageThreshold;
|
|
11
|
+
extraTransformModules?: string[];
|
|
12
|
+
moduleNameMapper?: Record<string, string>;
|
|
13
|
+
testEnvironment?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The `transformIgnorePatterns` entry that lets Jest compile RN/Expo packages (plus `extra`). */
|
|
16
|
+
declare function transformIgnorePattern(extra?: readonly string[]): string;
|
|
17
|
+
/** The house jest-expo config; app-specific paths and thresholds come from `options`. */
|
|
18
|
+
declare function createJestConfig(options?: SharedJestOptions): Record<string, unknown>;
|
|
19
|
+
|
|
20
|
+
export { type CoverageThreshold, type SharedJestOptions, createJestConfig, transformIgnorePattern };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/jest/index.ts
|
|
4
|
+
var TRANSFORM_MODULES = [
|
|
5
|
+
"(jest-)?react-native",
|
|
6
|
+
"@react-native(-community)?",
|
|
7
|
+
"expo(nent)?",
|
|
8
|
+
"@expo(nent)?/.*",
|
|
9
|
+
"@expo-google-fonts/.*",
|
|
10
|
+
"react-navigation",
|
|
11
|
+
"@react-navigation/.*",
|
|
12
|
+
"@unimodules/.*",
|
|
13
|
+
"unimodules",
|
|
14
|
+
"sentry-expo",
|
|
15
|
+
"native-base",
|
|
16
|
+
"react-native-svg",
|
|
17
|
+
"react-native-paper",
|
|
18
|
+
"react-native-vector-icons",
|
|
19
|
+
"@tanstack/.*",
|
|
20
|
+
"@reduxjs/.*"
|
|
21
|
+
];
|
|
22
|
+
var DEFAULT_COVERAGE_FROM = [
|
|
23
|
+
"src/utils/**/*.{ts,tsx}",
|
|
24
|
+
"src/lib/**/*.{ts,tsx}",
|
|
25
|
+
"src/auth/**/*.{ts,tsx}",
|
|
26
|
+
"src/config/**/*.{ts,tsx}",
|
|
27
|
+
"src/store/**/*.{ts,tsx}",
|
|
28
|
+
"!src/**/*.d.ts",
|
|
29
|
+
"!src/**/index.ts",
|
|
30
|
+
"!src/server/**/*"
|
|
31
|
+
];
|
|
32
|
+
var DEFAULT_COVERAGE_PERCENT = 40;
|
|
33
|
+
function transformIgnorePattern(extra = []) {
|
|
34
|
+
const [first, second, ...rest] = [...TRANSFORM_MODULES, ...extra];
|
|
35
|
+
return `node_modules/(?!(${String(first)}|${String(second)})|${rest.join("|")})`;
|
|
36
|
+
}
|
|
37
|
+
function createJestConfig(options = {}) {
|
|
38
|
+
return {
|
|
39
|
+
preset: "jest-expo",
|
|
40
|
+
setupFilesAfterEnv: options.setupFilesAfterEnv ?? ["<rootDir>/jest.setup.js"],
|
|
41
|
+
testMatch: ["**/__tests__/**/*.test.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
|
|
42
|
+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
|
|
43
|
+
watchPathIgnorePatterns: ["/dist/", "/node_modules/", "/.expo/", "/.git/"],
|
|
44
|
+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
45
|
+
transformIgnorePatterns: [transformIgnorePattern(options.extraTransformModules)],
|
|
46
|
+
moduleNameMapper: { "^@/(.*)$": "<rootDir>/src/$1", ...options.moduleNameMapper },
|
|
47
|
+
collectCoverageFrom: options.collectCoverageFrom ?? DEFAULT_COVERAGE_FROM,
|
|
48
|
+
coverageThreshold: {
|
|
49
|
+
global: options.coverageThreshold ?? {
|
|
50
|
+
branches: DEFAULT_COVERAGE_PERCENT,
|
|
51
|
+
functions: DEFAULT_COVERAGE_PERCENT,
|
|
52
|
+
lines: DEFAULT_COVERAGE_PERCENT,
|
|
53
|
+
statements: DEFAULT_COVERAGE_PERCENT
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
testEnvironment: options.testEnvironment ?? "jsdom"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.createJestConfig = createJestConfig;
|
|
61
|
+
exports.transformIgnorePattern = transformIgnorePattern;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jest/index.ts"],"names":[],"mappings":";;;AAgBA,IAAM,iBAAA,GAAoB;AAAA,EACxB,sBAAA;AAAA,EAAwB,4BAAA;AAAA,EAA8B,aAAA;AAAA,EAAe,iBAAA;AAAA,EAAmB,uBAAA;AAAA,EACxF,kBAAA;AAAA,EAAoB,sBAAA;AAAA,EAAwB,gBAAA;AAAA,EAAkB,YAAA;AAAA,EAAc,aAAA;AAAA,EAAe,aAAA;AAAA,EAC3F,kBAAA;AAAA,E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B,GAAG,QAAQ,gBAAA,EAAiB;AAAA,IAChF,mBAAA,EAAqB,QAAQ,mBAAA,IAAuB,qBAAA;AAAA,IACpD,iBAAA,EAAmB;AAAA,MACjB,MAAA,EAAQ,QAAQ,iBAAA,IAAqB;AAAA,QACnC,QAAA,EAAU,wBAAA;AAAA,QACV,SAAA,EAAW,wBAAA;AAAA,QACX,KAAA,EAAO,wBAAA;AAAA,QACP,UAAA,EAAY;AAAA;AACd,KACF;AAAA,IACA,eAAA,EAAiB,QAAQ,eAAA,IAAmB;AAAA,GAC9C;AACF","file":"index.js","sourcesContent":["export interface CoverageThreshold {\n branches: number;\n functions: number;\n lines: number;\n statements: number;\n}\n\nexport interface SharedJestOptions {\n setupFilesAfterEnv?: string[];\n collectCoverageFrom?: string[];\n coverageThreshold?: CoverageThreshold;\n extraTransformModules?: string[];\n moduleNameMapper?: Record<string, string>;\n testEnvironment?: string;\n}\n\nconst TRANSFORM_MODULES = [\n '(jest-)?react-native', '@react-native(-community)?', 'expo(nent)?', '@expo(nent)?/.*', '@expo-google-fonts/.*',\n 'react-navigation', '@react-navigation/.*', '@unimodules/.*', 'unimodules', 'sentry-expo', 'native-base',\n 'react-native-svg', 'react-native-paper', 'react-native-vector-icons', '@tanstack/.*', '@reduxjs/.*',\n];\n\nconst DEFAULT_COVERAGE_FROM = [\n 'src/utils/**/*.{ts,tsx}',\n 'src/lib/**/*.{ts,tsx}',\n 'src/auth/**/*.{ts,tsx}',\n 'src/config/**/*.{ts,tsx}',\n 'src/store/**/*.{ts,tsx}',\n '!src/**/*.d.ts',\n '!src/**/index.ts',\n '!src/server/**/*',\n];\n\nconst DEFAULT_COVERAGE_PERCENT = 40;\n\n/** The `transformIgnorePatterns` entry that lets Jest compile RN/Expo packages (plus `extra`). */\nexport function transformIgnorePattern(extra: readonly string[] = []): string {\n const [first, second, ...rest] = [...TRANSFORM_MODULES, ...extra];\n return `node_modules/(?!(${String(first)}|${String(second)})|${rest.join('|')})`;\n}\n\n/** The house jest-expo config; app-specific paths and thresholds come from `options`. */\nexport function createJestConfig(options: SharedJestOptions = {}): Record<string, unknown> {\n return {\n preset: 'jest-expo',\n setupFilesAfterEnv: options.setupFilesAfterEnv ?? ['<rootDir>/jest.setup.js'],\n testMatch: ['**/__tests__/**/*.test.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],\n testPathIgnorePatterns: ['/node_modules/', '/dist/'],\n watchPathIgnorePatterns: ['/dist/', '/node_modules/', '/.expo/', '/.git/'],\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n transformIgnorePatterns: [transformIgnorePattern(options.extraTransformModules)],\n moduleNameMapper: { '^@/(.*)$': '<rootDir>/src/$1', ...options.moduleNameMapper },\n collectCoverageFrom: options.collectCoverageFrom ?? DEFAULT_COVERAGE_FROM,\n coverageThreshold: {\n global: options.coverageThreshold ?? {\n branches: DEFAULT_COVERAGE_PERCENT,\n functions: DEFAULT_COVERAGE_PERCENT,\n lines: DEFAULT_COVERAGE_PERCENT,\n statements: DEFAULT_COVERAGE_PERCENT,\n },\n },\n testEnvironment: options.testEnvironment ?? 'jsdom',\n };\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/jest/index.ts
|
|
2
|
+
var TRANSFORM_MODULES = [
|
|
3
|
+
"(jest-)?react-native",
|
|
4
|
+
"@react-native(-community)?",
|
|
5
|
+
"expo(nent)?",
|
|
6
|
+
"@expo(nent)?/.*",
|
|
7
|
+
"@expo-google-fonts/.*",
|
|
8
|
+
"react-navigation",
|
|
9
|
+
"@react-navigation/.*",
|
|
10
|
+
"@unimodules/.*",
|
|
11
|
+
"unimodules",
|
|
12
|
+
"sentry-expo",
|
|
13
|
+
"native-base",
|
|
14
|
+
"react-native-svg",
|
|
15
|
+
"react-native-paper",
|
|
16
|
+
"react-native-vector-icons",
|
|
17
|
+
"@tanstack/.*",
|
|
18
|
+
"@reduxjs/.*"
|
|
19
|
+
];
|
|
20
|
+
var DEFAULT_COVERAGE_FROM = [
|
|
21
|
+
"src/utils/**/*.{ts,tsx}",
|
|
22
|
+
"src/lib/**/*.{ts,tsx}",
|
|
23
|
+
"src/auth/**/*.{ts,tsx}",
|
|
24
|
+
"src/config/**/*.{ts,tsx}",
|
|
25
|
+
"src/store/**/*.{ts,tsx}",
|
|
26
|
+
"!src/**/*.d.ts",
|
|
27
|
+
"!src/**/index.ts",
|
|
28
|
+
"!src/server/**/*"
|
|
29
|
+
];
|
|
30
|
+
var DEFAULT_COVERAGE_PERCENT = 40;
|
|
31
|
+
function transformIgnorePattern(extra = []) {
|
|
32
|
+
const [first, second, ...rest] = [...TRANSFORM_MODULES, ...extra];
|
|
33
|
+
return `node_modules/(?!(${String(first)}|${String(second)})|${rest.join("|")})`;
|
|
34
|
+
}
|
|
35
|
+
function createJestConfig(options = {}) {
|
|
36
|
+
return {
|
|
37
|
+
preset: "jest-expo",
|
|
38
|
+
setupFilesAfterEnv: options.setupFilesAfterEnv ?? ["<rootDir>/jest.setup.js"],
|
|
39
|
+
testMatch: ["**/__tests__/**/*.test.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
|
|
40
|
+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
|
|
41
|
+
watchPathIgnorePatterns: ["/dist/", "/node_modules/", "/.expo/", "/.git/"],
|
|
42
|
+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
43
|
+
transformIgnorePatterns: [transformIgnorePattern(options.extraTransformModules)],
|
|
44
|
+
moduleNameMapper: { "^@/(.*)$": "<rootDir>/src/$1", ...options.moduleNameMapper },
|
|
45
|
+
collectCoverageFrom: options.collectCoverageFrom ?? DEFAULT_COVERAGE_FROM,
|
|
46
|
+
coverageThreshold: {
|
|
47
|
+
global: options.coverageThreshold ?? {
|
|
48
|
+
branches: DEFAULT_COVERAGE_PERCENT,
|
|
49
|
+
functions: DEFAULT_COVERAGE_PERCENT,
|
|
50
|
+
lines: DEFAULT_COVERAGE_PERCENT,
|
|
51
|
+
statements: DEFAULT_COVERAGE_PERCENT
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
testEnvironment: options.testEnvironment ?? "jsdom"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { createJestConfig, transformIgnorePattern };
|
|
59
|
+
//# sourceMappingURL=index.mjs.map
|
|
60
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jest/index.ts"],"names":[],"mappings":";AAgBA,IAAM,iBAAA,GAAoB;AAAA,EACxB,sBAAA;AAAA,EAAwB,4BAAA;AAAA,EAA8B,aAAA;AAAA,EAAe,iBAAA;AAAA,EAAmB,uBAAA;AAAA,EACxF,kBAAA;AAAA,EAAoB,sBAAA;AAAA,EAAwB,gBAAA;AAAA,EAAkB,YAAA;AAAA,EAAc,aAAA;AAAA,EAAe,aAAA;AAAA,EAC3F,kBAAA;AAAA,EAAoB,oBAAA;AAAA,EAAsB,2BAAA;AAAA,EAA6B,cAAA;AAAA,EAAgB;AACzF,CAAA;AAEA,IAAM,qBAAA,GAAwB;AAAA,EAC5B,yBAAA;AAAA,EACA,uBAAA;AAAA,EACA,wBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AAAA,EACA,gBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,wBAAA,GAA2B,EAAA;AAG1B,SAAS,sBAAA,CAAuB,KAAA,GAA2B,EAAC,EAAW;AAC5E,EAAA,MAAM,CAAC,KAAA,EAAO,MAAA,EAAQ,GAAG,IAAI,IAAI,CAAC,GAAG,iBAAA,EAAmB,GAAG,KAAK,CAAA;AAChE,EAAA,OAAO,CAAA,iBAAA,EAAoB,MAAA,CAAO,KAAK,CAAC,CAAA,CAAA,EAAI,MAAA,CAAO,MAAM,CAAC,CAAA,EAAA,EAAK,IAAA,CAAK,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AAC/E;AAGO,SAAS,gBAAA,CAAiB,OAAA,GAA6B,EAAC,EAA4B;AACzF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,WAAA;AAAA,IACR,kBAAA,EAAoB,OAAA,CAAQ,kBAAA,IAAsB,CAAC,yBAAyB,CAAA;AAAA,IAC5E,SAAA,EAAW,CAAC,kCAAA,EAAoC,gCAAgC,CAAA;AAAA,IAChF,sBAAA,EAAwB,CAAC,gBAAA,EAAkB,QAAQ,CAAA;AAAA,IACnD,uBAAA,EAAyB,CAAC,QAAA,EAAU,gBAAA,EAAkB,WAAW,QAAQ,CAAA;AAAA,IACzE,sBAAsB,CAAC,IAAA,EAAM,OAAO,IAAA,EAAM,KAAA,EAAO,QAAQ,MAAM,CAAA;AAAA,IAC/D,uBAAA,EAAyB,CAAC,sBAAA,CAAuB,OAAA,CAAQ,qBAAqB,CAAC,CAAA;AAAA,IAC/E,kBAAkB,EAAE,UAAA,EAAY,kBAAA,EAAoB,GAAG,QAAQ,gBAAA,EAAiB;AAAA,IAChF,mBAAA,EAAqB,QAAQ,mBAAA,IAAuB,qBAAA;AAAA,IACpD,iBAAA,EAAmB;AAAA,MACjB,MAAA,EAAQ,QAAQ,iBAAA,IAAqB;AAAA,QACnC,QAAA,EAAU,wBAAA;AAAA,QACV,SAAA,EAAW,wBAAA;AAAA,QACX,KAAA,EAAO,wBAAA;AAAA,QACP,UAAA,EAAY;AAAA;AACd,KACF;AAAA,IACA,eAAA,EAAiB,QAAQ,eAAA,IAAmB;AAAA,GAC9C;AACF","file":"index.mjs","sourcesContent":["export interface CoverageThreshold {\n branches: number;\n functions: number;\n lines: number;\n statements: number;\n}\n\nexport interface SharedJestOptions {\n setupFilesAfterEnv?: string[];\n collectCoverageFrom?: string[];\n coverageThreshold?: CoverageThreshold;\n extraTransformModules?: string[];\n moduleNameMapper?: Record<string, string>;\n testEnvironment?: string;\n}\n\nconst TRANSFORM_MODULES = [\n '(jest-)?react-native', '@react-native(-community)?', 'expo(nent)?', '@expo(nent)?/.*', '@expo-google-fonts/.*',\n 'react-navigation', '@react-navigation/.*', '@unimodules/.*', 'unimodules', 'sentry-expo', 'native-base',\n 'react-native-svg', 'react-native-paper', 'react-native-vector-icons', '@tanstack/.*', '@reduxjs/.*',\n];\n\nconst DEFAULT_COVERAGE_FROM = [\n 'src/utils/**/*.{ts,tsx}',\n 'src/lib/**/*.{ts,tsx}',\n 'src/auth/**/*.{ts,tsx}',\n 'src/config/**/*.{ts,tsx}',\n 'src/store/**/*.{ts,tsx}',\n '!src/**/*.d.ts',\n '!src/**/index.ts',\n '!src/server/**/*',\n];\n\nconst DEFAULT_COVERAGE_PERCENT = 40;\n\n/** The `transformIgnorePatterns` entry that lets Jest compile RN/Expo packages (plus `extra`). */\nexport function transformIgnorePattern(extra: readonly string[] = []): string {\n const [first, second, ...rest] = [...TRANSFORM_MODULES, ...extra];\n return `node_modules/(?!(${String(first)}|${String(second)})|${rest.join('|')})`;\n}\n\n/** The house jest-expo config; app-specific paths and thresholds come from `options`. */\nexport function createJestConfig(options: SharedJestOptions = {}): Record<string, unknown> {\n return {\n preset: 'jest-expo',\n setupFilesAfterEnv: options.setupFilesAfterEnv ?? ['<rootDir>/jest.setup.js'],\n testMatch: ['**/__tests__/**/*.test.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],\n testPathIgnorePatterns: ['/node_modules/', '/dist/'],\n watchPathIgnorePatterns: ['/dist/', '/node_modules/', '/.expo/', '/.git/'],\n moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],\n transformIgnorePatterns: [transformIgnorePattern(options.extraTransformModules)],\n moduleNameMapper: { '^@/(.*)$': '<rootDir>/src/$1', ...options.moduleNameMapper },\n collectCoverageFrom: options.collectCoverageFrom ?? DEFAULT_COVERAGE_FROM,\n coverageThreshold: {\n global: options.coverageThreshold ?? {\n branches: DEFAULT_COVERAGE_PERCENT,\n functions: DEFAULT_COVERAGE_PERCENT,\n lines: DEFAULT_COVERAGE_PERCENT,\n statements: DEFAULT_COVERAGE_PERCENT,\n },\n },\n testEnvironment: options.testEnvironment ?? 'jsdom',\n };\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/jest/mocks.ts
|
|
4
|
+
function modalFactory(jestApi) {
|
|
5
|
+
return () => {
|
|
6
|
+
const React = jestApi.requireActual("react");
|
|
7
|
+
const { View } = jestApi.requireActual("react-native");
|
|
8
|
+
const MockModal = ({ children, visible, testID }) => visible === true ? React.createElement(View, { testID }, children) : null;
|
|
9
|
+
return { default: MockModal, __esModule: true };
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function switchFactory(jestApi) {
|
|
13
|
+
return () => createSwitchMock(jestApi.requireActual("react"), jestApi.requireActual("react-native"));
|
|
14
|
+
}
|
|
15
|
+
function createSwitchMock(React, ReactNative) {
|
|
16
|
+
const MockSwitch = (props) => {
|
|
17
|
+
const { value, testID, disabled, accessibilityLabel, accessibilityHint, onValueChange } = props;
|
|
18
|
+
const handlePress = () => {
|
|
19
|
+
if (disabled !== true && typeof onValueChange === "function") {
|
|
20
|
+
onValueChange(value !== true);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return React.createElement(
|
|
24
|
+
ReactNative.View,
|
|
25
|
+
{
|
|
26
|
+
accessibilityRole: "switch",
|
|
27
|
+
accessibilityLabel,
|
|
28
|
+
accessibilityHint,
|
|
29
|
+
disabled,
|
|
30
|
+
testID,
|
|
31
|
+
value,
|
|
32
|
+
accessible: true,
|
|
33
|
+
onPress: handlePress,
|
|
34
|
+
onTouchEnd: handlePress
|
|
35
|
+
},
|
|
36
|
+
React.createElement(ReactNative.Text, null, value === true ? "ON" : "OFF")
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
return { default: MockSwitch, __esModule: true };
|
|
40
|
+
}
|
|
41
|
+
function storageMocks(jestApi) {
|
|
42
|
+
jestApi.mock("expo-constants", () => ({ expoConfig: { extra: { env: "test" } } }));
|
|
43
|
+
jestApi.mock("expo-secure-store", () => ({
|
|
44
|
+
getItemAsync: jestApi.fn(async () => Promise.resolve(null)),
|
|
45
|
+
setItemAsync: jestApi.fn(async () => Promise.resolve()),
|
|
46
|
+
deleteItemAsync: jestApi.fn(async () => Promise.resolve())
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
function i18nMocks(jestApi) {
|
|
50
|
+
jestApi.mock("react-i18next", () => ({
|
|
51
|
+
initReactI18next: { type: "3rdParty", init: jestApi.fn() },
|
|
52
|
+
useTranslation: () => ({ t: (key) => key, i18n: { changeLanguage: jestApi.fn() } }),
|
|
53
|
+
I18nextProvider: ({ children }) => children
|
|
54
|
+
}));
|
|
55
|
+
jestApi.mock("expo-localization", () => ({ getLocales: jestApi.fn(() => [{ languageCode: "en" }]) }));
|
|
56
|
+
}
|
|
57
|
+
function installSharedJestMocks(jestApi, host) {
|
|
58
|
+
storageMocks(jestApi);
|
|
59
|
+
jestApi.mock("react-native/Libraries/Modal/Modal", modalFactory(jestApi));
|
|
60
|
+
jestApi.mock("react-native/Libraries/Components/Switch/Switch", switchFactory(jestApi));
|
|
61
|
+
i18nMocks(jestApi);
|
|
62
|
+
host.console = {
|
|
63
|
+
...host.console,
|
|
64
|
+
debug: jestApi.fn(),
|
|
65
|
+
info: jestApi.fn(),
|
|
66
|
+
warn: jestApi.fn(),
|
|
67
|
+
error: jestApi.fn()
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/jest/setup.ts
|
|
72
|
+
installSharedJestMocks(jest, globalThis);
|
|
73
|
+
//# sourceMappingURL=setup.js.map
|
|
74
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jest/mocks.ts","../../src/jest/setup.ts"],"names":[],"mappings":";;;AAsBA,SAAS,aAAa,OAAA,EAA4B;AAChD,EAAA,OAAO,MAAM;AAC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E,YAAA,EAAc,IAAA,EAAM,CAAC,GAAE,CAAE,CAAA;AACtG;AAGO,SAAS,sBAAA,CAAuB,SAAmB,IAAA,EAAyB;AACjF,EAAA,YAAA,CAAa,OAAO,CAAA;AACpB,EAAA,OAAA,CAAQ,IAAA,CAAK,oCAAA,EAAsC,YAAA,CAAa,OAAO,CAAC,CAAA;AACxE,EAAA,OAAA,CAAQ,IAAA,CAAK,iDAAA,EAAmD,aAAA,CAAc,OAAO,CAAC,CAAA;AACtF,EAAA,SAAA,CAAU,OAAO,CAAA;AACjB,EAAA,IAAA,CAAK,OAAA,GAAU;AAAA,IACb,GAAG,IAAA,CAAK,OAAA;AAAA,IACR,KAAA,EAAO,QAAQ,EAAA,EAAG;AAAA,IAClB,IAAA,EAAM,QAAQ,EAAA,EAAG;AAAA,IACjB,IAAA,EAAM,QAAQ,EAAA,EAAG;AAAA,IACjB,KAAA,EAAO,QAAQ,EAAA;AAAG,GACpB;AACF;;;ACrFA,sBAAA,CAAuB,MAAM,UAAU,CAAA","file":"setup.js","sourcesContent":["type Factory = () => unknown;\ntype Props = Record<string, unknown>;\n\ninterface ReactLike {\n createElement: (type: unknown, props: Props | null, ...children: unknown[]) => unknown;\n}\n\ninterface ReactNativeLike {\n View: unknown;\n Text: unknown;\n}\n\nexport interface JestLike {\n mock: (moduleName: string, factory: Factory) => unknown;\n fn: (implementation?: (...args: never[]) => unknown) => unknown;\n requireActual: (moduleName: string) => unknown;\n}\n\nexport interface ConsoleHost {\n console: Console;\n}\n\nfunction modalFactory(jestApi: JestLike): Factory {\n return () => {\n const React = jestApi.requireActual('react') as ReactLike;\n const { View } = jestApi.requireActual('react-native') as ReactNativeLike;\n const MockModal = ({ children, visible, testID }: Props): unknown =>\n visible === true ? React.createElement(View, { testID }, children) : null;\n return { default: MockModal, __esModule: true };\n };\n}\n\nfunction switchFactory(jestApi: JestLike): Factory {\n return () => createSwitchMock(jestApi.requireActual('react') as ReactLike, jestApi.requireActual('react-native') as ReactNativeLike);\n}\n\nfunction createSwitchMock(React: ReactLike, ReactNative: ReactNativeLike): unknown {\n const MockSwitch = (props: Props): unknown => {\n const { value, testID, disabled, accessibilityLabel, accessibilityHint, onValueChange } = props;\n const handlePress = (): void => {\n if (disabled !== true && typeof onValueChange === 'function') {\n onValueChange(value !== true);\n }\n };\n return React.createElement(\n ReactNative.View,\n {\n accessibilityRole: 'switch', accessibilityLabel, accessibilityHint, disabled, testID, value,\n accessible: true, onPress: handlePress, onTouchEnd: handlePress,\n },\n React.createElement(ReactNative.Text, null, value === true ? 'ON' : 'OFF'),\n );\n };\n return { default: MockSwitch, __esModule: true };\n}\n\nfunction storageMocks(jestApi: JestLike): void {\n jestApi.mock('expo-constants', () => ({ expoConfig: { extra: { env: 'test' } } }));\n jestApi.mock('expo-secure-store', () => ({\n getItemAsync: jestApi.fn(async () => Promise.resolve(null)),\n setItemAsync: jestApi.fn(async () => Promise.resolve()),\n deleteItemAsync: jestApi.fn(async () => Promise.resolve()),\n }));\n}\n\nfunction i18nMocks(jestApi: JestLike): void {\n jestApi.mock('react-i18next', () => ({\n initReactI18next: { type: '3rdParty', init: jestApi.fn() },\n useTranslation: (): { t: (key: string) => string; i18n: unknown } => ({ t: (key: string): string => key, i18n: { changeLanguage: jestApi.fn() } }),\n I18nextProvider: ({ children }: { children: unknown }): unknown => children,\n }));\n jestApi.mock('expo-localization', () => ({ getLocales: jestApi.fn(() => [{ languageCode: 'en' }]) }));\n}\n\n/** Registers the house Expo test mocks and silences console noise; apps add their own after it. */\nexport function installSharedJestMocks(jestApi: JestLike, host: ConsoleHost): void {\n storageMocks(jestApi);\n jestApi.mock('react-native/Libraries/Modal/Modal', modalFactory(jestApi));\n jestApi.mock('react-native/Libraries/Components/Switch/Switch', switchFactory(jestApi));\n i18nMocks(jestApi);\n host.console = {\n ...host.console,\n debug: jestApi.fn() as Console['debug'],\n info: jestApi.fn() as Console['info'],\n warn: jestApi.fn() as Console['warn'],\n error: jestApi.fn() as Console['error'],\n };\n}\n","import { installSharedJestMocks } from './mocks';\n\ninstallSharedJestMocks(jest, globalThis);\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/jest/mocks.ts
|
|
2
|
+
function modalFactory(jestApi) {
|
|
3
|
+
return () => {
|
|
4
|
+
const React = jestApi.requireActual("react");
|
|
5
|
+
const { View } = jestApi.requireActual("react-native");
|
|
6
|
+
const MockModal = ({ children, visible, testID }) => visible === true ? React.createElement(View, { testID }, children) : null;
|
|
7
|
+
return { default: MockModal, __esModule: true };
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function switchFactory(jestApi) {
|
|
11
|
+
return () => createSwitchMock(jestApi.requireActual("react"), jestApi.requireActual("react-native"));
|
|
12
|
+
}
|
|
13
|
+
function createSwitchMock(React, ReactNative) {
|
|
14
|
+
const MockSwitch = (props) => {
|
|
15
|
+
const { value, testID, disabled, accessibilityLabel, accessibilityHint, onValueChange } = props;
|
|
16
|
+
const handlePress = () => {
|
|
17
|
+
if (disabled !== true && typeof onValueChange === "function") {
|
|
18
|
+
onValueChange(value !== true);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return React.createElement(
|
|
22
|
+
ReactNative.View,
|
|
23
|
+
{
|
|
24
|
+
accessibilityRole: "switch",
|
|
25
|
+
accessibilityLabel,
|
|
26
|
+
accessibilityHint,
|
|
27
|
+
disabled,
|
|
28
|
+
testID,
|
|
29
|
+
value,
|
|
30
|
+
accessible: true,
|
|
31
|
+
onPress: handlePress,
|
|
32
|
+
onTouchEnd: handlePress
|
|
33
|
+
},
|
|
34
|
+
React.createElement(ReactNative.Text, null, value === true ? "ON" : "OFF")
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
return { default: MockSwitch, __esModule: true };
|
|
38
|
+
}
|
|
39
|
+
function storageMocks(jestApi) {
|
|
40
|
+
jestApi.mock("expo-constants", () => ({ expoConfig: { extra: { env: "test" } } }));
|
|
41
|
+
jestApi.mock("expo-secure-store", () => ({
|
|
42
|
+
getItemAsync: jestApi.fn(async () => Promise.resolve(null)),
|
|
43
|
+
setItemAsync: jestApi.fn(async () => Promise.resolve()),
|
|
44
|
+
deleteItemAsync: jestApi.fn(async () => Promise.resolve())
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
function i18nMocks(jestApi) {
|
|
48
|
+
jestApi.mock("react-i18next", () => ({
|
|
49
|
+
initReactI18next: { type: "3rdParty", init: jestApi.fn() },
|
|
50
|
+
useTranslation: () => ({ t: (key) => key, i18n: { changeLanguage: jestApi.fn() } }),
|
|
51
|
+
I18nextProvider: ({ children }) => children
|
|
52
|
+
}));
|
|
53
|
+
jestApi.mock("expo-localization", () => ({ getLocales: jestApi.fn(() => [{ languageCode: "en" }]) }));
|
|
54
|
+
}
|
|
55
|
+
function installSharedJestMocks(jestApi, host) {
|
|
56
|
+
storageMocks(jestApi);
|
|
57
|
+
jestApi.mock("react-native/Libraries/Modal/Modal", modalFactory(jestApi));
|
|
58
|
+
jestApi.mock("react-native/Libraries/Components/Switch/Switch", switchFactory(jestApi));
|
|
59
|
+
i18nMocks(jestApi);
|
|
60
|
+
host.console = {
|
|
61
|
+
...host.console,
|
|
62
|
+
debug: jestApi.fn(),
|
|
63
|
+
info: jestApi.fn(),
|
|
64
|
+
warn: jestApi.fn(),
|
|
65
|
+
error: jestApi.fn()
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/jest/setup.ts
|
|
70
|
+
installSharedJestMocks(jest, globalThis);
|
|
71
|
+
//# sourceMappingURL=setup.mjs.map
|
|
72
|
+
//# sourceMappingURL=setup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jest/mocks.ts","../../src/jest/setup.ts"],"names":[],"mappings":";AAsBA,SAAS,aAAa,OAAA,EAA4B;AAChD,EAAA,OAAO,MAAM;AACX,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,aAAA,CAAc,OAAO,CAAA;AAC3C,IA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,CAAuB,SAAmB,IAAA,EAAyB;AACjF,EAAA,YAAA,CAAa,OAAO,CAAA;AACpB,EAAA,OAAA,CAAQ,IAAA,CAAK,oCAAA,EAAsC,YAAA,CAAa,OAAO,CAAC,CAAA;AACxE,EAAA,OAAA,CAAQ,IAAA,CAAK,iDAAA,EAAmD,aAAA,CAAc,OAAO,CAAC,CAAA;AACtF,EAAA,SAAA,CAAU,OAAO,CAAA;AACjB,EAAA,IAAA,CAAK,OAAA,GAAU;AAAA,IACb,GAAG,IAAA,CAAK,OAAA;AAAA,IACR,KAAA,EAAO,QAAQ,EAAA,EAAG;AAAA,IAClB,IAAA,EAAM,QAAQ,EAAA,EAAG;AAAA,IACjB,IAAA,EAAM,QAAQ,EAAA,EAAG;AAAA,IACjB,KAAA,EAAO,QAAQ,EAAA;AAAG,GACpB;AACF;;;ACrFA,sBAAA,CAAuB,MAAM,UAAU,CAAA","file":"setup.mjs","sourcesContent":["type Factory = () => unknown;\ntype Props = Record<string, unknown>;\n\ninterface ReactLike {\n createElement: (type: unknown, props: Props | null, ...children: unknown[]) => unknown;\n}\n\ninterface ReactNativeLike {\n View: unknown;\n Text: unknown;\n}\n\nexport interface JestLike {\n mock: (moduleName: string, factory: Factory) => unknown;\n fn: (implementation?: (...args: never[]) => unknown) => unknown;\n requireActual: (moduleName: string) => unknown;\n}\n\nexport interface ConsoleHost {\n console: Console;\n}\n\nfunction modalFactory(jestApi: JestLike): Factory {\n return () => {\n const React = jestApi.requireActual('react') as ReactLike;\n const { View } = jestApi.requireActual('react-native') as ReactNativeLike;\n const MockModal = ({ children, visible, testID }: Props): unknown =>\n visible === true ? React.createElement(View, { testID }, children) : null;\n return { default: MockModal, __esModule: true };\n };\n}\n\nfunction switchFactory(jestApi: JestLike): Factory {\n return () => createSwitchMock(jestApi.requireActual('react') as ReactLike, jestApi.requireActual('react-native') as ReactNativeLike);\n}\n\nfunction createSwitchMock(React: ReactLike, ReactNative: ReactNativeLike): unknown {\n const MockSwitch = (props: Props): unknown => {\n const { value, testID, disabled, accessibilityLabel, accessibilityHint, onValueChange } = props;\n const handlePress = (): void => {\n if (disabled !== true && typeof onValueChange === 'function') {\n onValueChange(value !== true);\n }\n };\n return React.createElement(\n ReactNative.View,\n {\n accessibilityRole: 'switch', accessibilityLabel, accessibilityHint, disabled, testID, value,\n accessible: true, onPress: handlePress, onTouchEnd: handlePress,\n },\n React.createElement(ReactNative.Text, null, value === true ? 'ON' : 'OFF'),\n );\n };\n return { default: MockSwitch, __esModule: true };\n}\n\nfunction storageMocks(jestApi: JestLike): void {\n jestApi.mock('expo-constants', () => ({ expoConfig: { extra: { env: 'test' } } }));\n jestApi.mock('expo-secure-store', () => ({\n getItemAsync: jestApi.fn(async () => Promise.resolve(null)),\n setItemAsync: jestApi.fn(async () => Promise.resolve()),\n deleteItemAsync: jestApi.fn(async () => Promise.resolve()),\n }));\n}\n\nfunction i18nMocks(jestApi: JestLike): void {\n jestApi.mock('react-i18next', () => ({\n initReactI18next: { type: '3rdParty', init: jestApi.fn() },\n useTranslation: (): { t: (key: string) => string; i18n: unknown } => ({ t: (key: string): string => key, i18n: { changeLanguage: jestApi.fn() } }),\n I18nextProvider: ({ children }: { children: unknown }): unknown => children,\n }));\n jestApi.mock('expo-localization', () => ({ getLocales: jestApi.fn(() => [{ languageCode: 'en' }]) }));\n}\n\n/** Registers the house Expo test mocks and silences console noise; apps add their own after it. */\nexport function installSharedJestMocks(jestApi: JestLike, host: ConsoleHost): void {\n storageMocks(jestApi);\n jestApi.mock('react-native/Libraries/Modal/Modal', modalFactory(jestApi));\n jestApi.mock('react-native/Libraries/Components/Switch/Switch', switchFactory(jestApi));\n i18nMocks(jestApi);\n host.console = {\n ...host.console,\n debug: jestApi.fn() as Console['debug'],\n info: jestApi.fn() as Console['info'],\n warn: jestApi.fn() as Console['warn'],\n error: jestApi.fn() as Console['error'],\n };\n}\n","import { installSharedJestMocks } from './mocks';\n\ninstallSharedJestMocks(jest, globalThis);\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface MetroResolution {
|
|
2
|
+
filePath?: string;
|
|
3
|
+
type: string;
|
|
4
|
+
}
|
|
5
|
+
interface MetroResolveContext {
|
|
6
|
+
resolveRequest: (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;
|
|
7
|
+
}
|
|
8
|
+
type MetroResolveRequest = (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;
|
|
9
|
+
interface MetroConfigLike {
|
|
10
|
+
resolver?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface SharedMetroOptions {
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
blockedDirs?: string[];
|
|
15
|
+
srcDir?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Regexes that keep Metro's watcher out of build-output dirs (Windows symlink lstat errors). */
|
|
18
|
+
declare function buildBlockList(projectRoot: string, dirs?: readonly string[]): RegExp[];
|
|
19
|
+
/** Resolver that maps `@/` to src and forces react / react-dom to the host app's single copy. */
|
|
20
|
+
declare function createResolveRequest(projectRoot: string, srcDir?: string): MetroResolveRequest;
|
|
21
|
+
/** Applies the house resolver settings to the config from expo's `getDefaultConfig(projectRoot)`. */
|
|
22
|
+
declare function withSharedMetroConfig<T extends MetroConfigLike>(config: T, options: SharedMetroOptions): T;
|
|
23
|
+
|
|
24
|
+
export { type MetroConfigLike, type MetroResolution, type MetroResolveContext, type MetroResolveRequest, type SharedMetroOptions, buildBlockList, createResolveRequest, withSharedMetroConfig };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface MetroResolution {
|
|
2
|
+
filePath?: string;
|
|
3
|
+
type: string;
|
|
4
|
+
}
|
|
5
|
+
interface MetroResolveContext {
|
|
6
|
+
resolveRequest: (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;
|
|
7
|
+
}
|
|
8
|
+
type MetroResolveRequest = (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;
|
|
9
|
+
interface MetroConfigLike {
|
|
10
|
+
resolver?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface SharedMetroOptions {
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
blockedDirs?: string[];
|
|
15
|
+
srcDir?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Regexes that keep Metro's watcher out of build-output dirs (Windows symlink lstat errors). */
|
|
18
|
+
declare function buildBlockList(projectRoot: string, dirs?: readonly string[]): RegExp[];
|
|
19
|
+
/** Resolver that maps `@/` to src and forces react / react-dom to the host app's single copy. */
|
|
20
|
+
declare function createResolveRequest(projectRoot: string, srcDir?: string): MetroResolveRequest;
|
|
21
|
+
/** Applies the house resolver settings to the config from expo's `getDefaultConfig(projectRoot)`. */
|
|
22
|
+
declare function withSharedMetroConfig<T extends MetroConfigLike>(config: T, options: SharedMetroOptions): T;
|
|
23
|
+
|
|
24
|
+
export { type MetroConfigLike, type MetroResolution, type MetroResolveContext, type MetroResolveRequest, type SharedMetroOptions, buildBlockList, createResolveRequest, withSharedMetroConfig };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
25
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
26
|
+
|
|
27
|
+
// src/metro/index.ts
|
|
28
|
+
var DEFAULT_BLOCKED_DIRS = ["dist", "coverage", "lighthouse-reports"];
|
|
29
|
+
var ALIAS_PREFIX = "@/";
|
|
30
|
+
var ALIAS_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".json", "/index.ts", "/index.tsx", "/index.js"];
|
|
31
|
+
function buildBlockList(projectRoot, dirs = DEFAULT_BLOCKED_DIRS) {
|
|
32
|
+
return dirs.map((dir) => path__namespace.join(projectRoot, dir)).map((p) => new RegExp(`^${p.replace(/\\/g, "\\\\").replace(/\//g, "[\\\\/]")}.*`));
|
|
33
|
+
}
|
|
34
|
+
function resolveAlias(projectRoot, srcDir, moduleName) {
|
|
35
|
+
const basePath = path__namespace.join(projectRoot, srcDir, moduleName.slice(ALIAS_PREFIX.length));
|
|
36
|
+
const filePath = ALIAS_EXTENSIONS.map((ext) => basePath + ext).find((candidate) => fs__namespace.existsSync(candidate));
|
|
37
|
+
return filePath === void 0 ? void 0 : { filePath, type: "sourceFile" };
|
|
38
|
+
}
|
|
39
|
+
function resolveHostCopy(projectRoot, packageName, moduleName) {
|
|
40
|
+
if (moduleName !== packageName && !moduleName.startsWith(`${packageName}/`)) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
const hostPath = path__namespace.join(projectRoot, "node_modules", packageName);
|
|
44
|
+
const file = moduleName === packageName ? "index.js" : `${moduleName.replace(`${packageName}/`, "")}.js`;
|
|
45
|
+
return { filePath: path__namespace.join(hostPath, file), type: "sourceFile" };
|
|
46
|
+
}
|
|
47
|
+
function createResolveRequest(projectRoot, srcDir = "src") {
|
|
48
|
+
return (context, moduleName, platform) => {
|
|
49
|
+
const aliased = moduleName.startsWith(ALIAS_PREFIX) ? resolveAlias(projectRoot, srcDir, moduleName) : void 0;
|
|
50
|
+
return aliased ?? resolveHostCopy(projectRoot, "react", moduleName) ?? resolveHostCopy(projectRoot, "react-dom", moduleName) ?? context.resolveRequest(context, moduleName, platform);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function withSharedMetroConfig(config, options) {
|
|
54
|
+
const { projectRoot } = options;
|
|
55
|
+
return {
|
|
56
|
+
...config,
|
|
57
|
+
resolver: {
|
|
58
|
+
...config.resolver,
|
|
59
|
+
unstable_enableSymlinks: true,
|
|
60
|
+
unstable_enablePackageExports: true,
|
|
61
|
+
blockList: buildBlockList(projectRoot, options.blockedDirs),
|
|
62
|
+
nodeModulesPaths: [path__namespace.join(projectRoot, "node_modules")],
|
|
63
|
+
resolveRequest: createResolveRequest(projectRoot, options.srcDir)
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.buildBlockList = buildBlockList;
|
|
69
|
+
exports.createResolveRequest = createResolveRequest;
|
|
70
|
+
exports.withSharedMetroConfig = withSharedMetroConfig;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/metro/index.ts"],"names":["path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAM,oBAAA,GAAuB,CAAC,MAAA,EAAQ,UAAA,EAAY,oBAAoB,CAAA;AACtE,IAAM,YAAA,GAAe,IAAA;AACrB,IAAM,gBAAA,GAAmB,CAAC,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA,EAAQ,OAAA,EAAS,WAAA,EAAa,YAAA,EAAc,WAAW,CAAA;AAGhG,SAAS,cAAA,CAAe,WAAA,EAAqB,IAAA,GAA0B,oBAAA,EAAgC;AAC5G,EAAA,OAAO,IAAA,CACJ,GAAA,CAAI,CAAC,GAAA,KAAaA,eAAA,CAAA,IAAA,CAAK,aAAa,GAAG,CAAC,CAAA,CACxC,GAAA,CAAI,CAAC,CAAA,KAAM,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,CAAA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O,CAAC,OAAA,EAA8B,UAAA,EAAoB,QAAA,KAA6C;AACrG,IAAA,MAAM,OAAA,GAAU,WAAW,UAAA,CAAW,YAAY,IAAI,YAAA,CAAa,WAAA,EAAa,MAAA,EAAQ,UAAU,CAAA,GAAI,MAAA;AACtG,IAAA,OAAO,OAAA,IACF,eAAA,CAAgB,WAAA,EAAa,OAAA,EAAS,UAAU,CAAA,IAChD,eAAA,CAAgB,WAAA,EAAa,WAAA,EAAa,UAAU,CAAA,IACpD,OAAA,CAAQ,cAAA,CAAe,OAAA,EAAS,YAAY,QAAQ,CAAA;AAAA,EAC3D,CAAA;AACF;AAGO,SAAS,qBAAA,CAAiD,QAAW,OAAA,EAAgC;AAC1G,EAAA,MAAM,EAAE,aAAY,GAAI,OAAA;AACxB,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,QAAA,EAAU;AAAA,MACR,GAAG,MAAA,CAAO,QAAA;AAAA,MACV,uBAAA,EAAyB,IAAA;AAAA,MACzB,6BAAA,EAA+B,IAAA;AAAA,MAC/B,SAAA,EAAW,cAAA,CAAe,WAAA,EAAa,OAAA,CAAQ,WAAW,CAAA;AAAA,MAC1D,gBAAA,EAAkB,CAAMA,eAAA,CAAA,IAAA,CAAK,WAAA,EAAa,cAAc,CAAC,CAAA;AAAA,MACzD,cAAA,EAAgB,oBAAA,CAAqB,WAAA,EAAa,OAAA,CAAQ,MAAM;AAAA;AAClE,GACF;AACF","file":"index.js","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface MetroResolution {\n filePath?: string;\n type: string;\n}\n\nexport interface MetroResolveContext {\n resolveRequest: (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;\n}\n\nexport type MetroResolveRequest = (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;\n\nexport interface MetroConfigLike {\n resolver?: Record<string, unknown>;\n}\n\nexport interface SharedMetroOptions {\n projectRoot: string;\n blockedDirs?: string[];\n srcDir?: string;\n}\n\nconst DEFAULT_BLOCKED_DIRS = ['dist', 'coverage', 'lighthouse-reports'];\nconst ALIAS_PREFIX = '@/';\nconst ALIAS_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.json', '/index.ts', '/index.tsx', '/index.js'];\n\n/** Regexes that keep Metro's watcher out of build-output dirs (Windows symlink lstat errors). */\nexport function buildBlockList(projectRoot: string, dirs: readonly string[] = DEFAULT_BLOCKED_DIRS): RegExp[] {\n return dirs\n .map((dir) => path.join(projectRoot, dir))\n .map((p) => new RegExp(`^${p.replace(/\\\\/g, '\\\\\\\\').replace(/\\//g, '[\\\\\\\\/]')}.*`));\n}\n\nfunction resolveAlias(projectRoot: string, srcDir: string, moduleName: string): MetroResolution | undefined {\n const basePath = path.join(projectRoot, srcDir, moduleName.slice(ALIAS_PREFIX.length));\n const filePath = ALIAS_EXTENSIONS.map((ext) => basePath + ext).find((candidate) => fs.existsSync(candidate));\n return filePath === undefined ? undefined : { filePath, type: 'sourceFile' };\n}\n\nfunction resolveHostCopy(projectRoot: string, packageName: string, moduleName: string): MetroResolution | undefined {\n if (moduleName !== packageName && !moduleName.startsWith(`${packageName}/`)) {\n return undefined;\n }\n const hostPath = path.join(projectRoot, 'node_modules', packageName);\n const file = moduleName === packageName ? 'index.js' : `${moduleName.replace(`${packageName}/`, '')}.js`;\n return { filePath: path.join(hostPath, file), type: 'sourceFile' };\n}\n\n/** Resolver that maps `@/` to src and forces react / react-dom to the host app's single copy. */\nexport function createResolveRequest(projectRoot: string, srcDir = 'src'): MetroResolveRequest {\n return (context: MetroResolveContext, moduleName: string, platform: string | null): MetroResolution => {\n const aliased = moduleName.startsWith(ALIAS_PREFIX) ? resolveAlias(projectRoot, srcDir, moduleName) : undefined;\n return aliased\n ?? resolveHostCopy(projectRoot, 'react', moduleName)\n ?? resolveHostCopy(projectRoot, 'react-dom', moduleName)\n ?? context.resolveRequest(context, moduleName, platform);\n };\n}\n\n/** Applies the house resolver settings to the config from expo's `getDefaultConfig(projectRoot)`. */\nexport function withSharedMetroConfig<T extends MetroConfigLike>(config: T, options: SharedMetroOptions): T {\n const { projectRoot } = options;\n return {\n ...config,\n resolver: {\n ...config.resolver,\n unstable_enableSymlinks: true,\n unstable_enablePackageExports: true,\n blockList: buildBlockList(projectRoot, options.blockedDirs),\n nodeModulesPaths: [path.join(projectRoot, 'node_modules')],\n resolveRequest: createResolveRequest(projectRoot, options.srcDir),\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
// src/metro/index.ts
|
|
5
|
+
var DEFAULT_BLOCKED_DIRS = ["dist", "coverage", "lighthouse-reports"];
|
|
6
|
+
var ALIAS_PREFIX = "@/";
|
|
7
|
+
var ALIAS_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".json", "/index.ts", "/index.tsx", "/index.js"];
|
|
8
|
+
function buildBlockList(projectRoot, dirs = DEFAULT_BLOCKED_DIRS) {
|
|
9
|
+
return dirs.map((dir) => path.join(projectRoot, dir)).map((p) => new RegExp(`^${p.replace(/\\/g, "\\\\").replace(/\//g, "[\\\\/]")}.*`));
|
|
10
|
+
}
|
|
11
|
+
function resolveAlias(projectRoot, srcDir, moduleName) {
|
|
12
|
+
const basePath = path.join(projectRoot, srcDir, moduleName.slice(ALIAS_PREFIX.length));
|
|
13
|
+
const filePath = ALIAS_EXTENSIONS.map((ext) => basePath + ext).find((candidate) => fs.existsSync(candidate));
|
|
14
|
+
return filePath === void 0 ? void 0 : { filePath, type: "sourceFile" };
|
|
15
|
+
}
|
|
16
|
+
function resolveHostCopy(projectRoot, packageName, moduleName) {
|
|
17
|
+
if (moduleName !== packageName && !moduleName.startsWith(`${packageName}/`)) {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
const hostPath = path.join(projectRoot, "node_modules", packageName);
|
|
21
|
+
const file = moduleName === packageName ? "index.js" : `${moduleName.replace(`${packageName}/`, "")}.js`;
|
|
22
|
+
return { filePath: path.join(hostPath, file), type: "sourceFile" };
|
|
23
|
+
}
|
|
24
|
+
function createResolveRequest(projectRoot, srcDir = "src") {
|
|
25
|
+
return (context, moduleName, platform) => {
|
|
26
|
+
const aliased = moduleName.startsWith(ALIAS_PREFIX) ? resolveAlias(projectRoot, srcDir, moduleName) : void 0;
|
|
27
|
+
return aliased ?? resolveHostCopy(projectRoot, "react", moduleName) ?? resolveHostCopy(projectRoot, "react-dom", moduleName) ?? context.resolveRequest(context, moduleName, platform);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function withSharedMetroConfig(config, options) {
|
|
31
|
+
const { projectRoot } = options;
|
|
32
|
+
return {
|
|
33
|
+
...config,
|
|
34
|
+
resolver: {
|
|
35
|
+
...config.resolver,
|
|
36
|
+
unstable_enableSymlinks: true,
|
|
37
|
+
unstable_enablePackageExports: true,
|
|
38
|
+
blockList: buildBlockList(projectRoot, options.blockedDirs),
|
|
39
|
+
nodeModulesPaths: [path.join(projectRoot, "node_modules")],
|
|
40
|
+
resolveRequest: createResolveRequest(projectRoot, options.srcDir)
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { buildBlockList, createResolveRequest, withSharedMetroConfig };
|
|
46
|
+
//# sourceMappingURL=index.mjs.map
|
|
47
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/metro/index.ts"],"names":[],"mappings":";;;;AAwBA,IAAM,oBAAA,GAAuB,CAAC,MAAA,EAAQ,UAAA,EAAY,oBAAoB,CAAA;AACtE,IAAM,YAAA,GAAe,IAAA;AACrB,IAAM,gBAAA,GAAmB,CAAC,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAA,EAAQ,OAAA,EAAS,WAAA,EAAa,YAAA,EAAc,WAAW,CAAA;AAGhG,SAAS,cAAA,CAAe,WAAA,EAAqB,IAAA,GAA0B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CAAA;AACnG,EAAA,OAAO,EAAE,QAAA,EAAe,IAAA,CAAA,IAAA,CAAK,UAAU,IAAI,CAAA,EAAG,MAAM,YAAA,EAAa;AACnE;AAGO,SAAS,oBAAA,CAAqB,WAAA,EAAqB,MAAA,GAAS,KAAA,EAA4B;AAC7F,EAAA,OAAO,CAAC,OAAA,EAA8B,UAAA,EAAoB,QAAA,KAA6C;AACrG,IAAA,MAAM,OAAA,GAAU,WAAW,UAAA,CAAW,YAAY,IAAI,YAAA,CAAa,WAAA,EAAa,MAAA,EAAQ,UAAU,CAAA,GAAI,MAAA;AACtG,IAAA,OAAO,OAAA,IACF,eAAA,CAAgB,WAAA,EAAa,OAAA,EAAS,UAAU,CAAA,IAChD,eAAA,CAAgB,WAAA,EAAa,WAAA,EAAa,UAAU,CAAA,IACpD,OAAA,CAAQ,cAAA,CAAe,OAAA,EAAS,YAAY,QAAQ,CAAA;AAAA,EAC3D,CAAA;AACF;AAGO,SAAS,qBAAA,CAAiD,QAAW,OAAA,EAAgC;AAC1G,EAAA,MAAM,EAAE,aAAY,GAAI,OAAA;AACxB,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,QAAA,EAAU;AAAA,MACR,GAAG,MAAA,CAAO,QAAA;AAAA,MACV,uBAAA,EAAyB,IAAA;AAAA,MACzB,6BAAA,EAA+B,IAAA;AAAA,MAC/B,SAAA,EAAW,cAAA,CAAe,WAAA,EAAa,OAAA,CAAQ,WAAW,CAAA;AAAA,MAC1D,gBAAA,EAAkB,CAAM,IAAA,CAAA,IAAA,CAAK,WAAA,EAAa,cAAc,CAAC,CAAA;AAAA,MACzD,cAAA,EAAgB,oBAAA,CAAqB,WAAA,EAAa,OAAA,CAAQ,MAAM;AAAA;AAClE,GACF;AACF","file":"index.mjs","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface MetroResolution {\n filePath?: string;\n type: string;\n}\n\nexport interface MetroResolveContext {\n resolveRequest: (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;\n}\n\nexport type MetroResolveRequest = (context: MetroResolveContext, moduleName: string, platform: string | null) => MetroResolution;\n\nexport interface MetroConfigLike {\n resolver?: Record<string, unknown>;\n}\n\nexport interface SharedMetroOptions {\n projectRoot: string;\n blockedDirs?: string[];\n srcDir?: string;\n}\n\nconst DEFAULT_BLOCKED_DIRS = ['dist', 'coverage', 'lighthouse-reports'];\nconst ALIAS_PREFIX = '@/';\nconst ALIAS_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.json', '/index.ts', '/index.tsx', '/index.js'];\n\n/** Regexes that keep Metro's watcher out of build-output dirs (Windows symlink lstat errors). */\nexport function buildBlockList(projectRoot: string, dirs: readonly string[] = DEFAULT_BLOCKED_DIRS): RegExp[] {\n return dirs\n .map((dir) => path.join(projectRoot, dir))\n .map((p) => new RegExp(`^${p.replace(/\\\\/g, '\\\\\\\\').replace(/\\//g, '[\\\\\\\\/]')}.*`));\n}\n\nfunction resolveAlias(projectRoot: string, srcDir: string, moduleName: string): MetroResolution | undefined {\n const basePath = path.join(projectRoot, srcDir, moduleName.slice(ALIAS_PREFIX.length));\n const filePath = ALIAS_EXTENSIONS.map((ext) => basePath + ext).find((candidate) => fs.existsSync(candidate));\n return filePath === undefined ? undefined : { filePath, type: 'sourceFile' };\n}\n\nfunction resolveHostCopy(projectRoot: string, packageName: string, moduleName: string): MetroResolution | undefined {\n if (moduleName !== packageName && !moduleName.startsWith(`${packageName}/`)) {\n return undefined;\n }\n const hostPath = path.join(projectRoot, 'node_modules', packageName);\n const file = moduleName === packageName ? 'index.js' : `${moduleName.replace(`${packageName}/`, '')}.js`;\n return { filePath: path.join(hostPath, file), type: 'sourceFile' };\n}\n\n/** Resolver that maps `@/` to src and forces react / react-dom to the host app's single copy. */\nexport function createResolveRequest(projectRoot: string, srcDir = 'src'): MetroResolveRequest {\n return (context: MetroResolveContext, moduleName: string, platform: string | null): MetroResolution => {\n const aliased = moduleName.startsWith(ALIAS_PREFIX) ? resolveAlias(projectRoot, srcDir, moduleName) : undefined;\n return aliased\n ?? resolveHostCopy(projectRoot, 'react', moduleName)\n ?? resolveHostCopy(projectRoot, 'react-dom', moduleName)\n ?? context.resolveRequest(context, moduleName, platform);\n };\n}\n\n/** Applies the house resolver settings to the config from expo's `getDefaultConfig(projectRoot)`. */\nexport function withSharedMetroConfig<T extends MetroConfigLike>(config: T, options: SharedMetroOptions): T {\n const { projectRoot } = options;\n return {\n ...config,\n resolver: {\n ...config.resolver,\n unstable_enableSymlinks: true,\n unstable_enablePackageExports: true,\n blockList: buildBlockList(projectRoot, options.blockedDirs),\n nodeModulesPaths: [path.join(projectRoot, 'node_modules')],\n resolveRequest: createResolveRequest(projectRoot, options.srcDir),\n },\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SourceReader,
|
|
2
|
-
export { F as Framework,
|
|
1
|
+
import { S as SourceReader, b as RunInfo, T as TestdocResults, a as TestStatus, c as RequirementRecord } from '../types-DQiTmmgP.mjs';
|
|
2
|
+
export { F as Framework, R as ReporterOptions, d as TestRecord } from '../types-DQiTmmgP.mjs';
|
|
3
3
|
export { JestAssertion, JestFileResult, JestRunResults, default as TestdocJestReporter, convertJestResults } from './jestReporter.mjs';
|
|
4
4
|
export { default as TestdocVitestReporter, VitestFile, VitestTask, convertVitestFiles, vitestStatus } from './vitestReporter.mjs';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SourceReader,
|
|
2
|
-
export { F as Framework,
|
|
1
|
+
import { S as SourceReader, b as RunInfo, T as TestdocResults, a as TestStatus, c as RequirementRecord } from '../types-DQiTmmgP.js';
|
|
2
|
+
export { F as Framework, R as ReporterOptions, d as TestRecord } from '../types-DQiTmmgP.js';
|
|
3
3
|
export { JestAssertion, JestFileResult, JestRunResults, default as TestdocJestReporter, convertJestResults } from './jestReporter.js';
|
|
4
4
|
export { default as TestdocVitestReporter, VitestFile, VitestTask, convertVitestFiles, vitestStatus } from './vitestReporter.js';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as ReporterOptions, S as SourceReader, T as TestdocResults, a as TestStatus } from '../types-DQiTmmgP.mjs';
|
|
2
2
|
|
|
3
3
|
interface VitestTask {
|
|
4
4
|
type: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as ReporterOptions, S as SourceReader, T as TestdocResults, a as TestStatus } from '../types-DQiTmmgP.js';
|
|
2
2
|
|
|
3
3
|
interface VitestTask {
|
|
4
4
|
type: string;
|