@datadog/datadog-ci 0.17.4 → 0.17.7

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 (130) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/dist/commands/dependencies/__tests__/helpers/context.d.ts +12 -0
  3. package/dist/commands/dependencies/__tests__/helpers/stream.d.ts +2 -0
  4. package/dist/commands/dependencies/__tests__/helpers/upload.run.d.ts +13 -0
  5. package/dist/commands/dependencies/__tests__/upload.test.d.ts +1 -0
  6. package/dist/commands/dependencies/api.d.ts +2 -0
  7. package/dist/commands/dependencies/index.d.ts +1 -0
  8. package/dist/commands/dependencies/interfaces.d.ts +10 -0
  9. package/dist/commands/dependencies/renderer.d.ts +13 -0
  10. package/dist/commands/dependencies/upload.d.ts +16 -0
  11. package/dist/commands/dsyms/__tests__/upload.test.d.ts +1 -0
  12. package/dist/commands/dsyms/__tests__/utils.test.d.ts +1 -0
  13. package/dist/commands/dsyms/index.d.ts +1 -0
  14. package/dist/commands/dsyms/interfaces.d.ts +7 -0
  15. package/dist/commands/dsyms/renderer.d.ts +9 -0
  16. package/dist/commands/dsyms/upload.d.ts +11 -0
  17. package/dist/commands/dsyms/utils.d.ts +9 -0
  18. package/dist/commands/git-metadata/__tests__/git.test.d.ts +1 -0
  19. package/dist/commands/{commit → git-metadata}/__tests__/git.test.js +0 -0
  20. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +1 -0
  21. package/dist/commands/{commit → git-metadata}/__tests__/upload.test.js +1 -1
  22. package/dist/commands/git-metadata/api.d.ts +3 -0
  23. package/dist/commands/{commit → git-metadata}/api.js +0 -0
  24. package/dist/commands/git-metadata/git.d.ts +8 -0
  25. package/dist/commands/{commit → git-metadata}/git.js +0 -0
  26. package/dist/commands/git-metadata/index.d.ts +1 -0
  27. package/dist/commands/{commit → git-metadata}/index.js +0 -0
  28. package/dist/commands/git-metadata/interfaces.d.ts +9 -0
  29. package/dist/commands/{commit → git-metadata}/interfaces.js +0 -0
  30. package/dist/commands/git-metadata/renderer.d.ts +8 -0
  31. package/dist/commands/{commit → git-metadata}/renderer.js +5 -8
  32. package/dist/commands/git-metadata/upload.d.ts +12 -0
  33. package/dist/commands/{commit → git-metadata}/upload.js +8 -3
  34. package/dist/commands/junit/__tests__/api.test.d.ts +1 -0
  35. package/dist/commands/junit/__tests__/upload.test.d.ts +1 -0
  36. package/dist/commands/junit/api.d.ts +8 -0
  37. package/dist/commands/junit/index.d.ts +1 -0
  38. package/dist/commands/junit/interfaces.d.ts +12 -0
  39. package/dist/commands/junit/renderer.d.ts +8 -0
  40. package/dist/commands/junit/upload.d.ts +15 -0
  41. package/dist/commands/junit/upload.js +8 -25
  42. package/dist/commands/junit/utils.d.ts +1 -0
  43. package/dist/commands/lambda/__tests__/function.test.d.ts +1 -0
  44. package/dist/commands/lambda/__tests__/instrument.test.d.ts +1 -0
  45. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +1 -0
  46. package/dist/commands/lambda/__tests__/tags.test.d.ts +1 -0
  47. package/dist/commands/lambda/constants.d.ts +43 -0
  48. package/dist/commands/lambda/function.d.ts +43 -0
  49. package/dist/commands/lambda/index.d.ts +1 -0
  50. package/dist/commands/lambda/instrument.d.ts +28 -0
  51. package/dist/commands/lambda/interfaces.d.ts +16 -0
  52. package/dist/commands/lambda/loggroup.d.ts +17 -0
  53. package/dist/commands/lambda/tags.d.ts +7 -0
  54. package/dist/commands/sourcemaps/__tests__/git.test.d.ts +1 -0
  55. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +1 -0
  56. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +1 -0
  57. package/dist/commands/sourcemaps/git.d.ts +20 -0
  58. package/dist/commands/sourcemaps/index.d.ts +1 -0
  59. package/dist/commands/sourcemaps/interfaces.d.ts +15 -0
  60. package/dist/commands/sourcemaps/renderer.d.ts +12 -0
  61. package/dist/commands/sourcemaps/upload.d.ts +25 -0
  62. package/dist/commands/sourcemaps/utils.d.ts +3 -0
  63. package/dist/commands/sourcemaps/validation.d.ts +6 -0
  64. package/dist/commands/synthetics/__tests__/api.test.d.ts +1 -0
  65. package/dist/commands/synthetics/__tests__/cli.test.d.ts +1 -0
  66. package/dist/commands/synthetics/__tests__/cli.test.js +232 -0
  67. package/dist/commands/synthetics/__tests__/crypto.test.d.ts +1 -0
  68. package/dist/commands/synthetics/__tests__/fixtures.d.ts +71 -0
  69. package/dist/commands/synthetics/__tests__/fixtures.js +17 -1
  70. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +1 -0
  71. package/dist/commands/synthetics/__tests__/reporters/default.test.js +2 -2
  72. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +1 -0
  73. package/dist/commands/synthetics/__tests__/reporters/junit.test.js +16 -14
  74. package/dist/commands/synthetics/__tests__/run-test.test.d.ts +1 -0
  75. package/dist/commands/synthetics/__tests__/run-test.test.js +42 -313
  76. package/dist/commands/synthetics/__tests__/tunnel.test.d.ts +1 -0
  77. package/dist/commands/synthetics/__tests__/utils.test.d.ts +1 -0
  78. package/dist/commands/synthetics/__tests__/utils.test.js +4 -0
  79. package/dist/commands/synthetics/__tests__/websocket.test.d.ts +1 -0
  80. package/dist/commands/synthetics/__tests__/websocket.test.js +6 -5
  81. package/dist/commands/synthetics/api.d.ts +24 -0
  82. package/dist/commands/synthetics/cli.d.ts +26 -0
  83. package/dist/commands/synthetics/cli.js +229 -0
  84. package/dist/commands/synthetics/crypto.d.ts +5 -0
  85. package/dist/commands/synthetics/errors.d.ts +9 -0
  86. package/dist/commands/synthetics/errors.js +25 -0
  87. package/dist/commands/synthetics/index.d.ts +1 -0
  88. package/dist/commands/synthetics/index.js +2 -2
  89. package/dist/commands/synthetics/interfaces.d.ts +342 -0
  90. package/dist/commands/synthetics/reporters/default.d.ts +18 -0
  91. package/dist/commands/synthetics/reporters/junit.d.ts +95 -0
  92. package/dist/commands/synthetics/reporters/junit.js +45 -19
  93. package/dist/commands/synthetics/run-test.d.ts +74 -0
  94. package/dist/commands/synthetics/run-test.js +135 -319
  95. package/dist/commands/synthetics/tunnel.d.ts +43 -0
  96. package/dist/commands/synthetics/utils.d.ts +26 -0
  97. package/dist/commands/synthetics/utils.js +11 -1
  98. package/dist/commands/synthetics/websocket.d.ts +38 -0
  99. package/dist/commands/trace/__tests__/trace.test.d.ts +1 -0
  100. package/dist/commands/trace/api.d.ts +6 -0
  101. package/dist/commands/trace/index.d.ts +1 -0
  102. package/dist/commands/trace/interfaces.d.ts +23 -0
  103. package/dist/commands/trace/trace.d.ts +17 -0
  104. package/dist/commands/trace/trace.js +32 -3
  105. package/dist/helpers/__tests__/ci.test.d.ts +1 -0
  106. package/dist/helpers/__tests__/ci.test.js +1 -1
  107. package/dist/helpers/__tests__/git.test.d.ts +1 -0
  108. package/dist/helpers/__tests__/retry.test.d.ts +1 -0
  109. package/dist/helpers/__tests__/retry.test.js +98 -0
  110. package/dist/helpers/__tests__/tags.test.d.ts +1 -0
  111. package/dist/helpers/__tests__/upload.test.d.ts +1 -0
  112. package/dist/helpers/__tests__/user-provided-git.test.d.ts +1 -0
  113. package/dist/helpers/__tests__/utils.test.d.ts +1 -0
  114. package/dist/helpers/apikey.d.ts +14 -0
  115. package/dist/helpers/ci.d.ts +15 -0
  116. package/dist/helpers/ci.js +3 -3
  117. package/dist/helpers/errors.d.ts +2 -0
  118. package/dist/helpers/formatting.d.ts +5 -0
  119. package/dist/helpers/git.d.ts +2 -0
  120. package/dist/helpers/interfaces.d.ts +19 -0
  121. package/dist/helpers/metrics.d.ts +11 -0
  122. package/dist/helpers/retry.d.ts +2 -0
  123. package/dist/helpers/retry.js +38 -0
  124. package/dist/helpers/tags.d.ts +28 -0
  125. package/dist/helpers/upload.d.ts +44 -0
  126. package/dist/helpers/upload.js +4 -26
  127. package/dist/helpers/user-provided-git.d.ts +1 -0
  128. package/dist/helpers/utils.d.ts +31 -0
  129. package/dist/index.d.ts +1 -0
  130. package/package.json +4 -3
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import * as simpleGit from 'simple-git';
3
+ import { Writable } from 'stream';
4
+ export declare const newSimpleGit: () => Promise<simpleGit.SimpleGit>;
5
+ export declare const gitRemote: (git: simpleGit.SimpleGit) => Promise<string>;
6
+ export declare const stripCredentials: (remote: string) => string;
7
+ export declare const gitTrackedFiles: (git: simpleGit.SimpleGit) => Promise<string[]>;
8
+ export interface RepositoryData {
9
+ hash: string;
10
+ remote: string;
11
+ trackedFilesMatcher: TrackedFilesMatcher;
12
+ }
13
+ export declare const getRepositoryData: (git: simpleGit.SimpleGit, stdout: Writable, repositoryURL: string | undefined) => Promise<RepositoryData | undefined>;
14
+ export declare class TrackedFilesMatcher {
15
+ private trackedFilenames;
16
+ constructor(trackedFiles: string[]);
17
+ matchSourcemap(stdout: Writable, srcmapPath: string): string[] | undefined;
18
+ matchSources(sources: string[]): string[];
19
+ private getFilename;
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { MultipartPayload } from '../../helpers/upload';
2
+ export declare class Sourcemap {
3
+ gitData?: GitData;
4
+ minifiedFilePath: string;
5
+ minifiedUrl: string;
6
+ sourcemapPath: string;
7
+ constructor(minifiedFilePath: string, minifiedUrl: string, sourcemapPath: string);
8
+ addRepositoryData(gitData: GitData): void;
9
+ asMultipartPayload(cliVersion: string, service: string, version: string, projectPath: string): MultipartPayload;
10
+ }
11
+ export interface GitData {
12
+ gitCommitSha: string;
13
+ gitRepositoryPayload?: string;
14
+ gitRepositoryURL: string;
15
+ }
@@ -0,0 +1,12 @@
1
+ import { UploadStatus } from '../../helpers/upload';
2
+ import { Sourcemap } from './interfaces';
3
+ export declare const renderGitWarning: (errorMessage: string) => string;
4
+ export declare const renderGitDataNotAttachedWarning: (sourcemap: string, errorMessage: string) => string;
5
+ export declare const renderSourcesNotFoundWarning: (sourcemap: string) => string;
6
+ export declare const renderConfigurationError: (error: Error) => string;
7
+ export declare const renderInvalidPrefix: string;
8
+ export declare const renderFailedUpload: (sourcemap: Sourcemap, errorMessage: string) => string;
9
+ export declare const renderRetriedUpload: (payload: Sourcemap, errorMessage: string, attempt: number) => string;
10
+ export declare const renderSuccessfulCommand: (statuses: UploadStatus[], duration: number, dryRun: boolean) => string;
11
+ export declare const renderCommandInfo: (basePath: string, minifiedPathPrefix: string, projectPath: string, releaseVersion: string, service: string, poolLimit: number, dryRun: boolean) => string;
12
+ export declare const renderUpload: (sourcemap: Sourcemap) => string;
@@ -0,0 +1,25 @@
1
+ import { Command } from 'clipanion';
2
+ export declare class UploadCommand extends Command {
3
+ static usage: import("clipanion/lib/advanced").Usage;
4
+ private basePath?;
5
+ private cliVersion;
6
+ private config;
7
+ private disableGit?;
8
+ private dryRun;
9
+ private maxConcurrency;
10
+ private minifiedPathPrefix?;
11
+ private projectPath;
12
+ private releaseVersion?;
13
+ private repositoryURL?;
14
+ private service?;
15
+ constructor();
16
+ execute(): Promise<1 | 0>;
17
+ private addRepositoryDataToPayloads;
18
+ private getMatchingSourcemapFiles;
19
+ private getMinifiedURL;
20
+ private getPayloadsToUpload;
21
+ private getRepositoryPayload;
22
+ private getRequestBuilder;
23
+ private isMinifiedPathPrefixValid;
24
+ private upload;
25
+ }
@@ -0,0 +1,3 @@
1
+ export declare const getMinifiedFilePath: (sourcemapPath: string) => string;
2
+ export declare const getBaseIntakeUrl: () => string;
3
+ export declare const pluralize: (nb: number, singular: string, plural: string) => string;
@@ -0,0 +1,6 @@
1
+ import { Sourcemap } from './interfaces';
2
+ export declare class InvalidPayload extends Error {
3
+ reason: string;
4
+ constructor(reason: string, message?: string);
5
+ }
6
+ export declare const validatePayload: (sourcemap: Sourcemap) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const ciUtils = __importStar(require("../../../helpers/utils"));
32
+ const cli_1 = require("../cli");
33
+ const interfaces_1 = require("../interfaces");
34
+ const runTests = __importStar(require("../run-test"));
35
+ const utils = __importStar(require("../utils"));
36
+ const fixtures_1 = require("./fixtures");
37
+ describe('run-test', () => {
38
+ beforeEach(() => {
39
+ jest.restoreAllMocks();
40
+ jest.spyOn(ciUtils, 'getConfig').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return ({}); }));
41
+ process.env = {};
42
+ });
43
+ describe('getAppBaseURL', () => {
44
+ beforeEach(() => {
45
+ jest.restoreAllMocks();
46
+ });
47
+ test('should default to datadog us', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ process.env = {};
49
+ const command = new cli_1.RunTestCommand();
50
+ expect(command['getAppBaseURL']()).toBe('https://app.datadoghq.com/');
51
+ }));
52
+ test('subdomain should be overridable', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ process.env = { DATADOG_SUBDOMAIN: 'custom' };
54
+ const command = new cli_1.RunTestCommand();
55
+ yield command['resolveConfig']();
56
+ expect(command['getAppBaseURL']()).toBe('https://custom.datadoghq.com/');
57
+ }));
58
+ test('should override subdomain and site', () => __awaiter(void 0, void 0, void 0, function* () {
59
+ process.env = {
60
+ DATADOG_SITE: 'datadoghq.eu',
61
+ DATADOG_SUBDOMAIN: 'custom',
62
+ };
63
+ const command = new cli_1.RunTestCommand();
64
+ yield command['resolveConfig']();
65
+ expect(command['getAppBaseURL']()).toBe('https://custom.datadoghq.eu/');
66
+ }));
67
+ });
68
+ describe('sortTestsByOutcome', () => {
69
+ beforeEach(() => {
70
+ jest.restoreAllMocks();
71
+ });
72
+ const test1 = { options: {}, public_id: 'test1' };
73
+ const test2 = { options: { ci: { executionRule: interfaces_1.ExecutionRule.BLOCKING } }, public_id: 'test2' };
74
+ const test3 = { options: { ci: { executionRule: interfaces_1.ExecutionRule.NON_BLOCKING } }, public_id: 'test3' };
75
+ const test4 = { options: { ci: { executionRule: interfaces_1.ExecutionRule.BLOCKING } }, public_id: 'test4' };
76
+ const test5 = { options: { ci: { executionRule: interfaces_1.ExecutionRule.NON_BLOCKING } }, public_id: 'test5' };
77
+ const tests = [test1, test2, test3, test4, test5];
78
+ const results = {
79
+ test1: [{ result: { passed: true } }],
80
+ test2: [{ result: { passed: true } }],
81
+ test3: [{ result: { passed: true } }],
82
+ test4: [{ result: { passed: false } }],
83
+ test5: [{ result: { passed: false } }],
84
+ };
85
+ test('should sort tests with success, non_blocking failures then failures', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ const command = new cli_1.RunTestCommand();
87
+ tests.sort(command['sortTestsByOutcome'](results));
88
+ expect(tests).toStrictEqual([test3, test1, test2, test5, test4]);
89
+ }));
90
+ });
91
+ describe('resolveConfig', () => {
92
+ beforeEach(() => {
93
+ jest.restoreAllMocks();
94
+ process.env = {};
95
+ jest.spyOn(ciUtils, 'getConfig').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return ({}); }));
96
+ });
97
+ test('override from ENV', () => __awaiter(void 0, void 0, void 0, function* () {
98
+ const overrideEnv = {
99
+ DATADOG_API_KEY: 'fake_api_key',
100
+ DATADOG_APP_KEY: 'fake_app_key',
101
+ DATADOG_SITE: 'datadoghq.eu',
102
+ DATADOG_SUBDOMAIN: 'custom',
103
+ };
104
+ process.env = overrideEnv;
105
+ const command = new cli_1.RunTestCommand();
106
+ yield command['resolveConfig']();
107
+ expect(command['config']).toEqual(Object.assign(Object.assign({}, cli_1.DEFAULT_COMMAND_CONFIG), { apiKey: overrideEnv.DATADOG_API_KEY, appKey: overrideEnv.DATADOG_APP_KEY, datadogSite: overrideEnv.DATADOG_SITE, subdomain: overrideEnv.DATADOG_SUBDOMAIN }));
108
+ }));
109
+ test('override from config file', () => __awaiter(void 0, void 0, void 0, function* () {
110
+ const overrideConfigFile = {
111
+ apiKey: 'fake_api_key',
112
+ appKey: 'fake_app_key',
113
+ configPath: 'fake-datadog-ci.json',
114
+ datadogSite: 'datadoghq.eu',
115
+ failOnCriticalErrors: true,
116
+ failOnTimeout: false,
117
+ files: ['my-new-file'],
118
+ global: { locations: [] },
119
+ locations: [],
120
+ pollingTimeout: 1,
121
+ proxy: { protocol: 'https' },
122
+ publicIds: ['ran-dom-id'],
123
+ subdomain: 'ppa',
124
+ tunnel: true,
125
+ };
126
+ jest.spyOn(ciUtils, 'getConfig').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return overrideConfigFile; }));
127
+ const command = new cli_1.RunTestCommand();
128
+ yield command['resolveConfig']();
129
+ expect(command['config']).toEqual(overrideConfigFile);
130
+ }));
131
+ test('override from CLI', () => __awaiter(void 0, void 0, void 0, function* () {
132
+ const overrideCLI = {
133
+ apiKey: 'fake_api_key',
134
+ appKey: 'fake_app_key',
135
+ configPath: 'fake-datadog-ci.json',
136
+ datadogSite: 'datadoghq.eu',
137
+ failOnCriticalErrors: true,
138
+ failOnTimeout: false,
139
+ files: ['new-file'],
140
+ publicIds: ['ran-dom-id'],
141
+ subdomain: 'new-sub-domain',
142
+ testSearchQuery: 'a-search-query',
143
+ tunnel: true,
144
+ };
145
+ const command = new cli_1.RunTestCommand();
146
+ command['apiKey'] = overrideCLI.apiKey;
147
+ command['appKey'] = overrideCLI.appKey;
148
+ command['configPath'] = overrideCLI.configPath;
149
+ command['datadogSite'] = overrideCLI.datadogSite;
150
+ command['failOnCriticalErrors'] = overrideCLI.failOnCriticalErrors;
151
+ command['failOnTimeout'] = overrideCLI.failOnTimeout;
152
+ command['files'] = overrideCLI.files;
153
+ command['publicIds'] = overrideCLI.publicIds;
154
+ command['subdomain'] = overrideCLI.subdomain;
155
+ command['tunnel'] = overrideCLI.tunnel;
156
+ command['testSearchQuery'] = overrideCLI.testSearchQuery;
157
+ yield command['resolveConfig']();
158
+ expect(command['config']).toEqual(Object.assign(Object.assign({}, cli_1.DEFAULT_COMMAND_CONFIG), { apiKey: 'fake_api_key', appKey: 'fake_app_key', configPath: 'fake-datadog-ci.json', datadogSite: 'datadoghq.eu', failOnCriticalErrors: true, failOnTimeout: false, files: ['new-file'], publicIds: ['ran-dom-id'], subdomain: 'new-sub-domain', testSearchQuery: 'a-search-query', tunnel: true }));
159
+ }));
160
+ test('override from config file < ENV < CLI', () => __awaiter(void 0, void 0, void 0, function* () {
161
+ jest.spyOn(ciUtils, 'getConfig').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
162
+ return ({
163
+ apiKey: 'api_key_config_file',
164
+ appKey: 'app_key_config_file',
165
+ datadogSite: 'datadog.config.file',
166
+ });
167
+ }));
168
+ process.env = {
169
+ DATADOG_API_KEY: 'api_key_env',
170
+ DATADOG_APP_KEY: 'app_key_env',
171
+ };
172
+ const command = new cli_1.RunTestCommand();
173
+ command['apiKey'] = 'api_key_cli';
174
+ yield command['resolveConfig']();
175
+ expect(command['config']).toEqual(Object.assign(Object.assign({}, cli_1.DEFAULT_COMMAND_CONFIG), { apiKey: 'api_key_cli', appKey: 'app_key_env', datadogSite: 'datadog.config.file' }));
176
+ }));
177
+ test('override locations with ENV variable', () => __awaiter(void 0, void 0, void 0, function* () {
178
+ const conf = {
179
+ content: { tests: [{ config: {}, id: 'publicId' }] },
180
+ name: 'Suite 1',
181
+ };
182
+ jest.spyOn(ciUtils, 'parseConfigFile').mockImplementation((config, _) => __awaiter(void 0, void 0, void 0, function* () { return config; }));
183
+ jest.spyOn(utils, 'getSuites').mockImplementation((() => [conf]));
184
+ // Throw to stop the test
185
+ const serverError = new Error('Server Error');
186
+ serverError.response = { data: { errors: ['Bad Gateway'] }, status: 502 };
187
+ serverError.config = { baseURL: 'baseURL', url: 'url' };
188
+ const triggerTests = jest.fn(() => {
189
+ throw serverError;
190
+ });
191
+ const apiHelper = {
192
+ getTest: jest.fn(() => (Object.assign({}, fixtures_1.getApiTest('publicId')))),
193
+ triggerTests,
194
+ };
195
+ const write = jest.fn();
196
+ const command = new cli_1.RunTestCommand();
197
+ command.context = { stdout: { write } };
198
+ command['config'].global = { locations: ['aws:us-east-2'] };
199
+ jest.spyOn(runTests, 'getApiHelper').mockImplementation(() => apiHelper);
200
+ expect(yield command.execute()).toBe(0);
201
+ expect(triggerTests).toHaveBeenCalledWith(expect.objectContaining({
202
+ tests: [{ executionRule: 'blocking', locations: ['aws:us-east-2'], public_id: 'publicId' }],
203
+ }));
204
+ // Env > global
205
+ process.env = {
206
+ DATADOG_SYNTHETICS_LOCATIONS: 'aws:us-east-3',
207
+ };
208
+ expect(yield command.execute()).toBe(0);
209
+ expect(triggerTests).toHaveBeenCalledTimes(2);
210
+ expect(triggerTests).toHaveBeenNthCalledWith(2, expect.objectContaining({
211
+ tests: [{ executionRule: 'blocking', locations: ['aws:us-east-3'], public_id: 'publicId' }],
212
+ }));
213
+ process.env = {
214
+ DATADOG_SYNTHETICS_LOCATIONS: 'aws:us-east-3;aws:us-east-4',
215
+ };
216
+ expect(yield command.execute()).toBe(0);
217
+ expect(triggerTests).toHaveBeenCalledTimes(3);
218
+ expect(triggerTests).toHaveBeenNthCalledWith(3, expect.objectContaining({
219
+ tests: [{ executionRule: 'blocking', locations: ['aws:us-east-3', 'aws:us-east-4'], public_id: 'publicId' }],
220
+ }));
221
+ // Test > env
222
+ const confWithLocation = {
223
+ content: { tests: [{ config: { locations: ['aws:us-east-1'] }, id: 'publicId' }] },
224
+ };
225
+ jest.spyOn(utils, 'getSuites').mockImplementation((() => [confWithLocation]));
226
+ expect(yield command.execute()).toBe(0);
227
+ expect(triggerTests).toHaveBeenCalledWith(expect.objectContaining({
228
+ tests: [{ executionRule: 'blocking', locations: ['aws:us-east-1'], public_id: 'publicId' }],
229
+ }));
230
+ }));
231
+ });
232
+ });
@@ -0,0 +1,71 @@
1
+ /// <reference types="jest" />
2
+ /// <reference types="node" />
3
+ import * as http from 'http';
4
+ import { ProxyConfiguration } from '../../../helpers/utils';
5
+ import { ApiTestResult, BrowserTestResult, CommandConfig, MainReporter, MultiStep, MultiStepsTestResult, PollResult, Step, Test } from '../interfaces';
6
+ export declare const mockReporter: MainReporter;
7
+ export declare const ciConfig: CommandConfig;
8
+ export declare const getApiTest: (publicId: string) => Test;
9
+ export declare const getStep: () => Step;
10
+ export declare const getMultiStep: () => MultiStep;
11
+ export declare const getBrowserPollResult: () => PollResult;
12
+ export declare const getApiPollResult: () => PollResult;
13
+ export declare const getBrowserResult: (opts?: any) => BrowserTestResult;
14
+ export declare const getApiResult: () => ApiTestResult;
15
+ export declare const getMultiStepsResult: () => MultiStepsTestResult;
16
+ export declare const mockSearchResponse: {
17
+ tests: {
18
+ public_id: string;
19
+ }[];
20
+ };
21
+ export declare const mockTestTriggerResponse: {
22
+ locations: string[];
23
+ results: {
24
+ location: number;
25
+ public_id: string;
26
+ result: {
27
+ dc_id: number;
28
+ result: {
29
+ device: string;
30
+ passed: boolean;
31
+ public_id: string;
32
+ };
33
+ result_id: string;
34
+ };
35
+ result_id: string;
36
+ }[];
37
+ triggered_check_ids: string[];
38
+ };
39
+ export declare const mockPollResultResponse: {
40
+ results: {
41
+ dc_id: number;
42
+ result: {
43
+ location: number;
44
+ public_id: string;
45
+ result: {
46
+ dc_id: number;
47
+ result: {
48
+ device: string;
49
+ passed: boolean;
50
+ public_id: string;
51
+ };
52
+ result_id: string;
53
+ };
54
+ result_id: string;
55
+ };
56
+ resultID: string;
57
+ }[];
58
+ };
59
+ export declare const getSyntheticsProxy: () => {
60
+ calls: {
61
+ get: jest.Mock<any, any>;
62
+ poll: jest.Mock<any, any>;
63
+ presignedUrl: jest.Mock<any, any>;
64
+ search: jest.Mock<any, any>;
65
+ trigger: jest.Mock<any, any>;
66
+ tunnel: jest.Mock<any, any>;
67
+ };
68
+ close: () => Promise<[unknown, unknown]>;
69
+ config: ProxyConfiguration;
70
+ server: http.Server;
71
+ };
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getSyntheticsProxy = exports.mockPollResultResponse = exports.mockTestTriggerResponse = exports.mockSearchResponse = exports.getMultiStepsResult = exports.getApiResult = exports.getBrowserResult = exports.getApiPollResult = exports.getBrowserPollResult = exports.getMultiStep = exports.getStep = exports.getApiTest = exports.mockReporter = void 0;
22
+ exports.getSyntheticsProxy = exports.mockPollResultResponse = exports.mockTestTriggerResponse = exports.mockSearchResponse = exports.getMultiStepsResult = exports.getApiResult = exports.getBrowserResult = exports.getApiPollResult = exports.getBrowserPollResult = exports.getMultiStep = exports.getStep = exports.getApiTest = exports.ciConfig = exports.mockReporter = void 0;
23
23
  const http = __importStar(require("http"));
