bdy 1.19.0-dev → 1.19.0-dev-pipeline

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.
Files changed (44) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +61 -2
  3. package/distTs/src/command/crawl/link.js +61 -0
  4. package/distTs/src/command/crawl/run.js +147 -0
  5. package/distTs/src/command/crawl/validation.js +154 -0
  6. package/distTs/src/command/crawl.js +13 -0
  7. package/distTs/src/command/pipeline/run/apply.js +62 -0
  8. package/distTs/src/command/pipeline/run/approve.js +62 -0
  9. package/distTs/src/command/pipeline/run/cancel.js +36 -0
  10. package/distTs/src/command/pipeline/run/list.js +52 -0
  11. package/distTs/src/command/pipeline/run/logs.js +37 -0
  12. package/distTs/src/command/pipeline/run/retry.js +36 -0
  13. package/distTs/src/command/pipeline/run/start.js +96 -0
  14. package/distTs/src/command/pipeline/run/status.js +35 -0
  15. package/distTs/src/command/pipeline/run.js +22 -125
  16. package/distTs/src/command/project/link.js +11 -11
  17. package/distTs/src/command/tests/capture/validation.js +46 -0
  18. package/distTs/src/command/tests/capture.js +103 -0
  19. package/distTs/src/command/tests/unit/link.js +61 -0
  20. package/distTs/src/command/tests/unit/upload.js +91 -0
  21. package/distTs/src/command/tests/unit.js +13 -0
  22. package/distTs/src/command/tests/visual/link.js +61 -0
  23. package/distTs/src/command/tests/visual/session/close.js +32 -0
  24. package/distTs/src/command/tests/visual/session/create.js +86 -0
  25. package/distTs/src/command/tests/visual/session.js +13 -0
  26. package/distTs/src/command/tests/visual/setup.js +20 -0
  27. package/distTs/src/command/tests/visual/shared/validation.js +145 -0
  28. package/distTs/src/command/tests/visual/upload.js +141 -0
  29. package/distTs/src/command/tests/visual.js +17 -0
  30. package/distTs/src/command/tests.js +15 -0
  31. package/distTs/src/crawl/requests.js +141 -0
  32. package/distTs/src/input.js +11 -10
  33. package/distTs/src/output/pipeline.js +1507 -0
  34. package/distTs/src/output.js +149 -31
  35. package/distTs/src/texts.js +55 -33
  36. package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
  37. package/distTs/src/types/crawl.js +2 -0
  38. package/distTs/src/types/pipeline.js +424 -0
  39. package/distTs/src/unitTest/context.js +26 -0
  40. package/package.json +1 -1
  41. package/distTs/src/command/project/get.js +0 -18
  42. package/distTs/src/command/project/set.js +0 -31
  43. package/distTs/src/command/sandbox/get/yaml.js +0 -30
  44. package/distTs/src/command/vt/scrape.js +0 -193
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const output_1 = __importDefault(require("../../../output"));
9
+ const commandUtLink = (0, utils_1.newCommand)('link', texts_1.DESC_COMMAND_UT_LINK);
10
+ commandUtLink.option('-w, --workspace <workspace>', texts_1.OPTION_REST_API_WORKSPACE);
11
+ commandUtLink.option('-p, --project <project>', texts_1.OPTION_REST_API_PROJECT);
12
+ commandUtLink.option('-s, --suite <suite>', texts_1.OPTION_SUITE_IDENTIFIER);
13
+ commandUtLink.action(async (options) => {
14
+ const Input = require('../../../input').default;
15
+ const ProjectCfg = require('../../../project/cfg').default;
16
+ output_1.default.handleSignals();
17
+ const workspace = Input.restApiWorkspace(options.workspace);
18
+ const project = Input.restApiProject(options.project);
19
+ const client = Input.restApiTokenClient(false, options.api, options.region);
20
+ let suiteIdentifier = options.suite;
21
+ if (!suiteIdentifier) {
22
+ const opt = await output_1.default.inputMenuAdv(texts_1.TXT_COMMAND_SUITE_SELECT, [
23
+ {
24
+ name: texts_1.TXT_COMMAND_SUITE_CREATE_NEW,
25
+ description: texts_1.TXT_COMMAND_SUITE_CREATE_NEW_UT_DESC,
26
+ value: 'new',
27
+ },
28
+ {
29
+ name: texts_1.TXT_COMMAND_SUITE_LINK_EXISTING,
30
+ description: texts_1.TXT_COMMAND_SUITE_LINK_EXISTING_DESC,
31
+ value: 'existing',
32
+ },
33
+ ]);
34
+ if (opt === 'new') {
35
+ const name = await output_1.default.inputString(texts_1.TXT_COMMAND_SUITE_NAME);
36
+ const response = await client.createUtSuite(workspace, project, { name, identifier: name });
37
+ output_1.default.okSign();
38
+ output_1.default.normal(texts_1.TXT_COMMAND_SUITE_CREATED);
39
+ suiteIdentifier = response.identifier;
40
+ }
41
+ else {
42
+ const result = await client.getUtSuites(workspace, project);
43
+ const suites = result?.suites || [];
44
+ if (!suites.length) {
45
+ output_1.default.exitError(texts_1.ERR_NO_UT_SUITES);
46
+ }
47
+ if (suites.length === 1) {
48
+ suiteIdentifier = suites[0].identifier;
49
+ }
50
+ else {
51
+ const items = suites.map((s) => s.name || s.identifier);
52
+ const index = await output_1.default.inputMenu(texts_1.TXT_COMMAND_UT_LINK_SELECT, items);
53
+ suiteIdentifier = suites[index].identifier;
54
+ }
55
+ }
56
+ }
57
+ ProjectCfg.setSuite((0, utils_1.getWorkingDir)(), 'ut', suiteIdentifier);
58
+ output_1.default.okSign();
59
+ output_1.default.exitSuccess(texts_1.TXT_COMMAND_UT_LINK_SUCCESS);
60
+ });
61
+ exports.default = commandUtLink;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const output_1 = __importDefault(require("../../../output"));
9
+ const commander_1 = require("commander");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const commandUtUpload = (0, utils_1.newCommand)('upload', texts_1.DESC_COMMAND_UT_UPLOAD);
12
+ commandUtUpload.argument('<glob>', texts_1.OPTION_UPLOAD_REPORT_GLOB);
13
+ commandUtUpload.addOption(new commander_1.Option('--format <format>', texts_1.OPTION_UPLOAD_REPORT_FORMAT)
14
+ .choices(['junit-xml'])
15
+ .makeOptionMandatory());
16
+ commandUtUpload.option('--dryRun', texts_1.OPTION_UPLOAD_DRY_RUN);
17
+ commandUtUpload.action(async (input, options) => {
18
+ const { getCiInfo } = require('../../../unitTest/ci');
19
+ const { sendUploadRequest } = require('../../../unitTest/requests');
20
+ const { createUtContext, applyUtToken, applyUtCiInfo } = require('../../../unitTest/context');
21
+ const Input = require('../../../input').default;
22
+ const ctx = createUtContext();
23
+ const token = await Input.utSuiteToken();
24
+ if (!token) {
25
+ output_1.default.exitError(texts_1.ERR_MISSING_UT_TOKEN);
26
+ }
27
+ applyUtToken(ctx, token);
28
+ const { glob, dryRun } = validateInputAndOptions(input, options);
29
+ const ciInfo = await getCiInfo();
30
+ applyUtCiInfo(ctx, ciInfo);
31
+ const { absolutePattern, files } = findFilesByGlob(glob);
32
+ if (files.length === 0) {
33
+ output_1.default.exitError(`No files matched the provided glob: ${absolutePattern}`);
34
+ }
35
+ if (dryRun) {
36
+ output_1.default.normal(`Found ${files.length} report file(s) using pattern: ${absolutePattern}`);
37
+ files.forEach((file) => {
38
+ output_1.default.normal(file);
39
+ });
40
+ output_1.default.exitSuccess('Dry run completed');
41
+ }
42
+ await sendUploadRequest(ctx, files);
43
+ output_1.default.exitSuccess('Upload completed');
44
+ });
45
+ exports.default = commandUtUpload;
46
+ function validateInputAndOptions(input, options) {
47
+ const z = require('zod');
48
+ const { ZodError } = require('zod');
49
+ const globSchema = z.string();
50
+ const optionsSchema = z.object({
51
+ format: z.enum(['junit-xml']),
52
+ dryRun: z.boolean().optional(),
53
+ });
54
+ try {
55
+ const glob = globSchema.parse(input);
56
+ const { format, dryRun } = optionsSchema.parse(options);
57
+ return {
58
+ glob,
59
+ format,
60
+ dryRun,
61
+ };
62
+ }
63
+ catch (error) {
64
+ if (error instanceof ZodError) {
65
+ output_1.default.exitError(error.errors.map((e) => `${e.path}: ${e.message}`).join(', '));
66
+ }
67
+ else {
68
+ throw error;
69
+ }
70
+ }
71
+ }
72
+ function findFilesByGlob(pattern) {
73
+ const { fdir } = require('fdir');
74
+ const picomatch = require('picomatch');
75
+ const cwd = process.cwd();
76
+ const scan = picomatch.scan(pattern);
77
+ if (!scan.isGlob) {
78
+ return {
79
+ absolutePattern: pattern,
80
+ files: (0, utils_1.isFile)(pattern) ? [pattern] : [],
81
+ };
82
+ }
83
+ if (node_path_1.default.isAbsolute(pattern)) {
84
+ const root = scan.base;
85
+ const files = new fdir().withFullPaths().glob(pattern).crawl(root).sync();
86
+ return { absolutePattern: pattern, files };
87
+ }
88
+ const preparedPattern = node_path_1.default.resolve(cwd, pattern);
89
+ const files = new fdir().withFullPaths().glob(preparedPattern).crawl().sync();
90
+ return { absolutePattern: preparedPattern, files };
91
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const upload_1 = __importDefault(require("./unit/upload"));
9
+ const link_1 = __importDefault(require("./unit/link"));
10
+ const commandUnit = (0, utils_1.newCommand)('unit', texts_1.DESC_COMMAND_UNIT);
11
+ commandUnit.addCommand(upload_1.default);
12
+ commandUnit.addCommand(link_1.default);
13
+ exports.default = commandUnit;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const output_1 = __importDefault(require("../../../output"));
9
+ const commandVisualLink = (0, utils_1.newCommand)('link', texts_1.DESC_COMMAND_VT_LINK);
10
+ commandVisualLink.option('-w, --workspace <workspace>', texts_1.OPTION_REST_API_WORKSPACE);
11
+ commandVisualLink.option('-p, --project <project>', texts_1.OPTION_REST_API_PROJECT);
12
+ commandVisualLink.option('-s, --suite <suite>', texts_1.OPTION_SUITE_IDENTIFIER);
13
+ commandVisualLink.action(async (options) => {
14
+ const Input = require('../../../input').default;
15
+ const ProjectCfg = require('../../../project/cfg').default;
16
+ output_1.default.handleSignals();
17
+ const workspace = Input.restApiWorkspace(options.workspace);
18
+ const project = Input.restApiProject(options.project);
19
+ const client = Input.restApiTokenClient(false, options.api, options.region);
20
+ let suiteIdentifier = options.suite;
21
+ if (!suiteIdentifier) {
22
+ const opt = await output_1.default.inputMenuAdv(texts_1.TXT_COMMAND_SUITE_SELECT, [
23
+ {
24
+ name: texts_1.TXT_COMMAND_SUITE_CREATE_NEW,
25
+ description: texts_1.TXT_COMMAND_SUITE_CREATE_NEW_VT_DESC,
26
+ value: 'new',
27
+ },
28
+ {
29
+ name: texts_1.TXT_COMMAND_SUITE_LINK_EXISTING,
30
+ description: texts_1.TXT_COMMAND_SUITE_LINK_EXISTING_DESC,
31
+ value: 'existing',
32
+ },
33
+ ]);
34
+ if (opt === 'new') {
35
+ const name = await output_1.default.inputString(texts_1.TXT_COMMAND_SUITE_NAME);
36
+ const response = await client.createVtSuite(workspace, project, { name, identifier: name });
37
+ output_1.default.okSign();
38
+ output_1.default.normal(texts_1.TXT_COMMAND_SUITE_CREATED);
39
+ suiteIdentifier = response.identifier;
40
+ }
41
+ else {
42
+ const result = await client.getVtSuites(workspace, project);
43
+ const suites = result?.suites || [];
44
+ if (!suites.length) {
45
+ output_1.default.exitError(texts_1.ERR_NO_VT_SUITES);
46
+ }
47
+ if (suites.length === 1) {
48
+ suiteIdentifier = suites[0].identifier;
49
+ }
50
+ else {
51
+ const items = suites.map((s) => s.name || s.identifier);
52
+ const index = await output_1.default.inputMenu(texts_1.TXT_COMMAND_VT_LINK_SELECT, items);
53
+ suiteIdentifier = suites[index].identifier;
54
+ }
55
+ }
56
+ }
57
+ ProjectCfg.setSuite((0, utils_1.getWorkingDir)(), 'vt', suiteIdentifier);
58
+ output_1.default.okSign();
59
+ output_1.default.exitSuccess(texts_1.TXT_COMMAND_VT_LINK_SUCCESS);
60
+ });
61
+ exports.default = commandVisualLink;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../../utils");
7
+ const texts_1 = require("../../../../texts");
8
+ const output_1 = __importDefault(require("../../../../output"));
9
+ const commandSessionClose = (0, utils_1.newCommand)('close', texts_1.DESC_COMMAND_SESSION_CLOSE);
10
+ commandSessionClose.action(async () => {
11
+ const { checkBuildId } = require('../../../../visualTest/validation');
12
+ const { closeSession } = require('../../../../visualTest/requests');
13
+ const { createVtContext, applyToken } = require('../../../../visualTest/context');
14
+ const Input = require('../../../../input').default;
15
+ const token = await Input.vtSuiteToken();
16
+ if (!token) {
17
+ output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
18
+ }
19
+ if (!checkBuildId()) {
20
+ output_1.default.exitError(texts_1.ERR_MISSING_BUILD_ID);
21
+ }
22
+ const ctx = createVtContext();
23
+ applyToken(ctx, token);
24
+ try {
25
+ const { message } = await closeSession(ctx);
26
+ output_1.default.exitNormal(message);
27
+ }
28
+ catch (error) {
29
+ output_1.default.exitError(`${error}`);
30
+ }
31
+ });
32
+ exports.default = commandSessionClose;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../../utils");
7
+ const texts_1 = require("../../../../texts");
8
+ const output_1 = __importDefault(require("../../../../output"));
9
+ const commandSessionCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_SESSION_CREATE);
10
+ commandSessionCreate.argument('<command>', texts_1.OPTION_EXEC_COMMAND);
11
+ commandSessionCreate.option('--skipDiscovery', texts_1.OPTION_EXEC_SKIP_DISCOVERY);
12
+ commandSessionCreate.option('--oneByOne', texts_1.OPTION_EXEC_ONE_BY_ONE);
13
+ commandSessionCreate.option('--parallel', texts_1.OPTION_EXEC_PARALLEL);
14
+ commandSessionCreate.action(async (command, options) => {
15
+ const which = require('which');
16
+ const { getCiAndGitInfo, formattedCiInfo } = require('@buddy-works/ci-info');
17
+ const { checkParallel } = require('../../../../visualTest/validation');
18
+ const { getDefaultSettings } = require('../../../../visualTest/requests');
19
+ const { debug, createVtContext, applyExecOptions, applyCiAndCommitInfo, applyToken } = require('../../../../visualTest/context');
20
+ const { createServer } = require('../../../../visualTest/server');
21
+ const { finishProcessingSnapshots, setDefaultSettings, showSessionLink } = require('../../../../visualTest/snapshots');
22
+ const { testExec } = require('../../../../visualTest/exec');
23
+ const { getBrowserPath } = require('../../../../visualTest/browser');
24
+ const Input = require('../../../../input').default;
25
+ const ctx = createVtContext();
26
+ applyExecOptions(ctx, options);
27
+ try {
28
+ const browserPath = await getBrowserPath();
29
+ ctx.browserPath = browserPath;
30
+ }
31
+ catch (error) {
32
+ output_1.default.exitError(`${error}`);
33
+ }
34
+ const token = await Input.vtSuiteToken();
35
+ if (!token) {
36
+ output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
37
+ }
38
+ applyToken(ctx, token);
39
+ if (!checkParallel(ctx)) {
40
+ output_1.default.exitError(texts_1.ERR_MISSING_BUILD_ID);
41
+ }
42
+ const app = await createServer(ctx);
43
+ const [mainCommand, ...mainCommandArguments] = command.split(' ');
44
+ output_1.default.normal((0, texts_1.LOG_RUNNING_EXEC_COMMAND)(`${mainCommand} ${[...mainCommandArguments].join(' ')}`));
45
+ const resolved = await which(mainCommand, { nothrow: true });
46
+ if (!resolved) {
47
+ output_1.default.exitError((0, texts_1.ERR_MISSING_EXEC_COMMAND)(`${mainCommand} ${[...mainCommandArguments].join(' ')}`));
48
+ }
49
+ try {
50
+ let t1, t11;
51
+ if (debug) {
52
+ t1 = performance.now();
53
+ }
54
+ const defaultSettings = await getDefaultSettings(ctx);
55
+ setDefaultSettings(defaultSettings);
56
+ const ciAndGitInfo = await getCiAndGitInfo({
57
+ baseBranch: defaultSettings.baseBranch,
58
+ logger: output_1.default.warning,
59
+ });
60
+ applyCiAndCommitInfo(ctx, ciAndGitInfo);
61
+ output_1.default.normal(formattedCiInfo(ciAndGitInfo));
62
+ if (debug) {
63
+ t11 = performance.now();
64
+ }
65
+ const spawnedProcessExitCode = await testExec(mainCommand, [
66
+ ...mainCommandArguments,
67
+ ]);
68
+ if (debug && t11) {
69
+ const t22 = performance.now();
70
+ output_1.default.normal((0, texts_1.DEBUG_EXEC_TEST_COMMAND)(t22 - t11));
71
+ }
72
+ await app.close();
73
+ await finishProcessingSnapshots(ctx, spawnedProcessExitCode);
74
+ showSessionLink();
75
+ if (debug && t1) {
76
+ const t2 = performance.now();
77
+ output_1.default.normal((0, texts_1.DEBUG_EXEC_COMMAND)(t2 - t1));
78
+ }
79
+ process.exit(spawnedProcessExitCode);
80
+ }
81
+ catch (error) {
82
+ await app.close();
83
+ output_1.default.exitError(`${error}`);
84
+ }
85
+ });
86
+ exports.default = commandSessionCreate;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const create_1 = __importDefault(require("./session/create"));
9
+ const close_1 = __importDefault(require("./session/close"));
10
+ const commandSession = (0, utils_1.newCommand)('session', texts_1.DESC_COMMAND_SESSION);
11
+ commandSession.addCommand(create_1.default);
12
+ commandSession.addCommand(close_1.default);
13
+ exports.default = commandSession;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const output_1 = __importDefault(require("../../../output"));
9
+ const commandVisualSetup = (0, utils_1.newCommand)('setup', texts_1.DESC_COMMAND_VISUAL_SETUP);
10
+ commandVisualSetup.action(async () => {
11
+ try {
12
+ const { installBrowser } = require('../../../visualTest/browser');
13
+ await installBrowser();
14
+ output_1.default.exitNormal('');
15
+ }
16
+ catch (error) {
17
+ output_1.default.exitError(`${error}`);
18
+ }
19
+ });
20
+ exports.default = commandVisualSetup;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.waitForSchema = exports.delaySchema = exports.headerSchema = exports.cookieSchema = exports.DEFAULT_SCOPE = void 0;
7
+ exports.parseScopedSelector = parseScopedSelector;
8
+ exports.parseScopedKeyValue = parseScopedKeyValue;
9
+ const zod_1 = require("zod");
10
+ const output_1 = __importDefault(require("../../../../output"));
11
+ exports.DEFAULT_SCOPE = '**';
12
+ function parseScopedSelector(value) {
13
+ return value?.map((v) => {
14
+ let scope, type, selectorValue;
15
+ if (v.includes('::CSS=') || v.includes('::XPATH=')) {
16
+ const [scopePart, ...rest] = v.split('::');
17
+ const [typePart, ...valuePart] = rest.join('::').split('=');
18
+ type = typePart;
19
+ selectorValue = valuePart.join('=');
20
+ scope = scopePart;
21
+ }
22
+ else {
23
+ const [typePart, ...valuePart] = v.split('=');
24
+ type = typePart;
25
+ selectorValue = valuePart.join('=');
26
+ scope = exports.DEFAULT_SCOPE;
27
+ }
28
+ return { scope, type, value: selectorValue };
29
+ });
30
+ }
31
+ function parseScopedKeyValue(rawValue) {
32
+ let scope = exports.DEFAULT_SCOPE;
33
+ let keyValue = rawValue;
34
+ const scopeSeparatorIndex = rawValue.indexOf('::');
35
+ if (scopeSeparatorIndex >= 0) {
36
+ scope = rawValue.slice(0, scopeSeparatorIndex).trim();
37
+ keyValue = rawValue.slice(scopeSeparatorIndex + 2).trim();
38
+ }
39
+ const equalSignIndex = keyValue.indexOf('=');
40
+ if (equalSignIndex <= 0) {
41
+ output_1.default.exitError("Option value must follow pattern '[scope::]key=value' (scope is optional)");
42
+ }
43
+ const key = keyValue.slice(0, equalSignIndex).trim();
44
+ const value = keyValue.slice(equalSignIndex + 1).trim();
45
+ if (!key) {
46
+ output_1.default.exitError('Option key cannot be empty');
47
+ }
48
+ return { scope, key, value };
49
+ }
50
+ exports.cookieSchema = zod_1.z
51
+ .array(zod_1.z
52
+ .string()
53
+ .max(4096, {
54
+ message: 'Cookie must be less than 4096 characters',
55
+ })
56
+ .regex(/^(?:([^:]+)::)?([^=]+)=(.*)$/, {
57
+ message: "Cookie option must follow pattern '[scope::]key=value[;attribute]' (scope is optional)",
58
+ }))
59
+ .optional()
60
+ .transform((value) => value?.map((v) => {
61
+ let scope = exports.DEFAULT_SCOPE;
62
+ let cookieValue = v;
63
+ if (v.includes('::')) {
64
+ const [scopePart, valuePart] = v.split('::');
65
+ scope = scopePart.trim();
66
+ cookieValue = valuePart.trim();
67
+ }
68
+ const cookieParts = cookieValue.split(';').map((part) => part.trim());
69
+ const mainPart = cookieParts[0];
70
+ const firstEqualSignIndex = mainPart.indexOf('=');
71
+ const key = mainPart.slice(0, firstEqualSignIndex).trim();
72
+ const value = mainPart.slice(firstEqualSignIndex + 1).trim();
73
+ const cookie = {
74
+ scope,
75
+ key,
76
+ value,
77
+ httpOnly: false,
78
+ secure: false,
79
+ };
80
+ for (let i = 1; i < cookieParts.length; i++) {
81
+ const part = cookieParts[i].toLowerCase();
82
+ if (part === 'httponly') {
83
+ cookie.httpOnly = true;
84
+ }
85
+ else if (part === 'secure') {
86
+ cookie.secure = true;
87
+ }
88
+ else if (part.startsWith('domain=')) {
89
+ cookie.domain = part.substring(7);
90
+ }
91
+ else if (part.startsWith('path=')) {
92
+ cookie.path = part.substring(5);
93
+ }
94
+ else if (part.startsWith('samesite=')) {
95
+ const sameSiteValue = part.substring(9);
96
+ if (['strict', 'lax', 'none'].includes(sameSiteValue)) {
97
+ cookie.sameSite = (sameSiteValue.charAt(0).toUpperCase() +
98
+ sameSiteValue.slice(1));
99
+ }
100
+ }
101
+ }
102
+ return cookie;
103
+ }));
104
+ exports.headerSchema = zod_1.z
105
+ .array(zod_1.z.string().regex(/^(?:([^:]+)::)?([^=]+)=(.*)$/, {
106
+ message: "Header option must follow pattern '[scope::]key=value' (scope is optional)",
107
+ }))
108
+ .optional()
109
+ .transform((value) => value?.map((v) => {
110
+ const { scope, key, value } = parseScopedKeyValue(v);
111
+ return { scope, key, value };
112
+ }));
113
+ exports.delaySchema = zod_1.z
114
+ .array(zod_1.z.string().regex(/^(?:([^:]+)::)?(\d+)$/, {
115
+ message: "Delay option must follow pattern '[scope::]milliseconds' (scope is optional)",
116
+ }))
117
+ .optional()
118
+ .transform((value) => value?.map((v) => {
119
+ let scope = exports.DEFAULT_SCOPE;
120
+ let milliseconds;
121
+ if (v.includes('::')) {
122
+ const [scopePart, msPart] = v.split('::');
123
+ scope = scopePart.trim();
124
+ milliseconds = Number(msPart);
125
+ }
126
+ else {
127
+ milliseconds = Number(v);
128
+ }
129
+ if (milliseconds < 1 || milliseconds > 60000) {
130
+ throw new zod_1.z.ZodError([
131
+ {
132
+ code: 'custom',
133
+ message: 'Delay must be between 1 and 60000 milliseconds',
134
+ path: [],
135
+ },
136
+ ]);
137
+ }
138
+ return { scope, value: milliseconds };
139
+ }));
140
+ exports.waitForSchema = zod_1.z
141
+ .array(zod_1.z.string().regex(/^(?:([^:]+)::)?(?:(CSS|XPATH))=(.+)$/, {
142
+ message: "WaitFor option must follow pattern '[scope::]type=value' where type must be CSS or XPATH (scope is optional)",
143
+ }))
144
+ .optional()
145
+ .transform(parseScopedSelector);
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const texts_1 = require("../../../texts");
8
+ const output_1 = __importDefault(require("../../../output"));
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const node_zlib_1 = require("node:zlib");
12
+ const commandVisualUpload = (0, utils_1.newCommand)('upload', texts_1.DESC_COMMAND_VISUAL_UPLOAD);
13
+ commandVisualUpload.action(async () => {
14
+ const { getCiAndGitInfo, formattedCiInfo } = require('@buddy-works/ci-info');
15
+ const { getDefaultSettings, sendStorybook } = require('../../../visualTest/requests');
16
+ const { setDefaultSettings } = require('../../../visualTest/snapshots');
17
+ const { createVtContext, applyToken, applyCiAndCommitInfo } = require('../../../visualTest/context');
18
+ const Input = require('../../../input').default;
19
+ const ctx = createVtContext();
20
+ const token = await Input.vtSuiteToken();
21
+ if (!token) {
22
+ output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
23
+ }
24
+ applyToken(ctx, token);
25
+ const currentDirectoryFiles = getCurrentDirectoryFiles();
26
+ if (!isStorybookDirectory(currentDirectoryFiles)) {
27
+ output_1.default.exitError(texts_1.ERR_WRONG_STORYBOOK_DIRECTORY);
28
+ }
29
+ const storybookStoriesIndex = getStorybookStoriesIndex(currentDirectoryFiles);
30
+ const storiesList = getStoriesList(storybookStoriesIndex);
31
+ const storybookSnapshots = getStorybookSnapshots(storiesList);
32
+ const defaultSettings = await getDefaultSettings(ctx);
33
+ setDefaultSettings(defaultSettings);
34
+ const ciAndGitInfo = await getCiAndGitInfo({
35
+ baseBranch: defaultSettings.baseBranch,
36
+ logger: output_1.default.warning,
37
+ });
38
+ applyCiAndCommitInfo(ctx, ciAndGitInfo);
39
+ output_1.default.normal(formattedCiInfo(ciAndGitInfo));
40
+ try {
41
+ const compressedStorybookDirectory = await createCompressedStorybookDirectory(currentDirectoryFiles);
42
+ const { message } = await sendStorybook(ctx, storybookSnapshots, compressedStorybookDirectory);
43
+ output_1.default.exitSuccess(message);
44
+ }
45
+ catch (error) {
46
+ output_1.default.exitError(`${error}`);
47
+ }
48
+ });
49
+ function getCurrentDirectoryFiles() {
50
+ const cwd = process.cwd();
51
+ const filesAndDirectories = (0, node_fs_1.readdirSync)(cwd, {
52
+ encoding: 'utf8',
53
+ recursive: true,
54
+ });
55
+ return filesAndDirectories.filter((file) => {
56
+ const elementPath = node_path_1.default.join(cwd, file);
57
+ const stats = (0, node_fs_1.statSync)(elementPath);
58
+ return stats.isFile();
59
+ });
60
+ }
61
+ async function createCompressedStorybookDirectory(files) {
62
+ const tar = require('tar-stream');
63
+ const cwd = process.cwd();
64
+ const chunks = [];
65
+ return new Promise((resolve, reject) => {
66
+ const compressStream = (0, node_zlib_1.createBrotliCompress)({
67
+ params: {
68
+ [node_zlib_1.constants.BROTLI_PARAM_QUALITY]: 6,
69
+ },
70
+ });
71
+ compressStream.on('data', (chunk) => {
72
+ chunks.push(chunk);
73
+ });
74
+ compressStream.on('end', () => {
75
+ resolve(Buffer.concat(chunks));
76
+ });
77
+ compressStream.on('error', reject);
78
+ const packStream = tar.pack();
79
+ packStream.pipe(compressStream);
80
+ let filesProcessed = 0;
81
+ for (const file of files) {
82
+ const filePath = node_path_1.default.join(cwd, file);
83
+ const stats = (0, node_fs_1.statSync)(filePath);
84
+ const entry = packStream.entry({
85
+ name: file,
86
+ size: stats.size,
87
+ }, (error) => {
88
+ if (error) {
89
+ reject(error);
90
+ }
91
+ else {
92
+ filesProcessed += 1;
93
+ if (filesProcessed === files.length) {
94
+ packStream.finalize();
95
+ }
96
+ }
97
+ });
98
+ const fileStream = (0, node_fs_1.createReadStream)(filePath);
99
+ fileStream.pipe(entry);
100
+ fileStream.on('error', reject);
101
+ }
102
+ });
103
+ }
104
+ function isStorybookDirectory(files) {
105
+ return (files.length > 0 &&
106
+ files.includes('index.html') &&
107
+ files.includes('iframe.html'));
108
+ }
109
+ function getStorybookStoriesIndex(files) {
110
+ const indexFiles = files.find((file) => file === 'index.json');
111
+ if (indexFiles) {
112
+ return indexFiles;
113
+ }
114
+ else {
115
+ return output_1.default.exitError(texts_1.ERR_MISSING_STORYBOOK_INDEX_FILE);
116
+ }
117
+ }
118
+ function getStoriesList(storybookStoriesIndex) {
119
+ const storiesListFile = (0, node_fs_1.readFileSync)(storybookStoriesIndex);
120
+ try {
121
+ const json = JSON.parse(storiesListFile.toString());
122
+ if (![4, 5].includes(json.v)) {
123
+ output_1.default.exitError(texts_1.ERR_UNSUPPORTED_STORYBOOK);
124
+ }
125
+ return json;
126
+ }
127
+ catch {
128
+ output_1.default.exitError(texts_1.ERR_PARSING_STORIES);
129
+ }
130
+ }
131
+ function getStorybookSnapshots(storiesList) {
132
+ const stories = Object.entries(storiesList.entries)
133
+ .filter(([, value]) => value.type === 'story')
134
+ .map(([key, value]) => ({
135
+ id: key,
136
+ name: `${value.title}/${value.name}`,
137
+ }));
138
+ output_1.default.normal((0, texts_1.TXT_STORIES_AMOUNT)(stories.length));
139
+ return stories;
140
+ }
141
+ exports.default = commandVisualUpload;