UNPKG

4.79 kBJavaScriptView Raw
1"use strict";
2// The MIT License (MIT)
3//
4// Copyright (c) 2019 Firebase
5//
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the 'Software'), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22// SOFTWARE.
23Object.defineProperty(exports, "__esModule", { value: true });
24exports.ResultStorage = exports.ClientInfo = exports.TestMatrix = exports.TestMatrixBuilder = exports._testMatrixWithOpts = exports.testMatrix = exports.TEST_MATRIX_COMPLETE_EVENT_TYPE = exports.SERVICE = exports.PROVIDER = void 0;
25const cloud_functions_1 = require("../cloud-functions");
26/** @internal */
27exports.PROVIDER = "google.testing";
28/** @internal */
29exports.SERVICE = "testing.googleapis.com";
30/** @internal */
31exports.TEST_MATRIX_COMPLETE_EVENT_TYPE = "testMatrix.complete";
32/** Handle events related to Test Lab test matrices. */
33function testMatrix() {
34 return _testMatrixWithOpts({});
35}
36exports.testMatrix = testMatrix;
37/** @internal */
38function _testMatrixWithOpts(opts) {
39 return new TestMatrixBuilder(() => {
40 if (!process.env.GCLOUD_PROJECT) {
41 throw new Error("process.env.GCLOUD_PROJECT is not set.");
42 }
43 return "projects/" + process.env.GCLOUD_PROJECT + "/testMatrices/{matrix}";
44 }, opts);
45}
46exports._testMatrixWithOpts = _testMatrixWithOpts;
47/** Builder used to create Cloud Functions for Test Lab test matrices events. */
48class TestMatrixBuilder {
49 /** @internal */
50 constructor(triggerResource, options) {
51 this.triggerResource = triggerResource;
52 this.options = options;
53 }
54 /** Handle a TestMatrix that reached a final test state. */
55 onComplete(handler) {
56 const dataConstructor = (raw) => {
57 return new TestMatrix(raw.data);
58 };
59 return (0, cloud_functions_1.makeCloudFunction)({
60 provider: exports.PROVIDER,
61 eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
62 triggerResource: this.triggerResource,
63 service: exports.SERVICE,
64 dataConstructor,
65 handler,
66 options: this.options,
67 });
68 }
69}
70exports.TestMatrixBuilder = TestMatrixBuilder;
71/** TestMatrix captures details about a test run. */
72class TestMatrix {
73 /** @internal */
74 constructor(data) {
75 this.testMatrixId = data.testMatrixId;
76 this.createTime = data.timestamp;
77 this.state = data.state;
78 this.outcomeSummary = data.outcomeSummary;
79 this.invalidMatrixDetails = data.invalidMatrixDetails;
80 this.resultStorage = new ResultStorage(data.resultStorage);
81 this.clientInfo = new ClientInfo(data.clientInfo);
82 }
83}
84exports.TestMatrix = TestMatrix;
85/** Information about the client which invoked the test. */
86class ClientInfo {
87 /** @internal */
88 constructor(data) {
89 this.name = (data === null || data === void 0 ? void 0 : data.name) || "";
90 this.details = {};
91 for (const detail of (data === null || data === void 0 ? void 0 : data.clientInfoDetails) || []) {
92 this.details[detail.key] = detail.value || "";
93 }
94 }
95}
96exports.ClientInfo = ClientInfo;
97/** Locations where the test results are stored. */
98class ResultStorage {
99 /** @internal */
100 constructor(data) {
101 var _a, _b, _c;
102 this.gcsPath = (_a = data === null || data === void 0 ? void 0 : data.googleCloudStorage) === null || _a === void 0 ? void 0 : _a.gcsPath;
103 this.toolResultsHistoryId = (_b = data === null || data === void 0 ? void 0 : data.toolResultsHistory) === null || _b === void 0 ? void 0 : _b.historyId;
104 this.toolResultsExecutionId = (_c = data === null || data === void 0 ? void 0 : data.toolResultsExecution) === null || _c === void 0 ? void 0 : _c.executionId;
105 this.resultsUrl = data === null || data === void 0 ? void 0 : data.resultsUrl;
106 }
107}
108exports.ResultStorage = ResultStorage;