24
24
  const url_1 = require("url");
25
25
  const ws_1 = require("ws");
@@ -39,6 +39,22 @@ exports.mockReporter = {
39
39
  testTrigger: jest.fn(),
40
40
  testWait: jest.fn(),
41
41
  };
42
+ exports.ciConfig = {
43
+ apiKey: '',
44
+ appKey: '',
45
+ configPath: 'datadog-ci.json',
46
+ datadogSite: 'datadoghq.com',
47
+ failOnCriticalErrors: false,
48
+ failOnTimeout: true,
49
+ files: ['{,!(node_modules)/**/}*.synthetics.json'],
50
+ global: {},
51
+ locations: [],
52
+ pollingTimeout: 2 * 60 * 1000,
53
+ proxy: { protocol: 'http' },
54
+ publicIds: [],
55
+ subdomain: 'app',
56
+ tunnel: false,
57
+ };
42
58
  const getApiTest = (publicId) => ({
43
59
  config: {
44
60
  assertions: [],
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const default_1 = require("../../reporters/default");
4
4
  describe('Default reporter', () => {
5
5
  const writeMock = jest.fn();
6
- const commandMock = {
6
+ const mockContext = {
7
7
  context: {
8
8
  stdout: {
9
9
  write: writeMock,
10
10
  },
11
11
  },
12
12
  };
13
- const reporter = new default_1.DefaultReporter(commandMock);
13
+ const reporter = new default_1.DefaultReporter(mockContext);
14
14
  it('should log for each hook', () => {
15
15
  const calls = [
16
16
  ['error', ['error']],
@@ -80,28 +80,29 @@ describe('Junit reporter', () => {
80
80
  }));
81
81
  });
82
82
  describe('testEnd', () => {
83
+ const rest = [[], '', {}, true, true];
83
84
  beforeEach(() => {
84
85
  reporter = new junit_1.JUnitReporter(commandMock);
85
86
  });
86
87
  it('should give a default suite name', () => {
87
- reporter.testEnd(globalTestMock, [], '', {});
88
+ reporter.testEnd(globalTestMock, ...rest);
88
89
  const testsuite = reporter['json'].testsuites.testsuite[0];
89
90
  expect(testsuite.$.name).toBe('Undefined suite');
90
91
  });
91
92
  it('should use the same report for tests from same suite', () => {
92
93
  const testMock = Object.assign({ suite: 'Suite 1' }, globalTestMock);
93
- reporter.testEnd(testMock, [], '', {});
94
- reporter.testEnd(testMock, [], '', {});
94
+ reporter.testEnd(testMock, ...rest);
95
+ reporter.testEnd(testMock, ...rest);
95
96
  expect(reporter['json'].testsuites.testsuite.length).toBe(1);
96
97
  });
97
98
  it('should add stats to the run', () => {
98
- reporter.testEnd(globalTestMock, [], '', {});
99
+ reporter.testEnd(globalTestMock, ...rest);
99
100
  const testsuite = reporter['json'].testsuites.testsuite[0];
100
101
  expect(testsuite.$).toMatchObject(junit_1.getDefaultStats());
101
102
  });
102
103
  it('should report errors', () => {
103
104
  const browserResult1 = Object.assign(Object.assign({}, globalResultMock), { result: Object.assign(Object.assign({}, fixtures_1.getBrowserResult()), { stepDetails: [
104
- Object.assign(Object.assign({}, fixtures_1.getStep()), { browserErrors: [
105
+ Object.assign(Object.assign({}, fixtures_1.getStep()), { allowFailure: true, browserErrors: [
105
106
  {
106
107
  description: 'error description',
107
108
  name: 'error name',
@@ -128,20 +129,21 @@ describe('Junit reporter', () => {
128
129
  message: 'message',
129
130
  } }),
130
131
  ] }) });
131
- reporter.testEnd(globalTestMock, [browserResult1, browserResult2, browserResult3, apiResult], '', {});
132
+ reporter.testEnd(globalTestMock, [browserResult1, browserResult2, browserResult3, apiResult], '', {}, true, true);
132
133
  const testsuite = reporter['json'].testsuites.testsuite[0];
133
134
  const results = [
134
- [2, 1, 1],
135
- [0, 0, 0],
136
- [0, 1, 0],
137
- [0, 1, 0],
135
+ [1, 2, 0, 1],
136
+ [0, 0, 0, 0],
137
+ [0, 0, 1, 0],
138
+ [0, 0, 1, 0],
138
139
  ];
139
140
  const entries = Object.entries(testsuite.testcase);
140
141
  for (const [i, testcase] of entries) {
141
142
  const result = results[i];
142
- expect(testcase.browser_error.length).toBe(result[0]);
143
- expect(testcase.error.length).toBe(result[1]);
144
- expect(testcase.warning.length).toBe(result[2]);
143
+ expect(testcase.allowed_error.length).toBe(result[0]);
144
+ expect(testcase.browser_error.length).toBe(result[1]);
145
+ expect(testcase.error.length).toBe(result[2]);
146
+ expect(testcase.warning.length).toBe(result[3]);
145
147
  }
146
148
  });
147
149
  });
@@ -158,7 +160,7 @@ describe('Junit reporter', () => {
158
160
  }),
159
161
  ] }),
160
162
  });
161
- const suite = reporter['getTestCase'](fixtures_1.getApiTest('123'), resultMock, {});
163
+ const suite = reporter['getTestCase'](fixtures_1.getApiTest('123'), resultMock, {}, true, true);
162
164
  expect(suite.$).toMatchObject(Object.assign(Object.assign({}, junit_1.getDefaultStats()), { errors: 2, failures: 1, tests: 3, warnings: 1 }));
163
165
  });
164
166
  });