@datadog/datadog-ci 2.4.1 → 2.5.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/dist/commands/dsyms/upload.js +2 -1
- package/dist/commands/dsyms/upload.js.map +1 -1
- package/dist/commands/flutter-symbols/helpers.js +1 -1
- package/dist/commands/flutter-symbols/helpers.js.map +1 -1
- package/dist/commands/flutter-symbols/upload.js +1 -1
- package/dist/commands/flutter-symbols/upload.js.map +1 -1
- package/dist/commands/lambda/instrument.js +1 -1
- package/dist/commands/lambda/instrument.js.map +1 -1
- package/dist/commands/lambda/uninstrument.js +1 -1
- package/dist/commands/lambda/uninstrument.js.map +1 -1
- package/dist/commands/react-native/upload.js +2 -2
- package/dist/commands/react-native/upload.js.map +1 -1
- package/dist/commands/react-native/xcode.js +5 -0
- package/dist/commands/react-native/xcode.js.map +1 -1
- package/dist/commands/synthetics/api.d.ts +2 -1
- package/dist/commands/synthetics/api.js +7 -0
- package/dist/commands/synthetics/api.js.map +1 -1
- package/dist/commands/synthetics/command.js +11 -2
- package/dist/commands/synthetics/command.js.map +1 -1
- package/dist/commands/synthetics/interfaces.d.ts +4 -1
- package/dist/commands/synthetics/reporters/default.d.ts +3 -2
- package/dist/commands/synthetics/reporters/default.js +19 -5
- package/dist/commands/synthetics/reporters/default.js.map +1 -1
- package/dist/commands/synthetics/reporters/junit.d.ts +2 -2
- package/dist/commands/synthetics/reporters/junit.js +1 -1
- package/dist/commands/synthetics/reporters/junit.js.map +1 -1
- package/dist/commands/synthetics/run-test.js +9 -1
- package/dist/commands/synthetics/run-test.js.map +1 -1
- package/dist/commands/synthetics/utils.d.ts +4 -2
- package/dist/commands/synthetics/utils.js +14 -5
- package/dist/commands/synthetics/utils.js.map +1 -1
- package/dist/helpers/utils.d.ts +2 -2
- package/dist/helpers/utils.js +9 -5
- package/dist/helpers/utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/commands/dsyms/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/dsyms/__tests__/upload.test.js +0 -297
- package/dist/commands/dsyms/__tests__/upload.test.js.map +0 -1
- package/dist/commands/dsyms/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/dsyms/__tests__/utils.test.js +0 -99
- package/dist/commands/dsyms/__tests__/utils.test.js.map +0 -1
- package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/flutter-symbols/__tests__/upload.test.js +0 -538
- package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/git.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/git.test.js +0 -148
- package/dist/commands/git-metadata/__tests__/git.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/library.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/library.test.js +0 -103
- package/dist/commands/git-metadata/__tests__/library.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/upload.test.js +0 -60
- package/dist/commands/git-metadata/__tests__/upload.test.js.map +0 -1
- package/dist/commands/junit/__tests__/api.test.d.ts +0 -1
- package/dist/commands/junit/__tests__/api.test.js +0 -9
- package/dist/commands/junit/__tests__/api.test.js.map +0 -1
- package/dist/commands/junit/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/junit/__tests__/upload.test.js +0 -283
- package/dist/commands/junit/__tests__/upload.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/fixtures.d.ts +0 -49
- package/dist/commands/lambda/__tests__/fixtures.js +0 -88
- package/dist/commands/lambda/__tests__/fixtures.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/commons.test.js +0 -716
- package/dist/commands/lambda/__tests__/functions/commons.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +0 -350
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +0 -583
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +0 -477
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +0 -33
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/instrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/instrument.test.js +0 -1478
- package/dist/commands/lambda/__tests__/instrument.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/loggroup.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/loggroup.test.js +0 -332
- package/dist/commands/lambda/__tests__/loggroup.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/prompt.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/prompt.test.js +0 -235
- package/dist/commands/lambda/__tests__/prompt.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/tags.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/tags.test.js +0 -253
- package/dist/commands/lambda/__tests__/tags.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/uninstrument.test.js +0 -679
- package/dist/commands/lambda/__tests__/uninstrument.test.js.map +0 -1
- package/dist/commands/metric/__tests__/metric.test.d.ts +0 -1
- package/dist/commands/metric/__tests__/metric.test.js +0 -97
- package/dist/commands/metric/__tests__/metric.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/codepush.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/codepush.test.js +0 -153
- package/dist/commands/react-native/__tests__/codepush.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/interfaces.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/interfaces.test.js +0 -52
- package/dist/commands/react-native/__tests__/interfaces.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/upload.test.js +0 -176
- package/dist/commands/react-native/__tests__/upload.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/xcode.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/xcode.test.js +0 -417
- package/dist/commands/react-native/__tests__/xcode.test.js.map +0 -1
- package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/sourcemaps/__tests__/upload.test.js +0 -270
- package/dist/commands/sourcemaps/__tests__/upload.test.js.map +0 -1
- package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/sourcemaps/__tests__/utils.test.js +0 -31
- package/dist/commands/sourcemaps/__tests__/utils.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/api.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/api.test.js +0 -273
- package/dist/commands/synthetics/__tests__/api.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/cli.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/cli.test.js +0 -391
- package/dist/commands/synthetics/__tests__/cli.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/fixtures.d.ts +0 -119
- package/dist/commands/synthetics/__tests__/fixtures.js +0 -386
- package/dist/commands/synthetics/__tests__/fixtures.js.map +0 -1
- package/dist/commands/synthetics/__tests__/mobile.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/mobile.test.js +0 -228
- package/dist/commands/synthetics/__tests__/mobile.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/reporters/default.test.js +0 -202
- package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js +0 -339
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/run-test.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/run-test.test.js +0 -419
- package/dist/commands/synthetics/__tests__/run-test.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +0 -21
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +0 -80
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +0 -111
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/utils.test.js +0 -933
- package/dist/commands/synthetics/__tests__/utils.test.js.map +0 -1
- package/dist/commands/tag/__tests__/tag.test.d.ts +0 -1
- package/dist/commands/tag/__tests__/tag.test.js +0 -77
- package/dist/commands/tag/__tests__/tag.test.js.map +0 -1
- package/dist/commands/trace/__tests__/trace.test.d.ts +0 -1
- package/dist/commands/trace/__tests__/trace.test.js +0 -64
- package/dist/commands/trace/__tests__/trace.test.js.map +0 -1
- package/dist/helpers/__tests__/ci.test.d.ts +0 -1
- package/dist/helpers/__tests__/ci.test.js +0 -197
- package/dist/helpers/__tests__/ci.test.js.map +0 -1
- package/dist/helpers/__tests__/plist.test.d.ts +0 -1
- package/dist/helpers/__tests__/plist.test.js +0 -31
- package/dist/helpers/__tests__/plist.test.js.map +0 -1
- package/dist/helpers/__tests__/retry.test.d.ts +0 -1
- package/dist/helpers/__tests__/retry.test.js +0 -99
- package/dist/helpers/__tests__/retry.test.js.map +0 -1
- package/dist/helpers/__tests__/tags.test.d.ts +0 -1
- package/dist/helpers/__tests__/tags.test.js +0 -17
- package/dist/helpers/__tests__/tags.test.js.map +0 -1
- package/dist/helpers/__tests__/upload.test.d.ts +0 -1
- package/dist/helpers/__tests__/upload.test.js +0 -185
- package/dist/helpers/__tests__/upload.test.js.map +0 -1
- package/dist/helpers/__tests__/user-provided-git.test.d.ts +0 -1
- package/dist/helpers/__tests__/user-provided-git.test.js +0 -119
- package/dist/helpers/__tests__/user-provided-git.test.js.map +0 -1
- package/dist/helpers/__tests__/utils.test.d.ts +0 -1
- package/dist/helpers/__tests__/utils.test.js +0 -382
- package/dist/helpers/__tests__/utils.test.js.map +0 -1
- package/dist/helpers/__tests__/validation.test.d.ts +0 -1
- package/dist/helpers/__tests__/validation.test.js +0 -21
- package/dist/helpers/__tests__/validation.test.js.map +0 -1
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +0 -106
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +0 -1
- package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/format-git-span-data.test.js +0 -67
- package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +0 -1
- package/dist/helpers/git/__tests__/get-git-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/get-git-data.test.js +0 -60
- package/dist/helpers/git/__tests__/get-git-data.test.js.map +0 -1
|
@@ -1,933 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
jest.mock('glob');
|
|
35
|
-
jest.mock('fs');
|
|
36
|
-
jest.mock('child_process');
|
|
37
|
-
jest.unmock('chalk');
|
|
38
|
-
jest.mock('path', () => {
|
|
39
|
-
const actualPath = jest.requireActual('path');
|
|
40
|
-
return Object.assign(Object.assign({}, actualPath), { relative: (from, to) => {
|
|
41
|
-
if (from === '/path/to/project' && to === '/path/to/another-project') {
|
|
42
|
-
return '../another-project';
|
|
43
|
-
}
|
|
44
|
-
if (from === '/path/to/project' && to === '/other-path/to/project') {
|
|
45
|
-
return '../../../other-path/to/project';
|
|
46
|
-
}
|
|
47
|
-
if (from === '/path/to/git/repository' && to === '/path/to/another-project') {
|
|
48
|
-
return '../../another-project';
|
|
49
|
-
}
|
|
50
|
-
if (from === '/path/to/git/repository' && to === '/other-path/to/project') {
|
|
51
|
-
return '../../../../other-path/to/project';
|
|
52
|
-
}
|
|
53
|
-
if (from.endsWith('subfolder') || to.endsWith('subfolder')) {
|
|
54
|
-
return 'subfolder';
|
|
55
|
-
}
|
|
56
|
-
if (to === '..') {
|
|
57
|
-
return '..';
|
|
58
|
-
}
|
|
59
|
-
return '.';
|
|
60
|
-
} });
|
|
61
|
-
});
|
|
62
|
-
const child_process_1 = __importDefault(require("child_process"));
|
|
63
|
-
const fs = __importStar(require("fs"));
|
|
64
|
-
const process_1 = __importDefault(require("process"));
|
|
65
|
-
const axios_1 = __importDefault(require("axios"));
|
|
66
|
-
const deep_extend_1 = __importDefault(require("deep-extend"));
|
|
67
|
-
const glob_1 = __importDefault(require("glob"));
|
|
68
|
-
process_1.default.env.DATADOG_SYNTHETICS_CI_TRIGGER_APP = 'env_default';
|
|
69
|
-
const ciHelpers = __importStar(require("../../../helpers/ci"));
|
|
70
|
-
const api_1 = require("../api");
|
|
71
|
-
const command_1 = require("../command");
|
|
72
|
-
const errors_1 = require("../errors");
|
|
73
|
-
const interfaces_1 = require("../interfaces");
|
|
74
|
-
const mobile = __importStar(require("../mobile"));
|
|
75
|
-
const utils = __importStar(require("../utils"));
|
|
76
|
-
const fixtures_1 = require("./fixtures");
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
jest.restoreAllMocks();
|
|
79
|
-
});
|
|
80
|
-
describe('utils', () => {
|
|
81
|
-
const apiConfiguration = {
|
|
82
|
-
apiKey: '123',
|
|
83
|
-
appKey: '123',
|
|
84
|
-
baseIntakeUrl: 'baseintake',
|
|
85
|
-
baseUnstableUrl: 'baseUnstable',
|
|
86
|
-
baseUrl: 'base',
|
|
87
|
-
proxyOpts: { protocol: 'http' },
|
|
88
|
-
};
|
|
89
|
-
const api = api_1.apiConstructor(apiConfiguration);
|
|
90
|
-
describe('getSuites', () => {
|
|
91
|
-
const GLOB = 'testGlob';
|
|
92
|
-
const FILES = ['file1', 'file2'];
|
|
93
|
-
const FILES_CONTENT = {
|
|
94
|
-
file1: '{"tests":"file1"}',
|
|
95
|
-
file2: '{"tests":"file2"}',
|
|
96
|
-
};
|
|
97
|
-
fs.readFile.mockImplementation((path, opts, callback) => callback(undefined, FILES_CONTENT[path]));
|
|
98
|
-
glob_1.default.mockImplementation((query, callback) => callback(undefined, FILES));
|
|
99
|
-
child_process_1.default.exec.mockImplementation((command, callback) => callback(undefined, '.', ''));
|
|
100
|
-
test('should get suites', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
const suites = yield utils.getSuites(GLOB, fixtures_1.mockReporter);
|
|
102
|
-
expect(JSON.stringify(suites)).toBe(`[{"name":"file1","content":${FILES_CONTENT.file1}},{"name":"file2","content":${FILES_CONTENT.file2}}]`);
|
|
103
|
-
}));
|
|
104
|
-
});
|
|
105
|
-
describe('getFilePathRelativeToRepo', () => {
|
|
106
|
-
afterEach(() => {
|
|
107
|
-
jest.restoreAllMocks();
|
|
108
|
-
});
|
|
109
|
-
test('datadog-ci is not run in a git repository', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
-
const pathToProject = '/path/to/project';
|
|
111
|
-
jest.spyOn(process_1.default, 'cwd').mockImplementation(() => pathToProject);
|
|
112
|
-
child_process_1.default.exec.mockImplementation((command, callback) => callback(Error('Not a git repository'), '', ''));
|
|
113
|
-
// Use the process working directory instead of the git repository's top level.
|
|
114
|
-
yield expect(utils.getFilePathRelativeToRepo('config.json')).resolves.toEqual('config.json');
|
|
115
|
-
yield expect(utils.getFilePathRelativeToRepo('./config.json')).resolves.toEqual('config.json');
|
|
116
|
-
yield expect(utils.getFilePathRelativeToRepo(`${pathToProject}/config.json`)).resolves.toEqual('config.json');
|
|
117
|
-
// Those cases will show a broken hyperlink in the GitLab test report because the file is outside of the project.
|
|
118
|
-
yield expect(utils.getFilePathRelativeToRepo('../config.json')).resolves.toEqual('../config.json');
|
|
119
|
-
yield expect(utils.getFilePathRelativeToRepo('/path/to/another-project/config.json')).resolves.toEqual('../another-project/config.json');
|
|
120
|
-
yield expect(utils.getFilePathRelativeToRepo('/other-path/to/project/config.json')).resolves.toEqual('../../../other-path/to/project/config.json');
|
|
121
|
-
}));
|
|
122
|
-
test('datadog-ci is run in the root of a git repository', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
-
const pathToGitRepository = '/path/to/git/repository';
|
|
124
|
-
jest.spyOn(process_1.default, 'cwd').mockImplementation(() => pathToGitRepository);
|
|
125
|
-
child_process_1.default.exec.mockImplementation((command, callback) => callback(undefined, pathToGitRepository, ''));
|
|
126
|
-
yield expect(utils.getFilePathRelativeToRepo('config.json')).resolves.toEqual('config.json');
|
|
127
|
-
yield expect(utils.getFilePathRelativeToRepo('./config.json')).resolves.toEqual('config.json');
|
|
128
|
-
yield expect(utils.getFilePathRelativeToRepo(`${pathToGitRepository}/config.json`)).resolves.toEqual('config.json');
|
|
129
|
-
yield expect(utils.getFilePathRelativeToRepo('subfolder/config.json')).resolves.toEqual('subfolder/config.json');
|
|
130
|
-
yield expect(utils.getFilePathRelativeToRepo('./subfolder/config.json')).resolves.toEqual('subfolder/config.json');
|
|
131
|
-
yield expect(utils.getFilePathRelativeToRepo(`${pathToGitRepository}/subfolder/config.json`)).resolves.toEqual('subfolder/config.json');
|
|
132
|
-
// Those cases will show a broken hyperlink in the GitLab test report because the file is outside of the repository.
|
|
133
|
-
yield expect(utils.getFilePathRelativeToRepo('../config.json')).resolves.toEqual('../config.json');
|
|
134
|
-
yield expect(utils.getFilePathRelativeToRepo('/path/to/another-project/config.json')).resolves.toEqual('../../another-project/config.json');
|
|
135
|
-
yield expect(utils.getFilePathRelativeToRepo('/other-path/to/project/config.json')).resolves.toEqual('../../../../other-path/to/project/config.json');
|
|
136
|
-
}));
|
|
137
|
-
test('datadog-ci is run in a subfolder of a git repository', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
const pathToGitRepositorySubfolder = '/path/to/git/repository/subfolder';
|
|
139
|
-
jest.spyOn(process_1.default, 'cwd').mockImplementation(() => pathToGitRepositorySubfolder);
|
|
140
|
-
child_process_1.default.exec.mockImplementation((command, callback) => callback(undefined, '/path/to/git/repository', ''));
|
|
141
|
-
// ...so the relative path must be prefixed with the subfolder.
|
|
142
|
-
yield expect(utils.getFilePathRelativeToRepo('config.json')).resolves.toEqual('subfolder/config.json');
|
|
143
|
-
yield expect(utils.getFilePathRelativeToRepo('./config.json')).resolves.toEqual('subfolder/config.json');
|
|
144
|
-
yield expect(utils.getFilePathRelativeToRepo(`${pathToGitRepositorySubfolder}/config.json`)).resolves.toEqual('subfolder/config.json');
|
|
145
|
-
}));
|
|
146
|
-
});
|
|
147
|
-
describe('runTest', () => {
|
|
148
|
-
const fakeId = '123-456-789';
|
|
149
|
-
const fakeTrigger = {
|
|
150
|
-
batch_id: 'bid',
|
|
151
|
-
locations: [],
|
|
152
|
-
};
|
|
153
|
-
test('should run test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
-
jest.spyOn(api, 'triggerTests').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return fakeTrigger; }));
|
|
155
|
-
const output = yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
156
|
-
expect(output).toEqual(fakeTrigger);
|
|
157
|
-
}));
|
|
158
|
-
test('runTests sends batch metadata', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
-
jest.spyOn(ciHelpers, 'getCIMetadata').mockImplementation(() => undefined);
|
|
160
|
-
const payloadMetadataSpy = jest.fn();
|
|
161
|
-
jest.spyOn(axios_1.default, 'create').mockImplementation((() => (request) => {
|
|
162
|
-
payloadMetadataSpy(request.data.metadata);
|
|
163
|
-
if (request.url === '/synthetics/tests/trigger/ci') {
|
|
164
|
-
return { data: fakeTrigger };
|
|
165
|
-
}
|
|
166
|
-
}));
|
|
167
|
-
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
168
|
-
expect(payloadMetadataSpy).toHaveBeenCalledWith(undefined);
|
|
169
|
-
const metadata = {
|
|
170
|
-
ci: { job: { name: 'job' }, pipeline: {}, provider: { name: 'jest' }, stage: {} },
|
|
171
|
-
git: { commit: { author: {}, committer: {}, message: 'test' } },
|
|
172
|
-
};
|
|
173
|
-
jest.spyOn(ciHelpers, 'getCIMetadata').mockImplementation(() => metadata);
|
|
174
|
-
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
175
|
-
expect(payloadMetadataSpy).toHaveBeenCalledWith(metadata);
|
|
176
|
-
}));
|
|
177
|
-
test('runTests api call includes trigger app header', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
-
jest.spyOn(ciHelpers, 'getCIMetadata').mockImplementation(() => undefined);
|
|
179
|
-
const headersMetadataSpy = jest.fn();
|
|
180
|
-
jest.spyOn(axios_1.default, 'create').mockImplementation((() => (request) => {
|
|
181
|
-
headersMetadataSpy(request.headers);
|
|
182
|
-
if (request.url === '/synthetics/tests/trigger/ci') {
|
|
183
|
-
return { data: fakeTrigger };
|
|
184
|
-
}
|
|
185
|
-
}));
|
|
186
|
-
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
187
|
-
expect(headersMetadataSpy).toHaveBeenCalledWith(expect.objectContaining({ 'X-Trigger-App': 'env_default' }));
|
|
188
|
-
utils.setCiTriggerApp('unit_test');
|
|
189
|
-
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
190
|
-
expect(headersMetadataSpy).toHaveBeenCalledWith(expect.objectContaining({ 'X-Trigger-App': 'unit_test' }));
|
|
191
|
-
}));
|
|
192
|
-
test('should run test with publicId from url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
jest.spyOn(api, 'triggerTests').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return fakeTrigger; }));
|
|
194
|
-
const output = yield utils.runTests(api, [
|
|
195
|
-
{
|
|
196
|
-
executionRule: interfaces_1.ExecutionRule.NON_BLOCKING,
|
|
197
|
-
public_id: `http://localhost/synthetics/tests/details/${fakeId}`,
|
|
198
|
-
},
|
|
199
|
-
]);
|
|
200
|
-
expect(output).toEqual(fakeTrigger);
|
|
201
|
-
}));
|
|
202
|
-
test('triggerTests throws', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
-
jest.spyOn(api, 'triggerTests').mockImplementation(() => {
|
|
204
|
-
throw fixtures_1.getAxiosHttpError(502, { message: 'Server Error' });
|
|
205
|
-
});
|
|
206
|
-
yield expect(utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }])).rejects.toThrow(/Failed to trigger tests:/);
|
|
207
|
-
}));
|
|
208
|
-
});
|
|
209
|
-
describe('getTestsToTrigger', () => {
|
|
210
|
-
const fakeTests = {
|
|
211
|
-
'123-456-789': {
|
|
212
|
-
config: { request: { url: 'http://example.org/' } },
|
|
213
|
-
name: 'Fake Test',
|
|
214
|
-
public_id: '123-456-789',
|
|
215
|
-
suite: 'Suite 1',
|
|
216
|
-
},
|
|
217
|
-
'mob-ile-tes': {
|
|
218
|
-
config: {},
|
|
219
|
-
name: 'Fake Mobile Test',
|
|
220
|
-
public_id: 'mob-ile-tes',
|
|
221
|
-
suite: 'Suite 3',
|
|
222
|
-
type: 'mobile',
|
|
223
|
-
},
|
|
224
|
-
'ski-ppe-d01': {
|
|
225
|
-
config: { request: { url: 'http://example.org/' } },
|
|
226
|
-
name: 'Skipped Fake Test',
|
|
227
|
-
options: { ci: { executionRule: 'skipped' } },
|
|
228
|
-
public_id: 'ski-ppe-d01',
|
|
229
|
-
suite: 'Suite 3',
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
beforeEach(() => {
|
|
233
|
-
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
234
|
-
axiosMock.mockImplementation((() => (e) => {
|
|
235
|
-
const publicId = e.url.slice(18);
|
|
236
|
-
if (fakeTests[publicId]) {
|
|
237
|
-
return { data: fakeTests[publicId] };
|
|
238
|
-
}
|
|
239
|
-
throw fixtures_1.getAxiosHttpError(404, { errors: ['Not found'] });
|
|
240
|
-
}));
|
|
241
|
-
});
|
|
242
|
-
test('only existing tests are returned', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
-
const triggerConfigs = [
|
|
244
|
-
{ suite: 'Suite 1', config: {}, id: '123-456-789' },
|
|
245
|
-
{ suite: 'Suite 2', config: {}, id: '987-654-321' },
|
|
246
|
-
{ suite: 'Suite 3', config: {}, id: 'ski-ppe-d01' },
|
|
247
|
-
];
|
|
248
|
-
const { tests, overriddenTestsToTrigger, initialSummary } = yield utils.getTestsToTrigger(api, triggerConfigs, fixtures_1.mockReporter);
|
|
249
|
-
expect(tests).toStrictEqual([fakeTests['123-456-789']]);
|
|
250
|
-
expect(overriddenTestsToTrigger).toStrictEqual([
|
|
251
|
-
{ executionRule: interfaces_1.ExecutionRule.BLOCKING, public_id: '123-456-789' },
|
|
252
|
-
{ executionRule: interfaces_1.ExecutionRule.SKIPPED, public_id: 'ski-ppe-d01' },
|
|
253
|
-
]);
|
|
254
|
-
const expectedSummary = {
|
|
255
|
-
criticalErrors: 0,
|
|
256
|
-
failed: 0,
|
|
257
|
-
failedNonBlocking: 0,
|
|
258
|
-
passed: 0,
|
|
259
|
-
skipped: 1,
|
|
260
|
-
testsNotFound: new Set(['987-654-321']),
|
|
261
|
-
timedOut: 0,
|
|
262
|
-
};
|
|
263
|
-
expect(initialSummary).toEqual(expectedSummary);
|
|
264
|
-
}));
|
|
265
|
-
test('no tests triggered throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
|
-
yield expect(utils.getTestsToTrigger(api, [], fixtures_1.mockReporter)).rejects.toEqual(new errors_1.CiError('NO_TESTS_TO_RUN'));
|
|
267
|
-
}));
|
|
268
|
-
describe('too many tests to trigger', () => {
|
|
269
|
-
const fakeApi = Object.assign(Object.assign({}, api), { getTest: (id) => {
|
|
270
|
-
if (id === 'missing') {
|
|
271
|
-
throw new Error('Request error');
|
|
272
|
-
}
|
|
273
|
-
const test = Object.assign({}, fixtures_1.getApiTest(id));
|
|
274
|
-
if (id === 'skipped') {
|
|
275
|
-
test.options.ci = { executionRule: interfaces_1.ExecutionRule.SKIPPED };
|
|
276
|
-
}
|
|
277
|
-
return Promise.resolve(test);
|
|
278
|
-
} });
|
|
279
|
-
test('trim and warn if from search', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
280
|
-
const tooManyTests = Array(command_1.MAX_TESTS_TO_TRIGGER + 10).fill({ id: 'stu-vwx-yza' });
|
|
281
|
-
const tests = yield utils.getTestsToTrigger(fakeApi, tooManyTests, fixtures_1.mockReporter, true);
|
|
282
|
-
expect(tests.tests.length).toBe(command_1.MAX_TESTS_TO_TRIGGER);
|
|
283
|
-
expect(fixtures_1.mockReporter.initErrors).toMatchSnapshot();
|
|
284
|
-
}));
|
|
285
|
-
test('fails outside of search', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
286
|
-
const tooManyTests = Array(command_1.MAX_TESTS_TO_TRIGGER + 10).fill({ id: 'stu-vwx-yza' });
|
|
287
|
-
yield expect(utils.getTestsToTrigger(fakeApi, tooManyTests, fixtures_1.mockReporter, false)).rejects.toEqual(new Error(`Cannot trigger more than ${command_1.MAX_TESTS_TO_TRIGGER} tests (received ${tooManyTests.length})`));
|
|
288
|
-
}));
|
|
289
|
-
test('does not account for skipped/not found tests outside of search', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
|
-
const tooManyTests = [
|
|
291
|
-
...Array(command_1.MAX_TESTS_TO_TRIGGER).fill({ id: 'stu-vwx-yza' }),
|
|
292
|
-
{ id: 'skipped' },
|
|
293
|
-
{ id: 'missing' },
|
|
294
|
-
];
|
|
295
|
-
const tests = yield utils.getTestsToTrigger(fakeApi, tooManyTests, fixtures_1.mockReporter, true);
|
|
296
|
-
expect(tests.tests.length).toBe(command_1.MAX_TESTS_TO_TRIGGER);
|
|
297
|
-
}));
|
|
298
|
-
});
|
|
299
|
-
test('call uploadApplicationAndOverrideConfig on mobile test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
300
|
-
const spy = jest.spyOn(mobile, 'uploadApplicationAndOverrideConfig').mockImplementation();
|
|
301
|
-
const triggerConfigs = [
|
|
302
|
-
{ suite: 'Suite 1', config: {}, id: '123-456-789' },
|
|
303
|
-
{ suite: 'Suite 3', config: {}, id: 'mob-ile-tes' },
|
|
304
|
-
];
|
|
305
|
-
yield utils.getTestsToTrigger(api, triggerConfigs, fixtures_1.mockReporter);
|
|
306
|
-
expect(spy).toBeCalledTimes(1);
|
|
307
|
-
}));
|
|
308
|
-
});
|
|
309
|
-
describe('getTestAndOverrideConfig', () => {
|
|
310
|
-
test('Forbidden error when getting a test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
311
|
-
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
312
|
-
axiosMock.mockImplementation((() => (e) => {
|
|
313
|
-
throw fixtures_1.getAxiosHttpError(403, { message: 'Forbidden' });
|
|
314
|
-
}));
|
|
315
|
-
const triggerConfig = { suite: 'Suite 1', config: {}, id: '123-456-789' };
|
|
316
|
-
yield expect(() => utils.getTestAndOverrideConfig(api, triggerConfig, fixtures_1.mockReporter, fixtures_1.getSummary())).rejects.toThrow('Failed to get test: could not query https://app.datadoghq.com/example\nForbidden\n');
|
|
317
|
-
}));
|
|
318
|
-
test('Passes when the tunnel is enabled for HTTP test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
-
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
320
|
-
axiosMock.mockImplementation((() => (e) => {
|
|
321
|
-
return { data: { subtype: 'http', public_id: '123-456-789' } };
|
|
322
|
-
}));
|
|
323
|
-
const triggerConfig = { suite: 'Suite 1', config: {}, id: '123-456-789' };
|
|
324
|
-
expect(yield utils.getTestAndOverrideConfig(api, triggerConfig, fixtures_1.mockReporter, fixtures_1.getSummary(), true)).toEqual(expect.objectContaining({ test: expect.objectContaining({ public_id: '123-456-789', subtype: 'http' }) }));
|
|
325
|
-
}));
|
|
326
|
-
test('Passes when the tunnel is enabled for Browser test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
327
|
-
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
328
|
-
axiosMock.mockImplementation((() => (e) => {
|
|
329
|
-
return { data: { type: 'browser', public_id: '123-456-789' } };
|
|
330
|
-
}));
|
|
331
|
-
const triggerConfig = { suite: 'Suite 1', config: {}, id: '123-456-789' };
|
|
332
|
-
expect(yield utils.getTestAndOverrideConfig(api, triggerConfig, fixtures_1.mockReporter, fixtures_1.getSummary(), true)).toEqual(expect.objectContaining({ test: expect.objectContaining({ public_id: '123-456-789', type: 'browser' }) }));
|
|
333
|
-
}));
|
|
334
|
-
test('Fails when the tunnel is enabled for an unsupported test type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
335
|
-
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
336
|
-
axiosMock.mockImplementation((() => (e) => {
|
|
337
|
-
return { data: { subtype: 'grpc', type: 'api', public_id: '123-456-789' } };
|
|
338
|
-
}));
|
|
339
|
-
const triggerConfig = { suite: 'Suite 1', config: {}, id: '123-456-789' };
|
|
340
|
-
yield expect(() => utils.getTestAndOverrideConfig(api, triggerConfig, fixtures_1.mockReporter, fixtures_1.getSummary(), true)).rejects.toThrow('The tunnel is only supported with HTTP API tests and Browser tests (public ID: 123-456-789, type: api, sub-type: grpc).');
|
|
341
|
-
}));
|
|
342
|
-
});
|
|
343
|
-
describe('getOverriddenConfig', () => {
|
|
344
|
-
test('empty config returns simple payload', () => {
|
|
345
|
-
const publicId = 'abc-def-ghi';
|
|
346
|
-
expect(utils.getOverriddenConfig({ public_id: publicId }, publicId, fixtures_1.mockReporter)).toEqual({
|
|
347
|
-
executionRule: interfaces_1.ExecutionRule.BLOCKING,
|
|
348
|
-
public_id: publicId,
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
test('strictest executionRule is forwarded', () => {
|
|
352
|
-
const expectHandledConfigToBe = (expectedExecutionRule, configExecutionRule, testExecutionRule) => {
|
|
353
|
-
const publicId = 'abc-def-ghi';
|
|
354
|
-
const fakeTest = {
|
|
355
|
-
config: { request: { url: 'http://example.org/path' } },
|
|
356
|
-
options: {},
|
|
357
|
-
public_id: publicId,
|
|
358
|
-
};
|
|
359
|
-
if (testExecutionRule) {
|
|
360
|
-
fakeTest.options.ci = { executionRule: testExecutionRule };
|
|
361
|
-
}
|
|
362
|
-
const configOverride = configExecutionRule ? { executionRule: configExecutionRule } : undefined;
|
|
363
|
-
expect(utils.getExecutionRule(fakeTest, configOverride)).toBe(expectedExecutionRule);
|
|
364
|
-
const overriddenConfig = utils.getOverriddenConfig(fakeTest, publicId, fixtures_1.mockReporter, configOverride);
|
|
365
|
-
expect(overriddenConfig.public_id).toBe(publicId);
|
|
366
|
-
expect(overriddenConfig.executionRule).toBe(expectedExecutionRule);
|
|
367
|
-
};
|
|
368
|
-
const BLOCKING = interfaces_1.ExecutionRule.BLOCKING;
|
|
369
|
-
const NON_BLOCKING = interfaces_1.ExecutionRule.NON_BLOCKING;
|
|
370
|
-
const SKIPPED = interfaces_1.ExecutionRule.SKIPPED;
|
|
371
|
-
// No override => BLOCKING
|
|
372
|
-
expectHandledConfigToBe(BLOCKING);
|
|
373
|
-
// CI config overrides only
|
|
374
|
-
expectHandledConfigToBe(BLOCKING, BLOCKING);
|
|
375
|
-
expectHandledConfigToBe(NON_BLOCKING, NON_BLOCKING);
|
|
376
|
-
expectHandledConfigToBe(SKIPPED, SKIPPED);
|
|
377
|
-
// Test config only
|
|
378
|
-
expectHandledConfigToBe(BLOCKING, undefined, BLOCKING);
|
|
379
|
-
expectHandledConfigToBe(NON_BLOCKING, undefined, NON_BLOCKING);
|
|
380
|
-
expectHandledConfigToBe(SKIPPED, undefined, SKIPPED);
|
|
381
|
-
// Strictest executionRule is forwarded
|
|
382
|
-
expectHandledConfigToBe(NON_BLOCKING, BLOCKING, NON_BLOCKING);
|
|
383
|
-
expectHandledConfigToBe(SKIPPED, SKIPPED, BLOCKING);
|
|
384
|
-
expectHandledConfigToBe(SKIPPED, NON_BLOCKING, SKIPPED);
|
|
385
|
-
expectHandledConfigToBe(SKIPPED, SKIPPED, NON_BLOCKING);
|
|
386
|
-
});
|
|
387
|
-
test('startUrl is not parsable', () => {
|
|
388
|
-
const envVars = Object.assign({}, process_1.default.env);
|
|
389
|
-
process_1.default.env = { CUSTOMVAR: '/newPath' };
|
|
390
|
-
const publicId = 'abc-def-ghi';
|
|
391
|
-
const fakeTest = {
|
|
392
|
-
config: { request: { url: 'http://{{ FAKE_VAR }}/path' } },
|
|
393
|
-
public_id: publicId,
|
|
394
|
-
type: 'browser',
|
|
395
|
-
};
|
|
396
|
-
const configOverride = {
|
|
397
|
-
startUrl: 'https://{{FAKE_VAR}}/newPath?oldPath={{CUSTOMVAR}}',
|
|
398
|
-
};
|
|
399
|
-
const expectedUrl = 'https://{{FAKE_VAR}}/newPath?oldPath=/newPath';
|
|
400
|
-
const overriddenConfig = utils.getOverriddenConfig(fakeTest, publicId, fixtures_1.mockReporter, configOverride);
|
|
401
|
-
expect(overriddenConfig.public_id).toBe(publicId);
|
|
402
|
-
expect(overriddenConfig.startUrl).toBe(expectedUrl);
|
|
403
|
-
process_1.default.env = envVars;
|
|
404
|
-
});
|
|
405
|
-
test('config overrides are applied', () => {
|
|
406
|
-
const publicId = 'abc-def-ghi';
|
|
407
|
-
const fakeTest = {
|
|
408
|
-
config: { request: { url: 'http://example.org/path' } },
|
|
409
|
-
public_id: publicId,
|
|
410
|
-
type: 'browser',
|
|
411
|
-
};
|
|
412
|
-
const configOverride = {
|
|
413
|
-
allowInsecureCertificates: true,
|
|
414
|
-
basicAuth: { username: 'user', password: 'password' },
|
|
415
|
-
body: 'body',
|
|
416
|
-
bodyType: 'application/json',
|
|
417
|
-
cookies: 'name=value;',
|
|
418
|
-
defaultStepTimeout: 15,
|
|
419
|
-
deviceIds: ['device_id'],
|
|
420
|
-
executionRule: interfaces_1.ExecutionRule.NON_BLOCKING,
|
|
421
|
-
followRedirects: true,
|
|
422
|
-
headers: { 'header-name': 'value' },
|
|
423
|
-
locations: ['location'],
|
|
424
|
-
pollingTimeout: 60 * 1000,
|
|
425
|
-
retry: { count: 5, interval: 30 },
|
|
426
|
-
startUrl: 'http://127.0.0.1:60/newPath',
|
|
427
|
-
startUrlSubstitutionRegex: '.*',
|
|
428
|
-
tunnel: { host: 'host', id: 'id', privateKey: 'privateKey' },
|
|
429
|
-
variables: { VAR_1: 'value' },
|
|
430
|
-
};
|
|
431
|
-
expect(utils.getOverriddenConfig(fakeTest, publicId, fixtures_1.mockReporter, configOverride)).toEqual(Object.assign(Object.assign({}, configOverride), { public_id: publicId }));
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
describe('hasResultPassed', () => {
|
|
435
|
-
test('complete result', () => {
|
|
436
|
-
const result = {
|
|
437
|
-
device: { height: 1100, id: 'chrome.laptop_large', width: 1440 },
|
|
438
|
-
duration: 0,
|
|
439
|
-
passed: true,
|
|
440
|
-
startUrl: '',
|
|
441
|
-
stepDetails: [],
|
|
442
|
-
};
|
|
443
|
-
expect(utils.hasResultPassed(result, false, false, true)).toBeTruthy();
|
|
444
|
-
expect(utils.hasResultPassed(result, false, true, true)).toBeTruthy();
|
|
445
|
-
result.passed = false;
|
|
446
|
-
expect(utils.hasResultPassed(result, false, false, true)).toBeFalsy();
|
|
447
|
-
expect(utils.hasResultPassed(result, false, true, true)).toBeFalsy();
|
|
448
|
-
});
|
|
449
|
-
test('result with error', () => {
|
|
450
|
-
const result = {
|
|
451
|
-
device: { height: 1100, id: 'chrome.laptop_large', width: 1440 },
|
|
452
|
-
duration: 0,
|
|
453
|
-
failure: {
|
|
454
|
-
code: 'ERRABORTED',
|
|
455
|
-
message: 'Connection aborted',
|
|
456
|
-
},
|
|
457
|
-
passed: false,
|
|
458
|
-
startUrl: '',
|
|
459
|
-
stepDetails: [],
|
|
460
|
-
};
|
|
461
|
-
expect(utils.hasResultPassed(result, false, false, true)).toBeFalsy();
|
|
462
|
-
expect(utils.hasResultPassed(result, false, true, true)).toBeFalsy();
|
|
463
|
-
});
|
|
464
|
-
test('result with unhealthy result', () => {
|
|
465
|
-
const result = {
|
|
466
|
-
device: { height: 1100, id: 'chrome.laptop_large', width: 1440 },
|
|
467
|
-
duration: 0,
|
|
468
|
-
failure: {
|
|
469
|
-
code: 'ERRABORTED',
|
|
470
|
-
message: 'Connection aborted',
|
|
471
|
-
},
|
|
472
|
-
passed: false,
|
|
473
|
-
startUrl: '',
|
|
474
|
-
stepDetails: [],
|
|
475
|
-
unhealthy: true,
|
|
476
|
-
};
|
|
477
|
-
expect(utils.hasResultPassed(result, false, false, true)).toBeTruthy();
|
|
478
|
-
expect(utils.hasResultPassed(result, false, true, true)).toBeFalsy();
|
|
479
|
-
});
|
|
480
|
-
test('result with timeout result', () => {
|
|
481
|
-
const result = {
|
|
482
|
-
device: { height: 1100, id: 'chrome.laptop_large', width: 1440 },
|
|
483
|
-
duration: 0,
|
|
484
|
-
passed: false,
|
|
485
|
-
startUrl: '',
|
|
486
|
-
stepDetails: [],
|
|
487
|
-
};
|
|
488
|
-
expect(utils.hasResultPassed(result, true, true, true)).toBeFalsy();
|
|
489
|
-
expect(utils.hasResultPassed(result, true, true, false)).toBeTruthy();
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
describe('getExecutionRule', () => {
|
|
493
|
-
const cases = [
|
|
494
|
-
[undefined, undefined, interfaces_1.ExecutionRule.BLOCKING],
|
|
495
|
-
[undefined, interfaces_1.ExecutionRule.BLOCKING, interfaces_1.ExecutionRule.BLOCKING],
|
|
496
|
-
[undefined, interfaces_1.ExecutionRule.NON_BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING],
|
|
497
|
-
[interfaces_1.ExecutionRule.BLOCKING, undefined, interfaces_1.ExecutionRule.BLOCKING],
|
|
498
|
-
[interfaces_1.ExecutionRule.BLOCKING, interfaces_1.ExecutionRule.BLOCKING, interfaces_1.ExecutionRule.BLOCKING],
|
|
499
|
-
[interfaces_1.ExecutionRule.BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING],
|
|
500
|
-
[interfaces_1.ExecutionRule.NON_BLOCKING, undefined, interfaces_1.ExecutionRule.NON_BLOCKING],
|
|
501
|
-
[interfaces_1.ExecutionRule.NON_BLOCKING, interfaces_1.ExecutionRule.BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING],
|
|
502
|
-
[interfaces_1.ExecutionRule.NON_BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING, interfaces_1.ExecutionRule.NON_BLOCKING],
|
|
503
|
-
];
|
|
504
|
-
test.each(cases)('Test execution rule: %s, result execution rule: %s. Expected rule: %s', (testRule, resultRule, expectedRule) => {
|
|
505
|
-
const test = fixtures_1.getApiTest('abc-def-ghi');
|
|
506
|
-
expect(utils.getExecutionRule(testRule ? Object.assign(Object.assign({}, test), { options: Object.assign(Object.assign({}, test.options), { ci: { executionRule: testRule } }) }) : test, resultRule ? { executionRule: resultRule } : {})).toEqual(expectedRule);
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
describe('getResultOutcome', () => {
|
|
510
|
-
const cases = [
|
|
511
|
-
[true, interfaces_1.ExecutionRule.BLOCKING, "passed" /* Passed */],
|
|
512
|
-
[true, interfaces_1.ExecutionRule.NON_BLOCKING, "passed-non-blocking" /* PassedNonBlocking */],
|
|
513
|
-
[false, interfaces_1.ExecutionRule.BLOCKING, "failed" /* Failed */],
|
|
514
|
-
[false, interfaces_1.ExecutionRule.NON_BLOCKING, "failed-non-blocking" /* FailedNonBlocking */],
|
|
515
|
-
];
|
|
516
|
-
test.each(cases)('Result passed: %s, execution rule: %s. Expected outcome: %s', (resultPassed, resultRule, expectedOutcome) => {
|
|
517
|
-
jest.spyOn(utils, 'getExecutionRule').mockReturnValue(resultRule);
|
|
518
|
-
const test = fixtures_1.getApiTest('abc-def-ghi');
|
|
519
|
-
const result = fixtures_1.getApiResult('1', test);
|
|
520
|
-
result.executionRule = resultRule;
|
|
521
|
-
result.passed = resultPassed;
|
|
522
|
-
expect(utils.getResultOutcome(result)).toEqual(expectedOutcome);
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
describe('waitForResults', () => {
|
|
526
|
-
beforeAll(() => {
|
|
527
|
-
// We still wait a few milliseconds to avoid the test going crazy on a infinite loop
|
|
528
|
-
// if case of mistakes in the code or test.
|
|
529
|
-
jest.spyOn(utils, 'wait').mockImplementation(() => new Promise((r) => setTimeout(r, 10)));
|
|
530
|
-
});
|
|
531
|
-
const batch = fixtures_1.getBatch();
|
|
532
|
-
const apiTest = fixtures_1.getApiTest(batch.results[0].test_public_id);
|
|
533
|
-
const result = {
|
|
534
|
-
executionRule: interfaces_1.ExecutionRule.BLOCKING,
|
|
535
|
-
location: fixtures_1.mockLocation.display_name,
|
|
536
|
-
passed: true,
|
|
537
|
-
result: fixtures_1.getBrowserServerResult({ passed: true }),
|
|
538
|
-
resultId: batch.results[0].result_id,
|
|
539
|
-
test: apiTest,
|
|
540
|
-
timedOut: false,
|
|
541
|
-
timestamp: 0,
|
|
542
|
-
};
|
|
543
|
-
const pollResult = {
|
|
544
|
-
check: result.test,
|
|
545
|
-
result: result.result,
|
|
546
|
-
resultID: result.resultId,
|
|
547
|
-
timestamp: result.timestamp,
|
|
548
|
-
};
|
|
549
|
-
const trigger = { batch_id: 'bid', locations: [fixtures_1.mockLocation] };
|
|
550
|
-
const mockApi = ({ getBatchImplementation, pollResultsImplementation, } = {}) => {
|
|
551
|
-
const getBatchMock = jest
|
|
552
|
-
.spyOn(api, 'getBatch')
|
|
553
|
-
.mockImplementation(getBatchImplementation || (() => __awaiter(void 0, void 0, void 0, function* () { return JSON.parse(JSON.stringify(batch)); })));
|
|
554
|
-
const pollResultsMock = jest
|
|
555
|
-
.spyOn(api, 'pollResults')
|
|
556
|
-
.mockImplementation(pollResultsImplementation || (() => __awaiter(void 0, void 0, void 0, function* () { return JSON.parse(JSON.stringify([pollResult])); })));
|
|
557
|
-
return { getBatchMock, pollResultsMock };
|
|
558
|
-
};
|
|
559
|
-
test('should poll result ids', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
560
|
-
mockApi();
|
|
561
|
-
expect(yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 120000, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toEqual([result]);
|
|
562
|
-
expect(fixtures_1.mockReporter.resultReceived).toHaveBeenCalledWith(batch.results[0]);
|
|
563
|
-
}));
|
|
564
|
-
test('Test object in each result should be different even if they share the same public ID (config overrides)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
565
|
-
mockApi({
|
|
566
|
-
getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
|
-
return ({
|
|
568
|
-
results: [batch.results[0], Object.assign(Object.assign({}, batch.results[0]), { result_id: '3' })],
|
|
569
|
-
status: 'in_progress',
|
|
570
|
-
});
|
|
571
|
-
}),
|
|
572
|
-
pollResultsImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
573
|
-
return [
|
|
574
|
-
deep_extend_1.default({}, pollResult),
|
|
575
|
-
// The test object from the second result has an overridden start URL
|
|
576
|
-
deep_extend_1.default({}, pollResult, { check: { config: { request: { url: 'https://reddit.com/' } } }, resultID: '3' }),
|
|
577
|
-
];
|
|
578
|
-
}),
|
|
579
|
-
});
|
|
580
|
-
const results = yield utils.waitForResults(api, trigger, [result.test, result.test], { maxPollingTimeout: 0, failOnCriticalErrors: false }, fixtures_1.mockReporter);
|
|
581
|
-
expect(results.map(({ test }) => test.config.request.url)).toEqual(['http://fake.url', 'https://reddit.com/']);
|
|
582
|
-
}));
|
|
583
|
-
test('results should be timed out if global pollingTimeout is exceeded', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
584
|
-
mockApi({
|
|
585
|
-
getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
586
|
-
return ({
|
|
587
|
-
results: [batch.results[0], Object.assign(Object.assign({}, batch.results[0]), { result_id: '3', timed_out: undefined })],
|
|
588
|
-
status: 'in_progress',
|
|
589
|
-
});
|
|
590
|
-
}),
|
|
591
|
-
pollResultsImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
592
|
-
return [
|
|
593
|
-
Object.assign(Object.assign({}, pollResult), { result: Object.assign({}, pollResult.result) }),
|
|
594
|
-
Object.assign(Object.assign({}, pollResult), { result: Object.assign({}, pollResult.result), resultID: '3' }),
|
|
595
|
-
];
|
|
596
|
-
}),
|
|
597
|
-
});
|
|
598
|
-
expect(yield utils.waitForResults(api, trigger, [result.test, result.test], { maxPollingTimeout: 0, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toEqual([
|
|
599
|
-
result,
|
|
600
|
-
Object.assign(Object.assign({}, result), { result: Object.assign(Object.assign({}, result.result), { failure: { code: 'TIMEOUT', message: 'Result timed out' }, passed: false }), resultId: '3', timedOut: true }),
|
|
601
|
-
]);
|
|
602
|
-
}));
|
|
603
|
-
test('results failure should ignore if timed-out', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
604
|
-
// The original failure of a result received between timing-out in batch poll
|
|
605
|
-
// and retrieving it should be ignored in favor of timeout.
|
|
606
|
-
mockApi({
|
|
607
|
-
getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
608
|
-
return ({
|
|
609
|
-
results: [Object.assign(Object.assign({}, batch.results[0]), { timed_out: undefined })],
|
|
610
|
-
status: 'in_progress',
|
|
611
|
-
});
|
|
612
|
-
}),
|
|
613
|
-
pollResultsImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
614
|
-
return [
|
|
615
|
-
Object.assign(Object.assign({}, pollResult), { passed: false, result: Object.assign(Object.assign({}, pollResult.result), { failure: { code: 'FAILURE', message: 'Original failure, should be ignored' }, passed: false }) }),
|
|
616
|
-
];
|
|
617
|
-
}),
|
|
618
|
-
});
|
|
619
|
-
expect(yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 0, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toStrictEqual([
|
|
620
|
-
Object.assign(Object.assign({}, result), { result: Object.assign(Object.assign({}, result.result), { failure: { code: 'TIMEOUT', message: 'Result timed out' }, passed: false }), timedOut: true }),
|
|
621
|
-
]);
|
|
622
|
-
}));
|
|
623
|
-
test('results should be timed out if batch result is timed out', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
624
|
-
const batchWithTimeoutResult = Object.assign(Object.assign({}, batch), { results: [Object.assign(Object.assign({}, batch.results[0]), { timed_out: true })] });
|
|
625
|
-
mockApi({ getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () { return batchWithTimeoutResult; }) });
|
|
626
|
-
expect(yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 120000, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toEqual([
|
|
627
|
-
Object.assign(Object.assign({}, result), { result: Object.assign(Object.assign({}, result.result), { failure: { code: 'TIMEOUT', message: 'Result timed out' }, passed: false }), timedOut: true }),
|
|
628
|
-
]);
|
|
629
|
-
}));
|
|
630
|
-
test('wait between batch polling', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
631
|
-
jest.restoreAllMocks();
|
|
632
|
-
const waitMock = jest.spyOn(utils, 'wait').mockImplementation(() => new Promise((r) => setTimeout(r, 10)));
|
|
633
|
-
let counter = 0;
|
|
634
|
-
mockApi({
|
|
635
|
-
getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
636
|
-
counter += 1;
|
|
637
|
-
return counter === 3 ? batch : Object.assign(Object.assign({}, batch), { status: 'in_progress' });
|
|
638
|
-
}),
|
|
639
|
-
});
|
|
640
|
-
expect(yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 120000, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toEqual([result]);
|
|
641
|
-
expect(counter).toBe(3);
|
|
642
|
-
expect(waitMock).toHaveBeenCalledTimes(2);
|
|
643
|
-
}));
|
|
644
|
-
test('correct number of pass and timeout results', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
645
|
-
const pollTimeoutResult = Object.assign(Object.assign({}, pollResult), { resultID: 'another-id' });
|
|
646
|
-
const batchWithTimeoutResult = Object.assign(Object.assign({}, batch), { results: [batch.results[0], Object.assign(Object.assign({}, batch.results[0]), { timed_out: true, result_id: pollTimeoutResult.resultID })] });
|
|
647
|
-
mockApi({
|
|
648
|
-
getBatchImplementation: () => __awaiter(void 0, void 0, void 0, function* () { return batchWithTimeoutResult; }),
|
|
649
|
-
pollResultsImplementation: () => __awaiter(void 0, void 0, void 0, function* () { return [pollResult, pollTimeoutResult]; }),
|
|
650
|
-
});
|
|
651
|
-
expect(yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 2000, failOnCriticalErrors: false }, fixtures_1.mockReporter)).toEqual([result, Object.assign(Object.assign({}, result), { resultId: pollTimeoutResult.resultID, timedOut: true })]);
|
|
652
|
-
}));
|
|
653
|
-
test('tunnel failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
654
|
-
mockApi();
|
|
655
|
-
const mockTunnel = {
|
|
656
|
-
keepAlive: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
657
|
-
throw new Error('keepAlive failed');
|
|
658
|
-
}),
|
|
659
|
-
};
|
|
660
|
-
yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 2000, failOnCriticalErrors: true }, fixtures_1.mockReporter, mockTunnel);
|
|
661
|
-
expect(fixtures_1.mockReporter.error).toBeCalledWith('The tunnel has stopped working, this may have affected the results.');
|
|
662
|
-
}));
|
|
663
|
-
test('location when tunnel', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
664
|
-
mockApi();
|
|
665
|
-
const mockTunnel = { keepAlive: () => __awaiter(void 0, void 0, void 0, function* () { return true; }) };
|
|
666
|
-
let results = yield utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 2000, failOnCriticalErrors: true }, fixtures_1.mockReporter, mockTunnel);
|
|
667
|
-
expect(results[0].location).toBe('Tunneled');
|
|
668
|
-
const newTest = Object.assign({}, result.test);
|
|
669
|
-
newTest.type = 'api';
|
|
670
|
-
newTest.subtype = 'http';
|
|
671
|
-
results = yield utils.waitForResults(api, trigger, [newTest], { maxPollingTimeout: 2000, failOnCriticalErrors: true }, fixtures_1.mockReporter, mockTunnel);
|
|
672
|
-
expect(results[0].location).toBe('Tunneled');
|
|
673
|
-
newTest.type = 'api';
|
|
674
|
-
newTest.subtype = 'ssl';
|
|
675
|
-
results = yield utils.waitForResults(api, trigger, [newTest], { failOnCriticalErrors: true, maxPollingTimeout: 2000 }, fixtures_1.mockReporter, mockTunnel);
|
|
676
|
-
expect(results[0].location).toBe('Frankfurt (AWS)');
|
|
677
|
-
}));
|
|
678
|
-
test('pollResults throws', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
679
|
-
const { pollResultsMock } = mockApi({
|
|
680
|
-
pollResultsImplementation: () => {
|
|
681
|
-
throw fixtures_1.getAxiosHttpError(502, { message: 'Poll results server error' });
|
|
682
|
-
},
|
|
683
|
-
});
|
|
684
|
-
yield expect(utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 2000 }, fixtures_1.mockReporter)).rejects.toThrowError('Failed to poll results: could not query https://app.datadoghq.com/example\nPoll results server error\n');
|
|
685
|
-
expect(pollResultsMock).toHaveBeenCalledWith([result.resultId]);
|
|
686
|
-
}));
|
|
687
|
-
test('getBatch throws', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
688
|
-
const { getBatchMock } = mockApi({
|
|
689
|
-
getBatchImplementation: () => {
|
|
690
|
-
throw fixtures_1.getAxiosHttpError(502, { message: 'Get batch server error' });
|
|
691
|
-
},
|
|
692
|
-
});
|
|
693
|
-
yield expect(utils.waitForResults(api, trigger, [result.test], { maxPollingTimeout: 2000 }, fixtures_1.mockReporter)).rejects.toThrowError('Failed to get batch: could not query https://app.datadoghq.com/example\nGet batch server error\n');
|
|
694
|
-
expect(getBatchMock).toHaveBeenCalledWith(trigger.batch_id);
|
|
695
|
-
}));
|
|
696
|
-
});
|
|
697
|
-
test('getStrictestExecutionRule', () => {
|
|
698
|
-
const BLOCKING = interfaces_1.ExecutionRule.BLOCKING;
|
|
699
|
-
const NON_BLOCKING = interfaces_1.ExecutionRule.NON_BLOCKING;
|
|
700
|
-
const SKIPPED = interfaces_1.ExecutionRule.SKIPPED;
|
|
701
|
-
expect(utils.getStrictestExecutionRule(BLOCKING, NON_BLOCKING)).toBe(NON_BLOCKING);
|
|
702
|
-
expect(utils.getStrictestExecutionRule(NON_BLOCKING, BLOCKING)).toBe(NON_BLOCKING);
|
|
703
|
-
expect(utils.getStrictestExecutionRule(NON_BLOCKING, SKIPPED)).toBe(SKIPPED);
|
|
704
|
-
expect(utils.getStrictestExecutionRule(BLOCKING, undefined)).toBe(BLOCKING);
|
|
705
|
-
expect(utils.getStrictestExecutionRule(SKIPPED, undefined)).toBe(SKIPPED);
|
|
706
|
-
});
|
|
707
|
-
describe('retry', () => {
|
|
708
|
-
test('retry works fine', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
709
|
-
const result = yield utils.retry(() => __awaiter(void 0, void 0, void 0, function* () { return 42; }), () => 1);
|
|
710
|
-
expect(result).toBe(42);
|
|
711
|
-
}));
|
|
712
|
-
test('retry works fine after some retries', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
713
|
-
let counter = 0;
|
|
714
|
-
const start = +new Date();
|
|
715
|
-
const result = yield utils.retry(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
716
|
-
if (counter === 3) {
|
|
717
|
-
return 42;
|
|
718
|
-
}
|
|
719
|
-
counter += 1;
|
|
720
|
-
throw new Error('');
|
|
721
|
-
}), (retries) => 100 * (retries + 1));
|
|
722
|
-
const end = +new Date();
|
|
723
|
-
const approximateWait = 100 + 100 * 2 + 100 * 3;
|
|
724
|
-
expect(result).toBe(42);
|
|
725
|
-
expect(counter).toBe(3);
|
|
726
|
-
expect(end - start - approximateWait < 50).toBeTruthy();
|
|
727
|
-
}));
|
|
728
|
-
test('retry rethrows after some retries', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
729
|
-
let counter = 0;
|
|
730
|
-
yield expect(utils.retry(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
731
|
-
counter += 1;
|
|
732
|
-
throw new Error('FAILURE');
|
|
733
|
-
}), (retries) => {
|
|
734
|
-
if (retries < 2) {
|
|
735
|
-
return 1;
|
|
736
|
-
}
|
|
737
|
-
})).rejects.toThrowError('FAILURE');
|
|
738
|
-
expect(counter).toBe(3);
|
|
739
|
-
}));
|
|
740
|
-
});
|
|
741
|
-
test('parseVariablesFromCli', () => {
|
|
742
|
-
const mockLogFunction = (message) => undefined;
|
|
743
|
-
expect(utils.parseVariablesFromCli(['TEST=42'], mockLogFunction)).toEqual({ TEST: '42' });
|
|
744
|
-
expect(utils.parseVariablesFromCli(['TEST=42 with some spaces'], mockLogFunction)).toEqual({
|
|
745
|
-
TEST: '42 with some spaces',
|
|
746
|
-
});
|
|
747
|
-
expect(utils.parseVariablesFromCli(['TEST=42=43=44'], mockLogFunction)).toEqual({ TEST: '42=43=44' });
|
|
748
|
-
expect(utils.parseVariablesFromCli(['TEST='], mockLogFunction)).toEqual({ TEST: '' });
|
|
749
|
-
expect(utils.parseVariablesFromCli([''], mockLogFunction)).toBeUndefined();
|
|
750
|
-
expect(utils.parseVariablesFromCli(undefined, mockLogFunction)).toBeUndefined();
|
|
751
|
-
});
|
|
752
|
-
test('getAppBaseURL', () => {
|
|
753
|
-
// Usual datadog site.
|
|
754
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.com', subdomain: '' })).toBe('https://app.datadoghq.com/');
|
|
755
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.com', subdomain: 'app' })).toBe('https://app.datadoghq.com/');
|
|
756
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.com', subdomain: 'myorg' })).toBe('https://myorg.datadoghq.com/');
|
|
757
|
-
// Different top-level domain.
|
|
758
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.eu', subdomain: '' })).toBe('https://app.datadoghq.eu/');
|
|
759
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.eu', subdomain: 'app' })).toBe('https://app.datadoghq.eu/');
|
|
760
|
-
expect(utils.getAppBaseURL({ datadogSite: 'datadoghq.eu', subdomain: 'myorg' })).toBe('https://myorg.datadoghq.eu/');
|
|
761
|
-
// US3/US5-type datadog site: the datadog site's subdomain is replaced by `subdomain` when `subdomain` is custom.
|
|
762
|
-
// The correct Main DC (US3 in this case) is resolved automatically.
|
|
763
|
-
expect(utils.getAppBaseURL({ datadogSite: 'us3.datadoghq.com', subdomain: '' })).toBe('https://us3.datadoghq.com/');
|
|
764
|
-
expect(utils.getAppBaseURL({ datadogSite: 'us3.datadoghq.com', subdomain: 'app' })).toBe('https://us3.datadoghq.com/');
|
|
765
|
-
expect(utils.getAppBaseURL({ datadogSite: 'us3.datadoghq.com', subdomain: 'myorg' })).toBe('https://myorg.datadoghq.com/');
|
|
766
|
-
});
|
|
767
|
-
describe('sortResultsByOutcome', () => {
|
|
768
|
-
const results = fixtures_1.getResults([
|
|
769
|
-
{ executionRule: interfaces_1.ExecutionRule.NON_BLOCKING, passed: false },
|
|
770
|
-
{ executionRule: interfaces_1.ExecutionRule.BLOCKING, passed: true },
|
|
771
|
-
{ executionRule: interfaces_1.ExecutionRule.BLOCKING, passed: false },
|
|
772
|
-
{ executionRule: interfaces_1.ExecutionRule.NON_BLOCKING, passed: true },
|
|
773
|
-
]);
|
|
774
|
-
test('should sort tests with success, non_blocking failures then failures', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
775
|
-
const sortedResults = [...results];
|
|
776
|
-
sortedResults.sort(utils.sortResultsByOutcome());
|
|
777
|
-
expect(sortedResults.map((r) => r.resultId)).toStrictEqual(['3', '1', '0', '2']);
|
|
778
|
-
}));
|
|
779
|
-
});
|
|
780
|
-
describe('Render results', () => {
|
|
781
|
-
const emptySummary = fixtures_1.getSummary();
|
|
782
|
-
const cases = [
|
|
783
|
-
{
|
|
784
|
-
description: '1 API test with 1 config override, 1 result (passed)',
|
|
785
|
-
expected: {
|
|
786
|
-
exitCode: 0,
|
|
787
|
-
summary: Object.assign(Object.assign({}, emptySummary), { passed: 1 }),
|
|
788
|
-
},
|
|
789
|
-
failOnCriticalErrors: false,
|
|
790
|
-
failOnTimeout: false,
|
|
791
|
-
results: fixtures_1.getResults([{ passed: true }]),
|
|
792
|
-
summary: Object.assign({}, emptySummary),
|
|
793
|
-
},
|
|
794
|
-
{
|
|
795
|
-
description: '1 API test with 1 config override, 1 result (failed timeout), no fail on timeout, no fail on critical errors',
|
|
796
|
-
expected: {
|
|
797
|
-
exitCode: 0,
|
|
798
|
-
summary: Object.assign(Object.assign({}, emptySummary), { passed: 1, timedOut: 1 }),
|
|
799
|
-
},
|
|
800
|
-
failOnCriticalErrors: false,
|
|
801
|
-
failOnTimeout: false,
|
|
802
|
-
results: fixtures_1.getResults([{ timedOut: true }]),
|
|
803
|
-
summary: Object.assign({}, emptySummary),
|
|
804
|
-
},
|
|
805
|
-
{
|
|
806
|
-
description: '1 API test with 1 config override, 1 result (failed timeout), fail on timeout, no fail on critical errors',
|
|
807
|
-
expected: {
|
|
808
|
-
exitCode: 1,
|
|
809
|
-
summary: Object.assign(Object.assign({}, emptySummary), { failed: 1 }),
|
|
810
|
-
},
|
|
811
|
-
failOnCriticalErrors: false,
|
|
812
|
-
failOnTimeout: true,
|
|
813
|
-
results: fixtures_1.getResults([{ timedOut: true }]),
|
|
814
|
-
summary: Object.assign({}, emptySummary),
|
|
815
|
-
},
|
|
816
|
-
{
|
|
817
|
-
description: '1 API test with 1 config override, 1 result (failed critical error), no fail on timeout, no fail on critical errors',
|
|
818
|
-
expected: {
|
|
819
|
-
exitCode: 0,
|
|
820
|
-
summary: Object.assign(Object.assign({}, emptySummary), { passed: 1, criticalErrors: 1 }),
|
|
821
|
-
},
|
|
822
|
-
failOnCriticalErrors: false,
|
|
823
|
-
failOnTimeout: false,
|
|
824
|
-
results: fixtures_1.getResults([{ unhealthy: true }]),
|
|
825
|
-
summary: Object.assign({}, emptySummary),
|
|
826
|
-
},
|
|
827
|
-
{
|
|
828
|
-
description: '1 API test with 1 config override, 1 result (failed critical error), no fail on timeout, fail on critical errors',
|
|
829
|
-
expected: {
|
|
830
|
-
exitCode: 1,
|
|
831
|
-
summary: Object.assign(Object.assign({}, emptySummary), { criticalErrors: 0, failed: 1 }),
|
|
832
|
-
},
|
|
833
|
-
failOnCriticalErrors: true,
|
|
834
|
-
failOnTimeout: false,
|
|
835
|
-
results: fixtures_1.getResults([{ unhealthy: true }]),
|
|
836
|
-
summary: Object.assign({}, emptySummary),
|
|
837
|
-
},
|
|
838
|
-
{
|
|
839
|
-
description: '1 API test (blocking) with 4 config overrides (1 skipped), 3 results (1 passed, 1 failed, 1 failed non-blocking)',
|
|
840
|
-
expected: {
|
|
841
|
-
exitCode: 1,
|
|
842
|
-
summary: Object.assign(Object.assign({}, emptySummary), { failed: 1, failedNonBlocking: 1, passed: 1, skipped: 1 }),
|
|
843
|
-
},
|
|
844
|
-
failOnCriticalErrors: false,
|
|
845
|
-
failOnTimeout: false,
|
|
846
|
-
results: fixtures_1.getResults([{ passed: true }, { executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }, {}]),
|
|
847
|
-
summary: Object.assign(Object.assign({}, emptySummary), { skipped: 1 }),
|
|
848
|
-
},
|
|
849
|
-
{
|
|
850
|
-
description: '1 API test (non-blocking) with 4 config overrides (1 skipped), 3 results (1 passed, 1 failed, 1 failed non-blocking)',
|
|
851
|
-
expected: {
|
|
852
|
-
exitCode: 0,
|
|
853
|
-
summary: Object.assign(Object.assign({}, emptySummary), { failedNonBlocking: 2, passed: 1, skipped: 1 }),
|
|
854
|
-
},
|
|
855
|
-
failOnCriticalErrors: false,
|
|
856
|
-
failOnTimeout: false,
|
|
857
|
-
results: fixtures_1.getResults([
|
|
858
|
-
{
|
|
859
|
-
executionRule: interfaces_1.ExecutionRule.NON_BLOCKING,
|
|
860
|
-
testExecutionRule: interfaces_1.ExecutionRule.NON_BLOCKING,
|
|
861
|
-
},
|
|
862
|
-
{ passed: true, testExecutionRule: interfaces_1.ExecutionRule.NON_BLOCKING },
|
|
863
|
-
{
|
|
864
|
-
testExecutionRule: interfaces_1.ExecutionRule.NON_BLOCKING,
|
|
865
|
-
},
|
|
866
|
-
]),
|
|
867
|
-
summary: Object.assign(Object.assign({}, emptySummary), { skipped: 1 }),
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
description: '3 API tests (blocking) with 1 config override each, 3 results (1 failed non-blocking, 1 failed, 1 passed)',
|
|
871
|
-
expected: {
|
|
872
|
-
exitCode: 1,
|
|
873
|
-
summary: Object.assign(Object.assign({}, emptySummary), { failed: 1, failedNonBlocking: 1, passed: 1 }),
|
|
874
|
-
},
|
|
875
|
-
failOnCriticalErrors: false,
|
|
876
|
-
failOnTimeout: false,
|
|
877
|
-
results: fixtures_1.getResults([{}, { passed: true }, { executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]),
|
|
878
|
-
summary: Object.assign({}, emptySummary),
|
|
879
|
-
},
|
|
880
|
-
];
|
|
881
|
-
test.each(cases)('$description', (testCase) => __awaiter(void 0, void 0, void 0, function* () {
|
|
882
|
-
testCase.results.forEach((result) => (result.passed = utils.hasResultPassed(result.result, result.timedOut, testCase.failOnCriticalErrors, testCase.failOnTimeout)));
|
|
883
|
-
const config = Object.assign(Object.assign({}, command_1.DEFAULT_COMMAND_CONFIG), { failOnCriticalErrors: testCase.failOnCriticalErrors, failOnTimeout: testCase.failOnTimeout });
|
|
884
|
-
const startTime = Date.now();
|
|
885
|
-
const exitCode = utils.renderResults({
|
|
886
|
-
config,
|
|
887
|
-
reporter: fixtures_1.mockReporter,
|
|
888
|
-
results: testCase.results,
|
|
889
|
-
startTime,
|
|
890
|
-
summary: testCase.summary,
|
|
891
|
-
});
|
|
892
|
-
expect(fixtures_1.mockReporter.reportStart).toHaveBeenCalledWith({ startTime });
|
|
893
|
-
expect(fixtures_1.mockReporter.resultEnd).toHaveBeenCalledTimes(testCase.results.length);
|
|
894
|
-
const baseUrl = `https://${command_1.DEFAULT_COMMAND_CONFIG.subdomain}.${command_1.DEFAULT_COMMAND_CONFIG.datadogSite}/`;
|
|
895
|
-
for (const result of testCase.results) {
|
|
896
|
-
expect(fixtures_1.mockReporter.resultEnd).toHaveBeenCalledWith(result, baseUrl);
|
|
897
|
-
}
|
|
898
|
-
expect(testCase.summary).toEqual(testCase.expected.summary);
|
|
899
|
-
expect(fixtures_1.mockReporter.runEnd).toHaveBeenCalledWith(testCase.expected.summary, baseUrl);
|
|
900
|
-
expect(exitCode).toBe(testCase.expected.exitCode);
|
|
901
|
-
}));
|
|
902
|
-
});
|
|
903
|
-
describe('getDatadogHost', () => {
|
|
904
|
-
beforeEach(() => {
|
|
905
|
-
jest.restoreAllMocks();
|
|
906
|
-
});
|
|
907
|
-
test('should default to datadog us api', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
908
|
-
process_1.default.env = {};
|
|
909
|
-
expect(utils.getDatadogHost({ useIntake: false, apiVersion: 'v1', config: fixtures_1.ciConfig })).toBe('https://api.datadoghq.com/api/v1');
|
|
910
|
-
expect(utils.getDatadogHost({ useIntake: false, apiVersion: 'unstable', config: fixtures_1.ciConfig })).toBe('https://api.datadoghq.com/api/unstable');
|
|
911
|
-
expect(utils.getDatadogHost({ useIntake: true, apiVersion: 'v1', config: fixtures_1.ciConfig })).toBe('https://intake.synthetics.datadoghq.com/api/v1');
|
|
912
|
-
}));
|
|
913
|
-
test('should use DD_API_HOST_OVERRIDE', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
914
|
-
process_1.default.env = { DD_API_HOST_OVERRIDE: 'https://foobar' };
|
|
915
|
-
expect(utils.getDatadogHost({ useIntake: true, apiVersion: 'v1', config: fixtures_1.ciConfig })).toBe('https://foobar/api/v1');
|
|
916
|
-
expect(utils.getDatadogHost({ useIntake: true, apiVersion: 'v1', config: fixtures_1.ciConfig })).toBe('https://foobar/api/v1');
|
|
917
|
-
}));
|
|
918
|
-
test('should use Synthetics intake endpoint', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
919
|
-
process_1.default.env = {};
|
|
920
|
-
expect(utils.getDatadogHost({
|
|
921
|
-
apiVersion: 'v1',
|
|
922
|
-
config: Object.assign(Object.assign({}, fixtures_1.ciConfig), { datadogSite: 'datadoghq.com' }),
|
|
923
|
-
useIntake: true,
|
|
924
|
-
})).toBe('https://intake.synthetics.datadoghq.com/api/v1');
|
|
925
|
-
expect(utils.getDatadogHost({
|
|
926
|
-
apiVersion: 'v1',
|
|
927
|
-
config: Object.assign(Object.assign({}, fixtures_1.ciConfig), { datadogSite: 'datad0g.com' }),
|
|
928
|
-
useIntake: true,
|
|
929
|
-
})).toBe('https://intake.synthetics.datad0g.com/api/v1');
|
|
930
|
-
}));
|
|
931
|
-
});
|
|
932
|
-
});
|
|
933
|
-
//# sourceMappingURL=utils.test.js.map
|