datagrok-tools 5.1.8 → 5.1.9
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/bin/commands/test.js +11 -3
- package/bin/utils/test-utils.js +19 -0
- package/bin/utils/utils.js +3 -3
- package/package.json +1 -1
package/bin/commands/test.js
CHANGED
|
@@ -62,7 +62,6 @@ async function test(args) {
|
|
|
62
62
|
encoding: 'utf-8'
|
|
63
63
|
}));
|
|
64
64
|
isArgsValid(args);
|
|
65
|
-
utils.setHost(args.host, config);
|
|
66
65
|
|
|
67
66
|
// If running from a core Dart library directory, delegate to DevTools package
|
|
68
67
|
if (!args.package) {
|
|
@@ -76,7 +75,8 @@ async function test(args) {
|
|
|
76
75
|
color.error(`Run 'grok test --category="${category}"' from 'public/packages/DevTools' instead.`);
|
|
77
76
|
process.exit(1);
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
const hostAlias = args.host ?? config.default;
|
|
79
|
+
color.info(`Detected core library directory. Delegating to DevTools with category: "${category}"${hostAlias ? ` (host: ${hostAlias})` : ''}`);
|
|
80
80
|
const cmdArgs = ['test', `--category=${category}`];
|
|
81
81
|
if (args.host) cmdArgs.push(`--host=${args.host}`);
|
|
82
82
|
if (args.test) cmdArgs.push(`--test=${args.test}`);
|
|
@@ -94,6 +94,13 @@ async function test(args) {
|
|
|
94
94
|
if (args.debug) cmdArgs.push('--debug');
|
|
95
95
|
if (args['ci-cd']) cmdArgs.push('--ci-cd');
|
|
96
96
|
if (args['no-retry']) cmdArgs.push('--no-retry');
|
|
97
|
+
if (!args['skip-publish']) {
|
|
98
|
+
const isDevToolsOnServer = await testUtils.isPackageOnServer(args.host ?? '', 'DevTools');
|
|
99
|
+
if (isDevToolsOnServer) {
|
|
100
|
+
cmdArgs.push('--skip-publish');
|
|
101
|
+
if (!args['skip-build']) cmdArgs.push('--skip-build');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
97
104
|
const grokScript = _path.default.resolve(__dirname, '..', 'grok.js');
|
|
98
105
|
const result = (0, _child_process.spawnSync)(process.execPath, [grokScript, ...cmdArgs], {
|
|
99
106
|
cwd: devToolsDir,
|
|
@@ -102,13 +109,14 @@ async function test(args) {
|
|
|
102
109
|
process.exit(result.status ?? 1);
|
|
103
110
|
}
|
|
104
111
|
}
|
|
112
|
+
utils.setHost(args.host, config, true);
|
|
105
113
|
let packageJsonData = undefined;
|
|
106
114
|
if (!args.package) packageJsonData = JSON.parse(_fs.default.readFileSync(_path.default.join(curDir, 'package.json'), {
|
|
107
115
|
encoding: 'utf-8'
|
|
108
116
|
}));
|
|
109
117
|
const packageName = args.package ? utils.kebabToCamelCase(args.package) : utils.kebabToCamelCase(utils.removeScope(packageJsonData.name));
|
|
110
118
|
const packagesDir = _path.default.basename(curDir) === 'packages' ? curDir : _path.default.dirname(curDir);
|
|
111
|
-
console.log(
|
|
119
|
+
console.log(`HOST: ${process.env.HOST}, TARGET_PACKAGE: ${packageName}`);
|
|
112
120
|
if (args.platform && packageName !== 'ApiTests') color.warn('--platform flag can only be used in the ApiTests package');
|
|
113
121
|
// if (args.core && packageName !== 'DevTools')
|
|
114
122
|
// color.warn('--core flag can only be used in the DevTools package');
|
package/bin/utils/test-utils.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.getDevKey = getDevKey;
|
|
|
15
15
|
exports.getToken = getToken;
|
|
16
16
|
exports.getWebUrl = getWebUrl;
|
|
17
17
|
exports.getWebUrlFromPage = getWebUrlFromPage;
|
|
18
|
+
exports.isPackageOnServer = isPackageOnServer;
|
|
18
19
|
exports.loadPackage = loadPackage;
|
|
19
20
|
exports.loadPackages = loadPackages;
|
|
20
21
|
exports.loadTestsList = loadTestsList;
|
|
@@ -59,6 +60,24 @@ async function getToken(url, key) {
|
|
|
59
60
|
const json = await response.json();
|
|
60
61
|
if (json.isSuccess == true) return json.token;else throw new Error('Unable to login to server. Check your dev key');
|
|
61
62
|
}
|
|
63
|
+
async function isPackageOnServer(hostKey, packageName) {
|
|
64
|
+
try {
|
|
65
|
+
const {
|
|
66
|
+
url,
|
|
67
|
+
key
|
|
68
|
+
} = getDevKey(hostKey);
|
|
69
|
+
const token = await getToken(url, key);
|
|
70
|
+
const response = await fetch(`${url}/packages/published/current`, {
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: token
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const packages = await response.json();
|
|
76
|
+
return Array.isArray(packages) && packages.some(p => p.name?.toLowerCase() === packageName.toLowerCase());
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
62
81
|
async function getWebUrl(url, token) {
|
|
63
82
|
const response = await fetch(`${url}/admin/plugins/admin/settings`, {
|
|
64
83
|
headers: {
|
package/bin/utils/utils.js
CHANGED
|
@@ -280,18 +280,18 @@ async function runScript(script, path, verbose = false) {
|
|
|
280
280
|
throw new Error(output);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
function setHost(host, configFile) {
|
|
283
|
+
function setHost(host, configFile, quiet = false) {
|
|
284
284
|
if (host) {
|
|
285
285
|
if (host in configFile.servers) {
|
|
286
286
|
process.env.HOST = host;
|
|
287
|
-
console.log('Environment variable `HOST` is set to', host);
|
|
287
|
+
if (!quiet) console.log('Environment variable `HOST` is set to', host);
|
|
288
288
|
} else {
|
|
289
289
|
console.error(`Unknown server alias. Please add it to Config File`);
|
|
290
290
|
return false;
|
|
291
291
|
}
|
|
292
292
|
} else if (configFile.default) {
|
|
293
293
|
process.env.HOST = configFile.default;
|
|
294
|
-
console.log('Environment variable `HOST` is set to', configFile.default);
|
|
294
|
+
if (!quiet) console.log('Environment variable `HOST` is set to', configFile.default);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
async function runAll(packagesDir, command, options, packagesToLoad = ['all']) {
|
package/package.json
CHANGED