@procore/hammer-test-jest 0.0.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/LICENSE +84 -0
- package/README.md +47 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +251 -0
- package/dist/index.mjs +209 -0
- package/dist/transforms/file.d.mts +2 -0
- package/dist/transforms/file.d.ts +2 -0
- package/dist/transforms/file.js +35 -0
- package/dist/transforms/file.mjs +32 -0
- package/dist/transforms/file.test.d.mts +2 -0
- package/dist/transforms/file.test.d.ts +2 -0
- package/dist/transforms/file.test.js +16180 -0
- package/dist/transforms/file.test.mjs +16186 -0
- package/dist/transforms/reactSvg.d.mts +2 -0
- package/dist/transforms/reactSvg.d.ts +2 -0
- package/dist/transforms/reactSvg.js +129 -0
- package/dist/transforms/reactSvg.mjs +133 -0
- package/dist/transforms/reactSvg.test.d.mts +2 -0
- package/dist/transforms/reactSvg.test.d.ts +2 -0
- package/dist/transforms/reactSvg.test.js +16274 -0
- package/dist/transforms/reactSvg.test.mjs +16280 -0
- package/package.json +73 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
|
|
4
|
+
// src/config/utils.ts
|
|
5
|
+
import fs2 from "fs";
|
|
6
|
+
import path2 from "path";
|
|
7
|
+
|
|
8
|
+
// src/config/baseConfig.ts
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
|
|
11
|
+
// src/config/getSetupFilesPath.ts
|
|
12
|
+
import path from "path";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
var EXTENSIONS = ["js", "jsx", "ts", "tsx"];
|
|
15
|
+
function getSetupFilesPath(rootDir) {
|
|
16
|
+
return EXTENSIONS.map(
|
|
17
|
+
(ext) => path.resolve(rootDir, "src", "__tests__", `setupFiles.${ext}`)
|
|
18
|
+
).find(fs.existsSync);
|
|
19
|
+
}
|
|
20
|
+
function getSetupFrameworkPath(rootDir) {
|
|
21
|
+
return EXTENSIONS.map(
|
|
22
|
+
(ext) => path.resolve(rootDir, "src", "__tests__", `setupFramework.${ext}`)
|
|
23
|
+
).find(fs.existsSync);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/config/baseConfig.ts
|
|
27
|
+
var require2 = createRequire(import.meta.url);
|
|
28
|
+
function getTestEnvironment(environment) {
|
|
29
|
+
switch (environment) {
|
|
30
|
+
case "node" /* node */:
|
|
31
|
+
return "node";
|
|
32
|
+
case "browser" /* browser */:
|
|
33
|
+
return "jsdom";
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`${environment} is not a valid environment.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var jestConfigFactory = (pluginOptions, opts) => {
|
|
39
|
+
const options = {
|
|
40
|
+
environment: "node" /* node */,
|
|
41
|
+
react: false,
|
|
42
|
+
reactSvg: false,
|
|
43
|
+
transformAssets: false,
|
|
44
|
+
...opts
|
|
45
|
+
};
|
|
46
|
+
const moduleNameMapper = {};
|
|
47
|
+
if (options.transformAssets) {
|
|
48
|
+
moduleNameMapper["^.+\\.(css|sass|scss)$"] = require2.resolve("identity-obj-proxy");
|
|
49
|
+
}
|
|
50
|
+
moduleNameMapper["^@/(.*)$"] = "<rootDir>/src/$1";
|
|
51
|
+
const transformIgnorePatterns = [
|
|
52
|
+
`/node_modules/(?!.*(@procore/core-react|@procore/core-icons|date-fns))(.*)`
|
|
53
|
+
];
|
|
54
|
+
const transform = {
|
|
55
|
+
"^.+\\.(js|jsx|ts|tsx)$": [
|
|
56
|
+
"babel-jest",
|
|
57
|
+
{
|
|
58
|
+
presets: [
|
|
59
|
+
[
|
|
60
|
+
require2.resolve("@babel/preset-env"),
|
|
61
|
+
{
|
|
62
|
+
targets: {
|
|
63
|
+
node: "current"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
options.react && [
|
|
68
|
+
require2.resolve("@babel/preset-react"),
|
|
69
|
+
{
|
|
70
|
+
development: true,
|
|
71
|
+
useBuiltIns: true
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
require2.resolve("@babel/preset-typescript")
|
|
75
|
+
].filter((preset) => preset),
|
|
76
|
+
babelrc: false,
|
|
77
|
+
configFile: false
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
const setupFilesAfterEnv = [];
|
|
82
|
+
const setupFiles = [];
|
|
83
|
+
if (options.reactSvg) {
|
|
84
|
+
transform["\\.svg$"] = require2.resolve("./transforms/reactSvg");
|
|
85
|
+
}
|
|
86
|
+
if (options.transformAssets) {
|
|
87
|
+
transform["^(?!.*\\.(js|jsx|ts|tsx|css|json)$)"] = require2.resolve("./transforms/file");
|
|
88
|
+
transformIgnorePatterns.push("\\.(css|sass|scss)$");
|
|
89
|
+
}
|
|
90
|
+
const setupFrameworkPath = getSetupFrameworkPath(pluginOptions.rootDir);
|
|
91
|
+
if (setupFrameworkPath) {
|
|
92
|
+
setupFilesAfterEnv.push(setupFrameworkPath);
|
|
93
|
+
}
|
|
94
|
+
const setupFilesPath = getSetupFilesPath(pluginOptions.rootDir);
|
|
95
|
+
if (setupFilesPath) {
|
|
96
|
+
setupFiles.push(setupFilesPath);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
collectCoverageFrom: ["<rootDir>/src/**/*.(js|jsx|ts|tsx)"],
|
|
100
|
+
coverageDirectory: "<rootDir>/coverage",
|
|
101
|
+
coveragePathIgnorePatterns: [
|
|
102
|
+
"/node_modules/",
|
|
103
|
+
"/__mocks__/",
|
|
104
|
+
"/__tests__/",
|
|
105
|
+
".d.ts$"
|
|
106
|
+
],
|
|
107
|
+
moduleFileExtensions: ["node", "js", "json", "jsx", "ts", "tsx"],
|
|
108
|
+
moduleNameMapper,
|
|
109
|
+
roots: ["<rootDir>/src"],
|
|
110
|
+
setupFiles,
|
|
111
|
+
setupFilesAfterEnv,
|
|
112
|
+
testEnvironment: getTestEnvironment(options.environment),
|
|
113
|
+
testMatch: ["<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"],
|
|
114
|
+
transform,
|
|
115
|
+
transformIgnorePatterns,
|
|
116
|
+
watchPlugins: [
|
|
117
|
+
"jest-watch-typeahead/filename",
|
|
118
|
+
"jest-watch-typeahead/testname"
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/config/utils.ts
|
|
124
|
+
function findReactDependency(rootDir) {
|
|
125
|
+
const packageJson = JSON.parse(
|
|
126
|
+
fs2.readFileSync(path2.resolve(rootDir, "package.json"), "utf8")
|
|
127
|
+
);
|
|
128
|
+
return Boolean(
|
|
129
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
130
|
+
packageJson?.peerDependencies?.hasOwnProperty("react") || // eslint-disable-next-line no-prototype-builtins
|
|
131
|
+
packageJson?.dependencies?.hasOwnProperty("react") || // eslint-disable-next-line no-prototype-builtins
|
|
132
|
+
packageJson?.devDependencies?.hasOwnProperty("react")
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function getDefaultConfig(options) {
|
|
136
|
+
return jestConfigFactory(options, {
|
|
137
|
+
transformAssets: false
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getReactConfig(options) {
|
|
141
|
+
return jestConfigFactory(options, {
|
|
142
|
+
environment: "browser" /* browser */,
|
|
143
|
+
react: true,
|
|
144
|
+
reactSvg: true,
|
|
145
|
+
transformAssets: true
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/config/index.ts
|
|
150
|
+
function getConfig(options) {
|
|
151
|
+
const hasReact = findReactDependency(options.rootDir);
|
|
152
|
+
const config = hasReact ? getReactConfig(options) : getDefaultConfig(options);
|
|
153
|
+
return options.config.testJest ? options.config.testJest(config) : config;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/utils/terminal.ts
|
|
157
|
+
import { highlight } from "cli-highlight";
|
|
158
|
+
function toHighlightedString(input) {
|
|
159
|
+
const inputAsString = JSON.stringify(
|
|
160
|
+
input,
|
|
161
|
+
function(_key, value) {
|
|
162
|
+
return typeof value === "function" ? value.toString() : value;
|
|
163
|
+
},
|
|
164
|
+
2
|
|
165
|
+
);
|
|
166
|
+
return highlight(inputAsString, { language: "js" });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/performTest.ts
|
|
170
|
+
import * as jest from "jest-cli";
|
|
171
|
+
|
|
172
|
+
// src/utils/argvForJest.ts
|
|
173
|
+
var allowedFlags = [
|
|
174
|
+
"watch",
|
|
175
|
+
"W",
|
|
176
|
+
"coverage",
|
|
177
|
+
"ci",
|
|
178
|
+
"silent"
|
|
179
|
+
];
|
|
180
|
+
function generateArgv(options) {
|
|
181
|
+
const argv = [];
|
|
182
|
+
for (const [key, value] of Object.entries(options)) {
|
|
183
|
+
if (value && allowedFlags.includes(key)) {
|
|
184
|
+
argv.push(`--${key}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return argv;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/performTest.ts
|
|
191
|
+
async function performTest(options) {
|
|
192
|
+
const config = JSON.stringify(getConfig(options));
|
|
193
|
+
return jest.run(["--config", config, ...generateArgv(options)]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/index.ts
|
|
197
|
+
async function test(options) {
|
|
198
|
+
await performTest(options);
|
|
199
|
+
}
|
|
200
|
+
async function inspect(options) {
|
|
201
|
+
const highlightedConfig = toHighlightedString(getConfig(options));
|
|
202
|
+
process.stdout.write(`
|
|
203
|
+
${highlightedConfig}
|
|
204
|
+
`);
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
inspect,
|
|
208
|
+
test
|
|
209
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/transforms/file.ts
|
|
26
|
+
var import_path = __toESM(require("path"));
|
|
27
|
+
module.exports = {
|
|
28
|
+
process(_src, filename) {
|
|
29
|
+
const assetFilename = JSON.stringify(import_path.default.basename(filename));
|
|
30
|
+
return `module.exports = {
|
|
31
|
+
__esModule: true,
|
|
32
|
+
default: ${assetFilename},
|
|
33
|
+
};`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __esm = (fn, res) => function __init() {
|
|
3
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
+
};
|
|
5
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
6
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/tsup/assets/esm_shims.js
|
|
10
|
+
var init_esm_shims = __esm({
|
|
11
|
+
"../../node_modules/tsup/assets/esm_shims.js"() {
|
|
12
|
+
"use strict";
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// src/transforms/file.ts
|
|
17
|
+
import path from "path";
|
|
18
|
+
var require_file = __commonJS({
|
|
19
|
+
"src/transforms/file.ts"(exports, module) {
|
|
20
|
+
init_esm_shims();
|
|
21
|
+
module.exports = {
|
|
22
|
+
process(_src, filename) {
|
|
23
|
+
const assetFilename = JSON.stringify(path.basename(filename));
|
|
24
|
+
return `module.exports = {
|
|
25
|
+
__esModule: true,
|
|
26
|
+
default: ${assetFilename},
|
|
27
|
+
};`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export default require_file();
|