@elliemae/pui-cli 9.0.0-next.21 → 9.0.0-next.22
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.
|
@@ -33,14 +33,6 @@ __export(test_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(test_exports);
|
|
34
34
|
var import_yargs = __toESM(require("yargs"), 1);
|
|
35
35
|
var import_utils = require("./utils.js");
|
|
36
|
-
const test = async (commandOptions) => {
|
|
37
|
-
await (0, import_utils.exec)(`cross-env NODE_ENV=test jest ${commandOptions}`);
|
|
38
|
-
};
|
|
39
|
-
const debugTest = async () => {
|
|
40
|
-
await (0, import_utils.exec)(
|
|
41
|
-
`node --inspect-brk ./node_modules/jest-cli/bin/jest.js --runInBand --watch`
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
36
|
const cmdArgs = {
|
|
45
37
|
fix: {
|
|
46
38
|
boolean: true,
|
|
@@ -71,24 +63,59 @@ const cmdArgs = {
|
|
|
71
63
|
boolean: true,
|
|
72
64
|
alias: "s",
|
|
73
65
|
default: false
|
|
66
|
+
},
|
|
67
|
+
coverage: {
|
|
68
|
+
string: true,
|
|
69
|
+
// we want to support "CI" | "false" | "true"
|
|
70
|
+
default: "true"
|
|
71
|
+
},
|
|
72
|
+
maxWorkers: {
|
|
73
|
+
string: true,
|
|
74
|
+
default: "50%"
|
|
74
75
|
}
|
|
75
76
|
};
|
|
77
|
+
const getJestFlags = (argv) => {
|
|
78
|
+
const flagsArray = [argv.maxWorkers];
|
|
79
|
+
const isCi = (0, import_utils.getCIEnv)();
|
|
80
|
+
switch (`${argv.coverage}`) {
|
|
81
|
+
case "CI":
|
|
82
|
+
if (isCi) {
|
|
83
|
+
flagsArray.push("--coverage");
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "false":
|
|
87
|
+
break;
|
|
88
|
+
case "true":
|
|
89
|
+
default:
|
|
90
|
+
flagsArray.push("--coverage");
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (argv.fix)
|
|
94
|
+
flagsArray.push("-u");
|
|
95
|
+
else if (argv.watch)
|
|
96
|
+
flagsArray.push("--watchAll");
|
|
97
|
+
if (argv.passWithNoTests)
|
|
98
|
+
flagsArray.push("--passWithNoTests");
|
|
99
|
+
if (argv.findReleatedTests)
|
|
100
|
+
flagsArray.push("--bail --findRelatedTests");
|
|
101
|
+
if (argv.silent)
|
|
102
|
+
flagsArray.push("--silent");
|
|
103
|
+
if (isCi)
|
|
104
|
+
flagsArray.push("--ci --no-colors");
|
|
105
|
+
return flagsArray.join(" ");
|
|
106
|
+
};
|
|
107
|
+
const test = async (argv) => {
|
|
108
|
+
const jestFlags = getJestFlags(argv);
|
|
109
|
+
await (0, import_utils.exec)(`cross-env NODE_ENV=test jest ${jestFlags}`);
|
|
110
|
+
};
|
|
111
|
+
const debugTest = async () => {
|
|
112
|
+
await (0, import_utils.exec)(
|
|
113
|
+
`node --inspect-brk ./node_modules/jest-cli/bin/jest.js --runInBand --watch`
|
|
114
|
+
);
|
|
115
|
+
};
|
|
76
116
|
const testCmd = {
|
|
77
117
|
// eslint-disable-next-line max-statements
|
|
78
118
|
handler: async (argv) => {
|
|
79
|
-
let commandOptions = "--coverage --maxWorkers=50%";
|
|
80
|
-
if (argv.fix)
|
|
81
|
-
commandOptions += " -u";
|
|
82
|
-
else if (argv.watch)
|
|
83
|
-
commandOptions += " --watchAll";
|
|
84
|
-
if ((0, import_utils.getCIEnv)())
|
|
85
|
-
commandOptions += " --ci --no-colors";
|
|
86
|
-
if (argv.passWithNoTests)
|
|
87
|
-
commandOptions += " --passWithNoTests";
|
|
88
|
-
if (argv.findReleatedTests)
|
|
89
|
-
commandOptions += " --bail --findRelatedTests";
|
|
90
|
-
if (argv.silent)
|
|
91
|
-
commandOptions += " --silent";
|
|
92
119
|
try {
|
|
93
120
|
if ((0, import_utils.getCIEnv)()) {
|
|
94
121
|
await (0, import_utils.exec)("rimraf ./reports");
|
|
@@ -96,7 +123,7 @@ const testCmd = {
|
|
|
96
123
|
if (argv.debug) {
|
|
97
124
|
await debugTest();
|
|
98
125
|
} else {
|
|
99
|
-
await test(
|
|
126
|
+
await test(argv);
|
|
100
127
|
}
|
|
101
128
|
(0, import_utils.logSuccess)("Unit test execution completed");
|
|
102
129
|
} catch (err) {
|
|
@@ -31,6 +31,7 @@ __export(utils_exports, {
|
|
|
31
31
|
copyBuildAssetsToVersionedFolder: () => copyBuildAssetsToVersionedFolder,
|
|
32
32
|
exec: () => exec,
|
|
33
33
|
getCIEnv: () => getCIEnv,
|
|
34
|
+
getUnspecifiedOptions: () => getUnspecifiedOptions,
|
|
34
35
|
isApp: () => isApp,
|
|
35
36
|
isPathExist: () => isPathExist,
|
|
36
37
|
isTypeScriptEnabled: () => isTypeScriptEnabled,
|
|
@@ -208,3 +209,29 @@ const isPathExist = async (pathToCheck) => {
|
|
|
208
209
|
const isApp = async () => isPathExist(import_node_path.default.join(process.cwd(), "app"));
|
|
209
210
|
const getCIEnv = () => process.env.CI === "true";
|
|
210
211
|
const isTypeScriptEnabled = () => import_node_fs.default.existsSync(import_node_path.default.join(process.cwd(), "tsconfig.json"));
|
|
212
|
+
const getUnspecifiedOptions = (options, command) => {
|
|
213
|
+
const rawArgs = process.argv.slice(2);
|
|
214
|
+
const rawArgsMap = /* @__PURE__ */ new Map();
|
|
215
|
+
rawArgs.forEach((arg) => {
|
|
216
|
+
const [key, value] = arg.split("=");
|
|
217
|
+
const keyWithoutPrefix = key.replace(/^-{1,2}/, "");
|
|
218
|
+
rawArgsMap.set(keyWithoutPrefix, value || true);
|
|
219
|
+
});
|
|
220
|
+
const expectedOptionsMap = /* @__PURE__ */ new Map();
|
|
221
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
222
|
+
expectedOptionsMap.set(key, value);
|
|
223
|
+
if (value.alias)
|
|
224
|
+
expectedOptionsMap.set(value.alias, value);
|
|
225
|
+
});
|
|
226
|
+
const unspecifiedOptions = {};
|
|
227
|
+
rawArgsMap.forEach((value, key) => {
|
|
228
|
+
if (key === command)
|
|
229
|
+
return;
|
|
230
|
+
if (key === "")
|
|
231
|
+
return;
|
|
232
|
+
if (!expectedOptionsMap.has(key)) {
|
|
233
|
+
unspecifiedOptions[key] = value;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return unspecifiedOptions;
|
|
237
|
+
};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import yargs from "yargs";
|
|
2
2
|
import { exec, logError, logSuccess, getCIEnv } from "./utils.js";
|
|
3
|
-
const test = async (commandOptions) => {
|
|
4
|
-
await exec(`cross-env NODE_ENV=test jest ${commandOptions}`);
|
|
5
|
-
};
|
|
6
|
-
const debugTest = async () => {
|
|
7
|
-
await exec(
|
|
8
|
-
`node --inspect-brk ./node_modules/jest-cli/bin/jest.js --runInBand --watch`
|
|
9
|
-
);
|
|
10
|
-
};
|
|
11
3
|
const cmdArgs = {
|
|
12
4
|
fix: {
|
|
13
5
|
boolean: true,
|
|
@@ -38,24 +30,59 @@ const cmdArgs = {
|
|
|
38
30
|
boolean: true,
|
|
39
31
|
alias: "s",
|
|
40
32
|
default: false
|
|
33
|
+
},
|
|
34
|
+
coverage: {
|
|
35
|
+
string: true,
|
|
36
|
+
// we want to support "CI" | "false" | "true"
|
|
37
|
+
default: "true"
|
|
38
|
+
},
|
|
39
|
+
maxWorkers: {
|
|
40
|
+
string: true,
|
|
41
|
+
default: "50%"
|
|
41
42
|
}
|
|
42
43
|
};
|
|
44
|
+
const getJestFlags = (argv) => {
|
|
45
|
+
const flagsArray = [argv.maxWorkers];
|
|
46
|
+
const isCi = getCIEnv();
|
|
47
|
+
switch (`${argv.coverage}`) {
|
|
48
|
+
case "CI":
|
|
49
|
+
if (isCi) {
|
|
50
|
+
flagsArray.push("--coverage");
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case "false":
|
|
54
|
+
break;
|
|
55
|
+
case "true":
|
|
56
|
+
default:
|
|
57
|
+
flagsArray.push("--coverage");
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
if (argv.fix)
|
|
61
|
+
flagsArray.push("-u");
|
|
62
|
+
else if (argv.watch)
|
|
63
|
+
flagsArray.push("--watchAll");
|
|
64
|
+
if (argv.passWithNoTests)
|
|
65
|
+
flagsArray.push("--passWithNoTests");
|
|
66
|
+
if (argv.findReleatedTests)
|
|
67
|
+
flagsArray.push("--bail --findRelatedTests");
|
|
68
|
+
if (argv.silent)
|
|
69
|
+
flagsArray.push("--silent");
|
|
70
|
+
if (isCi)
|
|
71
|
+
flagsArray.push("--ci --no-colors");
|
|
72
|
+
return flagsArray.join(" ");
|
|
73
|
+
};
|
|
74
|
+
const test = async (argv) => {
|
|
75
|
+
const jestFlags = getJestFlags(argv);
|
|
76
|
+
await exec(`cross-env NODE_ENV=test jest ${jestFlags}`);
|
|
77
|
+
};
|
|
78
|
+
const debugTest = async () => {
|
|
79
|
+
await exec(
|
|
80
|
+
`node --inspect-brk ./node_modules/jest-cli/bin/jest.js --runInBand --watch`
|
|
81
|
+
);
|
|
82
|
+
};
|
|
43
83
|
const testCmd = {
|
|
44
84
|
// eslint-disable-next-line max-statements
|
|
45
85
|
handler: async (argv) => {
|
|
46
|
-
let commandOptions = "--coverage --maxWorkers=50%";
|
|
47
|
-
if (argv.fix)
|
|
48
|
-
commandOptions += " -u";
|
|
49
|
-
else if (argv.watch)
|
|
50
|
-
commandOptions += " --watchAll";
|
|
51
|
-
if (getCIEnv())
|
|
52
|
-
commandOptions += " --ci --no-colors";
|
|
53
|
-
if (argv.passWithNoTests)
|
|
54
|
-
commandOptions += " --passWithNoTests";
|
|
55
|
-
if (argv.findReleatedTests)
|
|
56
|
-
commandOptions += " --bail --findRelatedTests";
|
|
57
|
-
if (argv.silent)
|
|
58
|
-
commandOptions += " --silent";
|
|
59
86
|
try {
|
|
60
87
|
if (getCIEnv()) {
|
|
61
88
|
await exec("rimraf ./reports");
|
|
@@ -63,7 +90,7 @@ const testCmd = {
|
|
|
63
90
|
if (argv.debug) {
|
|
64
91
|
await debugTest();
|
|
65
92
|
} else {
|
|
66
|
-
await test(
|
|
93
|
+
await test(argv);
|
|
67
94
|
}
|
|
68
95
|
logSuccess("Unit test execution completed");
|
|
69
96
|
} catch (err) {
|
|
@@ -177,10 +177,37 @@ const isPathExist = async (pathToCheck) => {
|
|
|
177
177
|
const isApp = async () => isPathExist(path.join(process.cwd(), "app"));
|
|
178
178
|
const getCIEnv = () => process.env.CI === "true";
|
|
179
179
|
const isTypeScriptEnabled = () => fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
|
|
180
|
+
const getUnspecifiedOptions = (options, command) => {
|
|
181
|
+
const rawArgs = process.argv.slice(2);
|
|
182
|
+
const rawArgsMap = /* @__PURE__ */ new Map();
|
|
183
|
+
rawArgs.forEach((arg) => {
|
|
184
|
+
const [key, value] = arg.split("=");
|
|
185
|
+
const keyWithoutPrefix = key.replace(/^-{1,2}/, "");
|
|
186
|
+
rawArgsMap.set(keyWithoutPrefix, value || true);
|
|
187
|
+
});
|
|
188
|
+
const expectedOptionsMap = /* @__PURE__ */ new Map();
|
|
189
|
+
Object.entries(options).forEach(([key, value]) => {
|
|
190
|
+
expectedOptionsMap.set(key, value);
|
|
191
|
+
if (value.alias)
|
|
192
|
+
expectedOptionsMap.set(value.alias, value);
|
|
193
|
+
});
|
|
194
|
+
const unspecifiedOptions = {};
|
|
195
|
+
rawArgsMap.forEach((value, key) => {
|
|
196
|
+
if (key === command)
|
|
197
|
+
return;
|
|
198
|
+
if (key === "")
|
|
199
|
+
return;
|
|
200
|
+
if (!expectedOptionsMap.has(key)) {
|
|
201
|
+
unspecifiedOptions[key] = value;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
return unspecifiedOptions;
|
|
205
|
+
};
|
|
180
206
|
export {
|
|
181
207
|
copyBuildAssetsToVersionedFolder,
|
|
182
208
|
exec,
|
|
183
209
|
getCIEnv,
|
|
210
|
+
getUnspecifiedOptions,
|
|
184
211
|
isApp,
|
|
185
212
|
isPathExist,
|
|
186
213
|
isTypeScriptEnabled,
|
|
@@ -16,3 +16,24 @@ export declare const isPathExist: (pathToCheck: string) => Promise<boolean>;
|
|
|
16
16
|
export declare const isApp: () => Promise<boolean>;
|
|
17
17
|
export declare const getCIEnv: () => boolean;
|
|
18
18
|
export declare const isTypeScriptEnabled: () => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* argv will generate an object with many assumptions based on the library own functionality.
|
|
21
|
+
* some of those assumptions make it hard to use the ...rest operator to get the options,
|
|
22
|
+
* this function is meant to get the options that are not specificially expected.
|
|
23
|
+
* @param {object} options - the options the command is specifically expecting
|
|
24
|
+
* @param {string} command - the raw command (without the prefix nor tag)
|
|
25
|
+
* @returns {object} - options that were not specifically expected by the command, key are camelCase, values are forced to be strings
|
|
26
|
+
* @example
|
|
27
|
+
* // options {
|
|
28
|
+
* // someOption: { alias: 'my-test', string: true, default:'foo' },
|
|
29
|
+
* // 'hello-world': { boolean: true, default:'bar' },
|
|
30
|
+
* // }
|
|
31
|
+
* // command "test"
|
|
32
|
+
* // user's args string
|
|
33
|
+
* // "test --hello-world -my-test='is-working' --orMaybe=\"it isn't\" is_it='? '--a"
|
|
34
|
+
* // ^ command ^ expected option ^ expected option(alias) | unspecified options...
|
|
35
|
+
* // returns { orMaybe: "it isn't", is_it: '? ', a: true }
|
|
36
|
+
* // note that the unspecified options are forced to be strings, unless boolean (without '=')
|
|
37
|
+
* @see {@link https://stackblitz.com/edit/node-gqcdb4?file=package.json stackblitz test}
|
|
38
|
+
*/
|
|
39
|
+
export declare const getUnspecifiedOptions: (options: Record<string, Record<string, unknown>>, command: string) => Record<string, string | boolean>;
|