@messagevisor/core 0.0.1 → 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/jest.config.js +8 -0
- package/lib/benchmark/index.d.ts +2 -0
- package/lib/benchmark/index.js +417 -0
- package/lib/benchmark/index.js.map +1 -0
- package/lib/builder/index.d.ts +70 -0
- package/lib/builder/index.js +831 -0
- package/lib/builder/index.js.map +1 -0
- package/lib/cli/index.d.ts +28 -0
- package/lib/cli/index.js +182 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/config/index.d.ts +61 -0
- package/lib/config/index.js +255 -0
- package/lib/config/index.js.map +1 -0
- package/lib/create/index.d.ts +2 -0
- package/lib/create/index.js +405 -0
- package/lib/create/index.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +44 -0
- package/lib/datasource/filesystemAdapter.js +424 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +39 -0
- package/lib/datasource/index.js +96 -0
- package/lib/datasource/index.js.map +1 -0
- package/lib/error.d.ts +6 -0
- package/lib/error.js +49 -0
- package/lib/error.js.map +1 -0
- package/lib/evaluate/cli.d.ts +8 -0
- package/lib/evaluate/cli.js +179 -0
- package/lib/evaluate/cli.js.map +1 -0
- package/lib/evaluate/index.d.ts +10 -0
- package/lib/evaluate/index.js +131 -0
- package/lib/evaluate/index.js.map +1 -0
- package/lib/examples/coerceExampleIsoDates.d.ts +12 -0
- package/lib/examples/coerceExampleIsoDates.js +81 -0
- package/lib/examples/coerceExampleIsoDates.js.map +1 -0
- package/lib/examples/index.d.ts +63 -0
- package/lib/examples/index.js +713 -0
- package/lib/examples/index.js.map +1 -0
- package/lib/exporter/index.d.ts +60 -0
- package/lib/exporter/index.js +610 -0
- package/lib/exporter/index.js.map +1 -0
- package/lib/find-duplicates/index.d.ts +41 -0
- package/lib/find-duplicates/index.js +297 -0
- package/lib/find-duplicates/index.js.map +1 -0
- package/lib/generate-code/index.d.ts +11 -0
- package/lib/generate-code/index.js +157 -0
- package/lib/generate-code/index.js.map +1 -0
- package/lib/generate-code/typescript.d.ts +14 -0
- package/lib/generate-code/typescript.js +307 -0
- package/lib/generate-code/typescript.js.map +1 -0
- package/lib/importer/index.d.ts +64 -0
- package/lib/importer/index.js +1092 -0
- package/lib/importer/index.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/info/index.d.ts +17 -0
- package/lib/info/index.js +132 -0
- package/lib/info/index.js.map +1 -0
- package/lib/init/index.d.ts +30 -0
- package/lib/init/index.js +348 -0
- package/lib/init/index.js.map +1 -0
- package/lib/lint/index.d.ts +1 -0
- package/lib/lint/index.js +6 -0
- package/lib/lint/index.js.map +1 -0
- package/lib/linter/attributeSchema.d.ts +7 -0
- package/lib/linter/attributeSchema.js +36 -0
- package/lib/linter/attributeSchema.js.map +1 -0
- package/lib/linter/checkLocaleCircularDependency.d.ts +7 -0
- package/lib/linter/checkLocaleCircularDependency.js +42 -0
- package/lib/linter/checkLocaleCircularDependency.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +3 -0
- package/lib/linter/conditionSchema.js +283 -0
- package/lib/linter/conditionSchema.js.map +1 -0
- package/lib/linter/formatSchema.d.ts +325 -0
- package/lib/linter/formatSchema.js +165 -0
- package/lib/linter/formatSchema.js.map +1 -0
- package/lib/linter/icuStyleLint.d.ts +6 -0
- package/lib/linter/icuStyleLint.js +226 -0
- package/lib/linter/icuStyleLint.js.map +1 -0
- package/lib/linter/index.d.ts +34 -0
- package/lib/linter/index.js +557 -0
- package/lib/linter/index.js.map +1 -0
- package/lib/linter/localeSchema.d.ts +672 -0
- package/lib/linter/localeSchema.js +50 -0
- package/lib/linter/localeSchema.js.map +1 -0
- package/lib/linter/messageSchema.d.ts +35 -0
- package/lib/linter/messageSchema.js +115 -0
- package/lib/linter/messageSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +8 -0
- package/lib/linter/printError.js +41 -0
- package/lib/linter/printError.js.map +1 -0
- package/lib/linter/schema.d.ts +33 -0
- package/lib/linter/schema.js +192 -0
- package/lib/linter/schema.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +8 -0
- package/lib/linter/segmentSchema.js +18 -0
- package/lib/linter/segmentSchema.js.map +1 -0
- package/lib/linter/targetSchema.d.ts +337 -0
- package/lib/linter/targetSchema.js +39 -0
- package/lib/linter/targetSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +71 -0
- package/lib/linter/testSchema.js +165 -0
- package/lib/linter/testSchema.js.map +1 -0
- package/lib/linter/zodHelpers.d.ts +2 -0
- package/lib/linter/zodHelpers.js +15 -0
- package/lib/linter/zodHelpers.js.map +1 -0
- package/lib/list/index.d.ts +8 -0
- package/lib/list/index.js +524 -0
- package/lib/list/index.js.map +1 -0
- package/lib/matrix.d.ts +4 -0
- package/lib/matrix.js +66 -0
- package/lib/matrix.js.map +1 -0
- package/lib/promoter/index.d.ts +65 -0
- package/lib/promoter/index.js +1208 -0
- package/lib/promoter/index.js.map +1 -0
- package/lib/prune/index.d.ts +37 -0
- package/lib/prune/index.js +673 -0
- package/lib/prune/index.js.map +1 -0
- package/lib/sets.d.ts +10 -0
- package/lib/sets.js +120 -0
- package/lib/sets.js.map +1 -0
- package/lib/tester/cliFormat.d.ts +8 -0
- package/lib/tester/cliFormat.js +15 -0
- package/lib/tester/cliFormat.js.map +1 -0
- package/lib/tester/index.d.ts +35 -0
- package/lib/tester/index.js +713 -0
- package/lib/tester/index.js.map +1 -0
- package/lib/tester/matrix.d.ts +14 -0
- package/lib/tester/matrix.js +76 -0
- package/lib/tester/matrix.js.map +1 -0
- package/lib/tester/prettyDuration.d.ts +1 -0
- package/lib/tester/prettyDuration.js +30 -0
- package/lib/tester/prettyDuration.js.map +1 -0
- package/lib/tester/printTestResult.d.ts +2 -0
- package/lib/tester/printTestResult.js +32 -0
- package/lib/tester/printTestResult.js.map +1 -0
- package/lib/tester/types.d.ts +29 -0
- package/lib/tester/types.js +3 -0
- package/lib/tester/types.js.map +1 -0
- package/package.json +41 -13
- package/src/benchmark/index.spec.ts +375 -0
- package/src/benchmark/index.ts +433 -0
- package/src/builder/index.spec.ts +822 -0
- package/src/builder/index.ts +920 -0
- package/src/cli/index.spec.ts +54 -0
- package/src/cli/index.ts +150 -0
- package/src/config/index.spec.ts +70 -0
- package/src/config/index.ts +259 -0
- package/src/create/index.spec.ts +272 -0
- package/src/create/index.ts +295 -0
- package/src/datasource/filesystemAdapter.ts +313 -0
- package/src/datasource/index.ts +135 -0
- package/src/error.ts +33 -0
- package/src/evaluate/cli.spec.ts +368 -0
- package/src/evaluate/cli.ts +130 -0
- package/src/evaluate/index.ts +161 -0
- package/src/examples/coerceExampleIsoDates.spec.ts +81 -0
- package/src/examples/coerceExampleIsoDates.ts +98 -0
- package/src/examples/index.spec.ts +453 -0
- package/src/examples/index.ts +854 -0
- package/src/exporter/index.spec.ts +443 -0
- package/src/exporter/index.ts +643 -0
- package/src/find-duplicates/index.spec.ts +289 -0
- package/src/find-duplicates/index.ts +314 -0
- package/src/generate-code/index.ts +92 -0
- package/src/generate-code/typescript.spec.ts +241 -0
- package/src/generate-code/typescript.ts +284 -0
- package/src/importer/index.spec.ts +1101 -0
- package/src/importer/index.ts +1190 -0
- package/src/index.ts +18 -0
- package/src/info/index.ts +67 -0
- package/src/init/index.spec.ts +279 -0
- package/src/init/index.ts +292 -0
- package/src/lint/index.ts +1 -0
- package/src/linter/attributeSchema.ts +38 -0
- package/src/linter/checkLocaleCircularDependency.ts +51 -0
- package/src/linter/conditionSchema.ts +386 -0
- package/src/linter/formatSchema.ts +170 -0
- package/src/linter/icuStyleLint.ts +312 -0
- package/src/linter/index.spec.ts +824 -0
- package/src/linter/index.ts +460 -0
- package/src/linter/localeSchema.ts +70 -0
- package/src/linter/messageSchema.ts +152 -0
- package/src/linter/printError.ts +52 -0
- package/src/linter/schema.ts +230 -0
- package/src/linter/segmentSchema.ts +15 -0
- package/src/linter/targetSchema.ts +50 -0
- package/src/linter/testSchema.spec.ts +405 -0
- package/src/linter/testSchema.ts +239 -0
- package/src/linter/zodHelpers.ts +16 -0
- package/src/list/index.spec.ts +431 -0
- package/src/list/index.ts +463 -0
- package/src/matrix.ts +69 -0
- package/src/promoter/index.spec.ts +584 -0
- package/src/promoter/index.ts +1267 -0
- package/src/prune/index.spec.ts +418 -0
- package/src/prune/index.ts +693 -0
- package/src/sets.ts +74 -0
- package/src/tester/cliFormat.ts +11 -0
- package/src/tester/featurevisorIntegration.spec.ts +101 -0
- package/src/tester/index.spec.ts +577 -0
- package/src/tester/index.ts +679 -0
- package/src/tester/matrix.ts +106 -0
- package/src/tester/prettyDuration.ts +34 -0
- package/src/tester/printTestResult.ts +40 -0
- package/src/tester/types.ts +32 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.typecheck.json +4 -0
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
47
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
57
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
+
switch (op[0]) {
|
|
65
|
+
case 0: case 1: t = op; break;
|
|
66
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
+
default:
|
|
70
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
+
if (t[2]) _.ops.pop();
|
|
75
|
+
_.trys.pop(); continue;
|
|
76
|
+
}
|
|
77
|
+
op = body.call(thisArg, _);
|
|
78
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
83
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
84
|
+
if (ar || !(i in from)) {
|
|
85
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
86
|
+
ar[i] = from[i];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
+
exports.testPlugin = void 0;
|
|
93
|
+
exports.testProject = testProject;
|
|
94
|
+
exports.testProjectSets = testProjectSets;
|
|
95
|
+
var fs = __importStar(require("fs"));
|
|
96
|
+
var path = __importStar(require("path"));
|
|
97
|
+
var sdk_1 = require("@messagevisor/sdk");
|
|
98
|
+
var builder_1 = require("../builder");
|
|
99
|
+
var evaluate_1 = require("../evaluate");
|
|
100
|
+
var sets_1 = require("../sets");
|
|
101
|
+
var cliFormat_1 = require("./cliFormat");
|
|
102
|
+
var matrix_1 = require("./matrix");
|
|
103
|
+
var prettyDuration_1 = require("./prettyDuration");
|
|
104
|
+
var printTestResult_1 = require("./printTestResult");
|
|
105
|
+
function isPlainObject(value) {
|
|
106
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
function containsSubset(actual, expected) {
|
|
109
|
+
if (isPlainObject(expected)) {
|
|
110
|
+
if (!isPlainObject(actual)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return Object.keys(expected).every(function (key) { return containsSubset(actual[key], expected[key]); });
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(expected)) {
|
|
116
|
+
return (Array.isArray(actual) &&
|
|
117
|
+
expected.length === actual.length &&
|
|
118
|
+
expected.every(function (value, index) { return containsSubset(actual[index], value); }));
|
|
119
|
+
}
|
|
120
|
+
return actual === expected;
|
|
121
|
+
}
|
|
122
|
+
function normalizeTestValue(value) {
|
|
123
|
+
if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(value)) {
|
|
124
|
+
var date = new Date(value);
|
|
125
|
+
if (!Number.isNaN(date.getTime())) {
|
|
126
|
+
return date;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(value)) {
|
|
130
|
+
return value.map(normalizeTestValue);
|
|
131
|
+
}
|
|
132
|
+
if (isPlainObject(value)) {
|
|
133
|
+
return Object.fromEntries(Object.entries(value).map(function (_a) {
|
|
134
|
+
var key = _a[0], entry = _a[1];
|
|
135
|
+
return [key, normalizeTestValue(entry)];
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
function createAssertion(description) {
|
|
141
|
+
return {
|
|
142
|
+
description: description,
|
|
143
|
+
duration: 0,
|
|
144
|
+
passed: true,
|
|
145
|
+
errors: [],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function failAssertion(assertion, error) {
|
|
149
|
+
assertion.passed = false;
|
|
150
|
+
assertion.errors.push(error);
|
|
151
|
+
}
|
|
152
|
+
function shouldRunAssertion(description, options) {
|
|
153
|
+
if (!options.assertionPattern) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return new RegExp(options.assertionPattern).test(description);
|
|
157
|
+
}
|
|
158
|
+
function getAssertionPrefix(assertion) {
|
|
159
|
+
if (typeof assertion.matrixIndex === "number") {
|
|
160
|
+
return "Assertion #".concat((assertion.assertionIndex || 0) + 1, ", matrix #").concat(assertion.matrixIndex + 1, ": ");
|
|
161
|
+
}
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
function getMessageAssertionDescription(messageKey, assertion) {
|
|
165
|
+
if (assertion.description) {
|
|
166
|
+
return assertion.description;
|
|
167
|
+
}
|
|
168
|
+
return "".concat(getAssertionPrefix(assertion)).concat(assertion.target || "web", "/").concat(assertion.locale, ": ").concat(messageKey);
|
|
169
|
+
}
|
|
170
|
+
function getSegmentAssertionDescription(testSegmentKey, assertion) {
|
|
171
|
+
if (assertion.description) {
|
|
172
|
+
return assertion.description;
|
|
173
|
+
}
|
|
174
|
+
return "".concat(getAssertionPrefix(assertion)).concat(assertion.segment || testSegmentKey, " with ").concat(JSON.stringify(assertion.context || {}));
|
|
175
|
+
}
|
|
176
|
+
function getTargetAssertionDescription(targetKey, assertion) {
|
|
177
|
+
if (assertion.description) {
|
|
178
|
+
return assertion.description;
|
|
179
|
+
}
|
|
180
|
+
var hasStructureChecks = typeof assertion.expectedFormats !== "undefined" ||
|
|
181
|
+
(assertion.expectedToIncludeMessages || []).length > 0 ||
|
|
182
|
+
(assertion.expectedToNotIncludeMessages || []).length > 0;
|
|
183
|
+
var hasEvaluation = typeof assertion.rawMessage !== "undefined" || typeof assertion.message !== "undefined";
|
|
184
|
+
if (hasStructureChecks && hasEvaluation) {
|
|
185
|
+
return "".concat(getAssertionPrefix(assertion)).concat(targetKey, "/").concat(assertion.locale, " structure + evaluation");
|
|
186
|
+
}
|
|
187
|
+
if (hasEvaluation) {
|
|
188
|
+
return "".concat(getAssertionPrefix(assertion)).concat(targetKey, "/").concat(assertion.locale, " evaluation");
|
|
189
|
+
}
|
|
190
|
+
return "".concat(getAssertionPrefix(assertion)).concat(targetKey, "/").concat(assertion.locale);
|
|
191
|
+
}
|
|
192
|
+
function getLocaleAssertionDescription(localeKey, assertion) {
|
|
193
|
+
if (assertion.description) {
|
|
194
|
+
return assertion.description;
|
|
195
|
+
}
|
|
196
|
+
var targetSuffix = assertion.target ? "/".concat(assertion.target) : "";
|
|
197
|
+
var hasFormats = typeof assertion.expectedFormats !== "undefined";
|
|
198
|
+
var hasEvaluation = typeof assertion.rawMessage !== "undefined" &&
|
|
199
|
+
typeof assertion.expectedTranslation !== "undefined";
|
|
200
|
+
if (hasFormats && hasEvaluation) {
|
|
201
|
+
return "".concat(getAssertionPrefix(assertion)).concat(localeKey).concat(targetSuffix, " formats + evaluation");
|
|
202
|
+
}
|
|
203
|
+
if (hasEvaluation) {
|
|
204
|
+
return "".concat(getAssertionPrefix(assertion)).concat(localeKey).concat(targetSuffix, " evaluation");
|
|
205
|
+
}
|
|
206
|
+
return "".concat(getAssertionPrefix(assertion)).concat(localeKey).concat(targetSuffix, " formats");
|
|
207
|
+
}
|
|
208
|
+
function getTestFilePath(projectConfig, testKey) {
|
|
209
|
+
var extension = projectConfig.parser.extension || "yml";
|
|
210
|
+
var basePath = path.join.apply(path, __spreadArray([projectConfig.testsDirectoryPath], testKey.split(projectConfig.namespaceCharacter), false));
|
|
211
|
+
var specPath = "".concat(basePath, ".spec.").concat(extension);
|
|
212
|
+
var legacyPath = "".concat(basePath, ".").concat(extension);
|
|
213
|
+
return path.relative(process.cwd(), fs.existsSync(specPath) ? specPath : legacyPath);
|
|
214
|
+
}
|
|
215
|
+
function runTest(projectConfig, datasource, testKey, test, revision, options) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
var startTime, type, subject, filePath, result, _loop_1, _i, _a, rawAssertion, segmentKeys, segments, _b, _c, _d, _e, rawAssertion, description, assertionStartTime, assertion, actual, _f, _g, rawAssertion, description, assertionStartTime, assertion, datafile, translationKeys, _h, _j, messageKey, _k, _l, messageKey, messagevisor, values, actual, _m, localeKeys, targetKeys, _o, locales, targets, localesByKey, targetsByKey, _p, _q, rawAssertion, description, assertionStartTime, assertion, target, formats, messagevisor, actual;
|
|
218
|
+
var _r;
|
|
219
|
+
var _this = this;
|
|
220
|
+
return __generator(this, function (_s) {
|
|
221
|
+
switch (_s.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
startTime = Date.now();
|
|
224
|
+
type = test.message
|
|
225
|
+
? "message"
|
|
226
|
+
: test.segment
|
|
227
|
+
? "segment"
|
|
228
|
+
: test.target
|
|
229
|
+
? "target"
|
|
230
|
+
: "locale";
|
|
231
|
+
subject = test.message || test.segment || test.target || test.locale;
|
|
232
|
+
filePath = getTestFilePath(projectConfig, testKey);
|
|
233
|
+
result = {
|
|
234
|
+
key: testKey,
|
|
235
|
+
filePath: filePath,
|
|
236
|
+
type: type,
|
|
237
|
+
subject: subject,
|
|
238
|
+
duration: 0,
|
|
239
|
+
passed: true,
|
|
240
|
+
assertions: [],
|
|
241
|
+
};
|
|
242
|
+
if (!test.message) return [3 /*break*/, 4];
|
|
243
|
+
_loop_1 = function (rawAssertion) {
|
|
244
|
+
var description, assertionStartTime, assertion, target, datafile, flags, variations, messagevisor, actual;
|
|
245
|
+
return __generator(this, function (_t) {
|
|
246
|
+
switch (_t.label) {
|
|
247
|
+
case 0:
|
|
248
|
+
description = getMessageAssertionDescription(test.message, rawAssertion);
|
|
249
|
+
if (!shouldRunAssertion(description, options))
|
|
250
|
+
return [2 /*return*/, "continue"];
|
|
251
|
+
assertionStartTime = Date.now();
|
|
252
|
+
assertion = createAssertion(description);
|
|
253
|
+
target = rawAssertion.target || "web";
|
|
254
|
+
return [4 /*yield*/, (0, builder_1.buildDatafile)(projectConfig, datasource, target, rawAssertion.locale, revision)];
|
|
255
|
+
case 1:
|
|
256
|
+
datafile = _t.sent();
|
|
257
|
+
if (options.showDatafile) {
|
|
258
|
+
console.log("");
|
|
259
|
+
console.log(JSON.stringify(datafile, null, 2));
|
|
260
|
+
console.log("");
|
|
261
|
+
}
|
|
262
|
+
flags = rawAssertion.withFlags || {};
|
|
263
|
+
variations = rawAssertion.withVariations || {};
|
|
264
|
+
messagevisor = (0, sdk_1.createMessagevisor)({
|
|
265
|
+
datafile: datafile,
|
|
266
|
+
context: rawAssertion.context,
|
|
267
|
+
resolveFlag: function (featureKey) { return flags[featureKey] === true; },
|
|
268
|
+
resolveVariation: function (experimentKey) { return variations[experimentKey]; },
|
|
269
|
+
modules: projectConfig.modules || [],
|
|
270
|
+
logLevel: "warn",
|
|
271
|
+
});
|
|
272
|
+
actual = messagevisor.translate(test.message, normalizeTestValue(rawAssertion.values), {
|
|
273
|
+
context: rawAssertion.context,
|
|
274
|
+
currency: rawAssertion.currency,
|
|
275
|
+
timeZone: rawAssertion.timeZone,
|
|
276
|
+
formats: rawAssertion.formats,
|
|
277
|
+
});
|
|
278
|
+
if (actual !== rawAssertion.expectedTranslation) {
|
|
279
|
+
failAssertion(assertion, {
|
|
280
|
+
message: "Translation mismatch",
|
|
281
|
+
expected: rawAssertion.expectedTranslation,
|
|
282
|
+
actual: actual,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
assertion.duration = Date.now() - assertionStartTime;
|
|
286
|
+
result.assertions.push(assertion);
|
|
287
|
+
return [2 /*return*/];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
_i = 0, _a = (0, matrix_1.expandMessageAssertions)(test.assertions || []);
|
|
292
|
+
_s.label = 1;
|
|
293
|
+
case 1:
|
|
294
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
295
|
+
rawAssertion = _a[_i];
|
|
296
|
+
return [5 /*yield**/, _loop_1(rawAssertion)];
|
|
297
|
+
case 2:
|
|
298
|
+
_s.sent();
|
|
299
|
+
_s.label = 3;
|
|
300
|
+
case 3:
|
|
301
|
+
_i++;
|
|
302
|
+
return [3 /*break*/, 1];
|
|
303
|
+
case 4:
|
|
304
|
+
if (!test.segment) return [3 /*break*/, 7];
|
|
305
|
+
return [4 /*yield*/, datasource.listSegments()];
|
|
306
|
+
case 5:
|
|
307
|
+
segmentKeys = _s.sent();
|
|
308
|
+
_c = (_b = Object).fromEntries;
|
|
309
|
+
return [4 /*yield*/, Promise.all(segmentKeys.map(function (key) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
310
|
+
switch (_b.label) {
|
|
311
|
+
case 0:
|
|
312
|
+
_a = [key];
|
|
313
|
+
return [4 /*yield*/, datasource.readSegment(key)];
|
|
314
|
+
case 1: return [2 /*return*/, _a.concat([_b.sent()])];
|
|
315
|
+
}
|
|
316
|
+
}); }); }))];
|
|
317
|
+
case 6:
|
|
318
|
+
segments = _c.apply(_b, [_s.sent()]);
|
|
319
|
+
for (_d = 0, _e = (0, matrix_1.expandSegmentAssertions)(test.assertions || []); _d < _e.length; _d++) {
|
|
320
|
+
rawAssertion = _e[_d];
|
|
321
|
+
description = getSegmentAssertionDescription(test.segment, rawAssertion);
|
|
322
|
+
if (!shouldRunAssertion(description, options))
|
|
323
|
+
continue;
|
|
324
|
+
assertionStartTime = Date.now();
|
|
325
|
+
assertion = createAssertion(description);
|
|
326
|
+
actual = (0, evaluate_1.evaluateSegment)(rawAssertion.segment || test.segment, {
|
|
327
|
+
segments: segments,
|
|
328
|
+
context: rawAssertion.context,
|
|
329
|
+
});
|
|
330
|
+
if (actual !== rawAssertion.expectedToMatch) {
|
|
331
|
+
failAssertion(assertion, {
|
|
332
|
+
message: "Segment match mismatch",
|
|
333
|
+
expected: rawAssertion.expectedToMatch,
|
|
334
|
+
actual: actual,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
assertion.duration = Date.now() - assertionStartTime;
|
|
338
|
+
result.assertions.push(assertion);
|
|
339
|
+
}
|
|
340
|
+
_s.label = 7;
|
|
341
|
+
case 7:
|
|
342
|
+
if (!test.target) return [3 /*break*/, 11];
|
|
343
|
+
_f = 0, _g = (0, matrix_1.expandTargetAssertions)(test.assertions || []);
|
|
344
|
+
_s.label = 8;
|
|
345
|
+
case 8:
|
|
346
|
+
if (!(_f < _g.length)) return [3 /*break*/, 11];
|
|
347
|
+
rawAssertion = _g[_f];
|
|
348
|
+
description = getTargetAssertionDescription(test.target, rawAssertion);
|
|
349
|
+
if (!shouldRunAssertion(description, options))
|
|
350
|
+
return [3 /*break*/, 10];
|
|
351
|
+
assertionStartTime = Date.now();
|
|
352
|
+
assertion = createAssertion(description);
|
|
353
|
+
return [4 /*yield*/, (0, builder_1.buildDatafile)(projectConfig, datasource, test.target, rawAssertion.locale, revision)];
|
|
354
|
+
case 9:
|
|
355
|
+
datafile = _s.sent();
|
|
356
|
+
if (options.showDatafile) {
|
|
357
|
+
console.log("");
|
|
358
|
+
console.log(JSON.stringify(datafile, null, 2));
|
|
359
|
+
console.log("");
|
|
360
|
+
}
|
|
361
|
+
translationKeys = Object.keys(datafile.translations);
|
|
362
|
+
for (_h = 0, _j = rawAssertion.expectedToIncludeMessages || []; _h < _j.length; _h++) {
|
|
363
|
+
messageKey = _j[_h];
|
|
364
|
+
if (!translationKeys.includes(messageKey)) {
|
|
365
|
+
failAssertion(assertion, {
|
|
366
|
+
message: "Expected datafile to include message \"".concat(messageKey, "\""),
|
|
367
|
+
expected: true,
|
|
368
|
+
actual: false,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
for (_k = 0, _l = rawAssertion.expectedToNotIncludeMessages || []; _k < _l.length; _k++) {
|
|
373
|
+
messageKey = _l[_k];
|
|
374
|
+
if (translationKeys.includes(messageKey)) {
|
|
375
|
+
failAssertion(assertion, {
|
|
376
|
+
message: "Expected datafile to not include message \"".concat(messageKey, "\""),
|
|
377
|
+
expected: false,
|
|
378
|
+
actual: true,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (rawAssertion.expectedFormats &&
|
|
383
|
+
!containsSubset(datafile.formats || {}, rawAssertion.expectedFormats)) {
|
|
384
|
+
failAssertion(assertion, {
|
|
385
|
+
message: "Formats subset mismatch",
|
|
386
|
+
expected: rawAssertion.expectedFormats,
|
|
387
|
+
actual: datafile.formats || {},
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (typeof rawAssertion.rawMessage !== "undefined" ||
|
|
391
|
+
typeof rawAssertion.message !== "undefined") {
|
|
392
|
+
messagevisor = (0, sdk_1.createMessagevisor)({
|
|
393
|
+
datafile: datafile,
|
|
394
|
+
locale: rawAssertion.locale,
|
|
395
|
+
context: rawAssertion.context,
|
|
396
|
+
modules: projectConfig.modules || [],
|
|
397
|
+
logLevel: "warn",
|
|
398
|
+
});
|
|
399
|
+
values = normalizeTestValue(rawAssertion.values);
|
|
400
|
+
actual = typeof rawAssertion.rawMessage !== "undefined"
|
|
401
|
+
? messagevisor.formatMessage(rawAssertion.rawMessage, values, {
|
|
402
|
+
formats: rawAssertion.formats,
|
|
403
|
+
currency: rawAssertion.currency,
|
|
404
|
+
timeZone: rawAssertion.timeZone,
|
|
405
|
+
})
|
|
406
|
+
: messagevisor.translate(rawAssertion.message, values, {
|
|
407
|
+
context: rawAssertion.context,
|
|
408
|
+
formats: rawAssertion.formats,
|
|
409
|
+
currency: rawAssertion.currency,
|
|
410
|
+
timeZone: rawAssertion.timeZone,
|
|
411
|
+
});
|
|
412
|
+
if (actual !== rawAssertion.expectedTranslation) {
|
|
413
|
+
failAssertion(assertion, {
|
|
414
|
+
message: "Translation mismatch",
|
|
415
|
+
expected: rawAssertion.expectedTranslation,
|
|
416
|
+
actual: actual,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
assertion.duration = Date.now() - assertionStartTime;
|
|
421
|
+
result.assertions.push(assertion);
|
|
422
|
+
_s.label = 10;
|
|
423
|
+
case 10:
|
|
424
|
+
_f++;
|
|
425
|
+
return [3 /*break*/, 8];
|
|
426
|
+
case 11:
|
|
427
|
+
if (!test.locale) return [3 /*break*/, 14];
|
|
428
|
+
return [4 /*yield*/, Promise.all([
|
|
429
|
+
datasource.listLocales(),
|
|
430
|
+
datasource.listTargets(),
|
|
431
|
+
])];
|
|
432
|
+
case 12:
|
|
433
|
+
_m = _s.sent(), localeKeys = _m[0], targetKeys = _m[1];
|
|
434
|
+
return [4 /*yield*/, Promise.all([
|
|
435
|
+
Promise.all(localeKeys.map(function (key) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
436
|
+
switch (_b.label) {
|
|
437
|
+
case 0:
|
|
438
|
+
_a = [key];
|
|
439
|
+
return [4 /*yield*/, datasource.readLocale(key)];
|
|
440
|
+
case 1: return [2 /*return*/, _a.concat([_b.sent()])];
|
|
441
|
+
}
|
|
442
|
+
}); }); })),
|
|
443
|
+
Promise.all(targetKeys.map(function (key) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
444
|
+
switch (_b.label) {
|
|
445
|
+
case 0:
|
|
446
|
+
_a = [key];
|
|
447
|
+
return [4 /*yield*/, datasource.readTarget(key)];
|
|
448
|
+
case 1: return [2 /*return*/, _a.concat([_b.sent()])];
|
|
449
|
+
}
|
|
450
|
+
}); }); })),
|
|
451
|
+
])];
|
|
452
|
+
case 13:
|
|
453
|
+
_o = _s.sent(), locales = _o[0], targets = _o[1];
|
|
454
|
+
localesByKey = Object.fromEntries(locales);
|
|
455
|
+
targetsByKey = Object.fromEntries(targets);
|
|
456
|
+
for (_p = 0, _q = (0, matrix_1.expandLocaleAssertions)(test.assertions || []); _p < _q.length; _p++) {
|
|
457
|
+
rawAssertion = _q[_p];
|
|
458
|
+
description = getLocaleAssertionDescription(test.locale, rawAssertion);
|
|
459
|
+
if (!shouldRunAssertion(description, options))
|
|
460
|
+
continue;
|
|
461
|
+
assertionStartTime = Date.now();
|
|
462
|
+
assertion = createAssertion(description);
|
|
463
|
+
target = rawAssertion.target ? targetsByKey[rawAssertion.target] : undefined;
|
|
464
|
+
formats = (0, builder_1.resolveFormats)(test.locale, localesByKey, target);
|
|
465
|
+
if (options.showDatafile) {
|
|
466
|
+
console.log("");
|
|
467
|
+
console.log(JSON.stringify(formats || {}, null, 2));
|
|
468
|
+
console.log("");
|
|
469
|
+
}
|
|
470
|
+
if (rawAssertion.expectedFormats &&
|
|
471
|
+
!containsSubset(formats || {}, rawAssertion.expectedFormats)) {
|
|
472
|
+
failAssertion(assertion, {
|
|
473
|
+
message: "Formats subset mismatch",
|
|
474
|
+
expected: rawAssertion.expectedFormats,
|
|
475
|
+
actual: formats || {},
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (typeof rawAssertion.rawMessage !== "undefined") {
|
|
479
|
+
messagevisor = (0, sdk_1.createMessagevisor)({
|
|
480
|
+
locale: test.locale,
|
|
481
|
+
context: rawAssertion.context,
|
|
482
|
+
defaultFormats: (_r = {},
|
|
483
|
+
_r[test.locale] = formats || {},
|
|
484
|
+
_r),
|
|
485
|
+
modules: projectConfig.modules || [],
|
|
486
|
+
logLevel: "warn",
|
|
487
|
+
});
|
|
488
|
+
actual = messagevisor.formatMessage(rawAssertion.rawMessage, normalizeTestValue(rawAssertion.values), {
|
|
489
|
+
formats: rawAssertion.formats,
|
|
490
|
+
currency: rawAssertion.currency,
|
|
491
|
+
timeZone: rawAssertion.timeZone,
|
|
492
|
+
});
|
|
493
|
+
if (actual !== rawAssertion.expectedTranslation) {
|
|
494
|
+
failAssertion(assertion, {
|
|
495
|
+
message: "Translation mismatch",
|
|
496
|
+
expected: rawAssertion.expectedTranslation,
|
|
497
|
+
actual: actual,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
assertion.duration = Date.now() - assertionStartTime;
|
|
502
|
+
result.assertions.push(assertion);
|
|
503
|
+
}
|
|
504
|
+
_s.label = 14;
|
|
505
|
+
case 14:
|
|
506
|
+
result.passed = result.assertions.every(function (assertion) { return assertion.passed; });
|
|
507
|
+
result.duration = Date.now() - startTime;
|
|
508
|
+
if (result.assertions.length === 0) {
|
|
509
|
+
return [2 /*return*/, undefined];
|
|
510
|
+
}
|
|
511
|
+
return [2 /*return*/, result];
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function testProject(projectConfig_1, datasource_1) {
|
|
517
|
+
return __awaiter(this, arguments, void 0, function (projectConfig, datasource, options) {
|
|
518
|
+
var startTime, testKeys, keyPattern, revision, results, _i, testKeys_1, testKey, test_1, result, failures, passedAssertions, failedAssertions, passedTests, failedTests;
|
|
519
|
+
if (options === void 0) { options = {}; }
|
|
520
|
+
return __generator(this, function (_a) {
|
|
521
|
+
switch (_a.label) {
|
|
522
|
+
case 0:
|
|
523
|
+
startTime = Date.now();
|
|
524
|
+
return [4 /*yield*/, datasource.listTests()];
|
|
525
|
+
case 1:
|
|
526
|
+
testKeys = _a.sent();
|
|
527
|
+
keyPattern = options.keyPattern ? new RegExp(options.keyPattern) : null;
|
|
528
|
+
return [4 /*yield*/, datasource.readRevision()];
|
|
529
|
+
case 2:
|
|
530
|
+
revision = _a.sent();
|
|
531
|
+
results = [];
|
|
532
|
+
_i = 0, testKeys_1 = testKeys;
|
|
533
|
+
_a.label = 3;
|
|
534
|
+
case 3:
|
|
535
|
+
if (!(_i < testKeys_1.length)) return [3 /*break*/, 7];
|
|
536
|
+
testKey = testKeys_1[_i];
|
|
537
|
+
if (keyPattern && !keyPattern.test(testKey)) {
|
|
538
|
+
return [3 /*break*/, 6];
|
|
539
|
+
}
|
|
540
|
+
return [4 /*yield*/, datasource.readTest(testKey)];
|
|
541
|
+
case 4:
|
|
542
|
+
test_1 = (_a.sent());
|
|
543
|
+
return [4 /*yield*/, runTest(projectConfig, datasource, testKey, test_1, revision, options)];
|
|
544
|
+
case 5:
|
|
545
|
+
result = _a.sent();
|
|
546
|
+
if (!result) {
|
|
547
|
+
return [3 /*break*/, 6];
|
|
548
|
+
}
|
|
549
|
+
results.push(result);
|
|
550
|
+
_a.label = 6;
|
|
551
|
+
case 6:
|
|
552
|
+
_i++;
|
|
553
|
+
return [3 /*break*/, 3];
|
|
554
|
+
case 7:
|
|
555
|
+
failures = results.flatMap(function (result) {
|
|
556
|
+
return result.assertions
|
|
557
|
+
.filter(function (assertion) { return !assertion.passed; })
|
|
558
|
+
.flatMap(function (assertion) {
|
|
559
|
+
return assertion.errors.map(function (error) { return ({
|
|
560
|
+
test: result.key,
|
|
561
|
+
message: "".concat(assertion.description, " - ").concat(error.message),
|
|
562
|
+
}); });
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
passedAssertions = results.reduce(function (sum, result) { return sum + result.assertions.filter(function (assertion) { return assertion.passed; }).length; }, 0);
|
|
566
|
+
failedAssertions = results.reduce(function (sum, result) { return sum + result.assertions.filter(function (assertion) { return !assertion.passed; }).length; }, 0);
|
|
567
|
+
passedTests = results.filter(function (result) { return result.passed; }).length;
|
|
568
|
+
failedTests = results.filter(function (result) { return !result.passed; }).length;
|
|
569
|
+
return [2 /*return*/, {
|
|
570
|
+
hasError: failures.length > 0,
|
|
571
|
+
results: results,
|
|
572
|
+
failures: failures,
|
|
573
|
+
assertionsCount: {
|
|
574
|
+
passed: passedAssertions,
|
|
575
|
+
failed: failedAssertions,
|
|
576
|
+
},
|
|
577
|
+
testsCount: {
|
|
578
|
+
passed: passedTests,
|
|
579
|
+
failed: failedTests,
|
|
580
|
+
},
|
|
581
|
+
duration: Date.now() - startTime,
|
|
582
|
+
}];
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
function testProjectSets(projectConfig_1, datasource_1) {
|
|
588
|
+
return __awaiter(this, arguments, void 0, function (projectConfig, datasource, options) {
|
|
589
|
+
var startTime, setExecutions, results, _loop_2, _i, setExecutions_1, execution, failures, passedAssertions, failedAssertions, passedTests, failedTests;
|
|
590
|
+
if (options === void 0) { options = {}; }
|
|
591
|
+
return __generator(this, function (_a) {
|
|
592
|
+
switch (_a.label) {
|
|
593
|
+
case 0:
|
|
594
|
+
startTime = Date.now();
|
|
595
|
+
return [4 /*yield*/, (0, sets_1.getProjectSetExecutions)(projectConfig, datasource, options.set)];
|
|
596
|
+
case 1:
|
|
597
|
+
setExecutions = _a.sent();
|
|
598
|
+
results = [];
|
|
599
|
+
_loop_2 = function (execution) {
|
|
600
|
+
var result;
|
|
601
|
+
return __generator(this, function (_b) {
|
|
602
|
+
switch (_b.label) {
|
|
603
|
+
case 0: return [4 /*yield*/, testProject(execution.projectConfig, execution.datasource, options)];
|
|
604
|
+
case 1:
|
|
605
|
+
result = _b.sent();
|
|
606
|
+
results.push.apply(results, result.results.map(function (testResult) { return (__assign(__assign({}, testResult), { key: projectConfig.sets ? "".concat(execution.set, "/").concat(testResult.key) : testResult.key, filePath: projectConfig.sets
|
|
607
|
+
? (0, sets_1.getProjectSetRelativeFilePath)(projectConfig, execution.set, testResult.filePath)
|
|
608
|
+
: testResult.filePath })); }));
|
|
609
|
+
return [2 /*return*/];
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
};
|
|
613
|
+
_i = 0, setExecutions_1 = setExecutions;
|
|
614
|
+
_a.label = 2;
|
|
615
|
+
case 2:
|
|
616
|
+
if (!(_i < setExecutions_1.length)) return [3 /*break*/, 5];
|
|
617
|
+
execution = setExecutions_1[_i];
|
|
618
|
+
return [5 /*yield**/, _loop_2(execution)];
|
|
619
|
+
case 3:
|
|
620
|
+
_a.sent();
|
|
621
|
+
_a.label = 4;
|
|
622
|
+
case 4:
|
|
623
|
+
_i++;
|
|
624
|
+
return [3 /*break*/, 2];
|
|
625
|
+
case 5:
|
|
626
|
+
failures = results.flatMap(function (result) {
|
|
627
|
+
return result.assertions
|
|
628
|
+
.filter(function (assertion) { return !assertion.passed; })
|
|
629
|
+
.flatMap(function (assertion) {
|
|
630
|
+
return assertion.errors.map(function (error) { return ({
|
|
631
|
+
test: result.key,
|
|
632
|
+
message: "".concat(assertion.description, " - ").concat(error.message),
|
|
633
|
+
}); });
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
passedAssertions = results.reduce(function (sum, result) { return sum + result.assertions.filter(function (assertion) { return assertion.passed; }).length; }, 0);
|
|
637
|
+
failedAssertions = results.reduce(function (sum, result) { return sum + result.assertions.filter(function (assertion) { return !assertion.passed; }).length; }, 0);
|
|
638
|
+
passedTests = results.filter(function (result) { return result.passed; }).length;
|
|
639
|
+
failedTests = results.filter(function (result) { return !result.passed; }).length;
|
|
640
|
+
return [2 /*return*/, {
|
|
641
|
+
hasError: failures.length > 0,
|
|
642
|
+
results: results,
|
|
643
|
+
failures: failures,
|
|
644
|
+
assertionsCount: {
|
|
645
|
+
passed: passedAssertions,
|
|
646
|
+
failed: failedAssertions,
|
|
647
|
+
},
|
|
648
|
+
testsCount: {
|
|
649
|
+
passed: passedTests,
|
|
650
|
+
failed: failedTests,
|
|
651
|
+
},
|
|
652
|
+
duration: Date.now() - startTime,
|
|
653
|
+
}];
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
function printSummary(result, options) {
|
|
659
|
+
if (options.onlyFailures !== true || result.hasError) {
|
|
660
|
+
console.log("\n---");
|
|
661
|
+
}
|
|
662
|
+
console.log("");
|
|
663
|
+
var testSpecsMessage = "Test specs: ".concat(result.testsCount.passed, " passed, ").concat(result.testsCount.failed, " failed");
|
|
664
|
+
var testAssertionsMessage = "Assertions: ".concat(result.assertionsCount.passed, " passed, ").concat(result.assertionsCount.failed, " failed");
|
|
665
|
+
if (result.hasError) {
|
|
666
|
+
console.log(cliFormat_1.CLI_FORMAT_RED, testSpecsMessage);
|
|
667
|
+
console.log(cliFormat_1.CLI_FORMAT_RED, testAssertionsMessage);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, testSpecsMessage);
|
|
671
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, testAssertionsMessage);
|
|
672
|
+
}
|
|
673
|
+
console.log(cliFormat_1.CLI_FORMAT_BOLD, "Time: ".concat((0, prettyDuration_1.prettyDuration)(result.duration)));
|
|
674
|
+
}
|
|
675
|
+
exports.testPlugin = {
|
|
676
|
+
command: "test",
|
|
677
|
+
handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
678
|
+
var result, _i, _c, testResult;
|
|
679
|
+
var projectConfig = _b.projectConfig, datasource = _b.datasource, parsed = _b.parsed;
|
|
680
|
+
return __generator(this, function (_d) {
|
|
681
|
+
switch (_d.label) {
|
|
682
|
+
case 0:
|
|
683
|
+
(0, sets_1.assertProjectSetJsonSelection)(projectConfig, parsed.set, parsed.json);
|
|
684
|
+
return [4 /*yield*/, testProjectSets(projectConfig, datasource, parsed)];
|
|
685
|
+
case 1:
|
|
686
|
+
result = _d.sent();
|
|
687
|
+
if (parsed.json) {
|
|
688
|
+
console.log(parsed.pretty ? JSON.stringify(result.failures, null, 2) : JSON.stringify(result.failures));
|
|
689
|
+
return [2 /*return*/, !result.hasError];
|
|
690
|
+
}
|
|
691
|
+
for (_i = 0, _c = result.results; _i < _c.length; _i++) {
|
|
692
|
+
testResult = _c[_i];
|
|
693
|
+
if (parsed.onlyFailures && testResult.passed) {
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
(0, printTestResult_1.printTestResult)(testResult);
|
|
697
|
+
}
|
|
698
|
+
printSummary(result, parsed);
|
|
699
|
+
return [2 /*return*/, !result.hasError];
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}); },
|
|
703
|
+
examples: [
|
|
704
|
+
{ command: "test", description: "run all tests" },
|
|
705
|
+
{ command: "test --keyPattern=pattern", description: "run tests matching key pattern" },
|
|
706
|
+
{ command: "test --assertionPattern=pattern", description: "run assertions matching pattern" },
|
|
707
|
+
{ command: "test --onlyFailures", description: "only print failed tests" },
|
|
708
|
+
{ command: "test --showDatafile", description: "show datafile content for each assertion" },
|
|
709
|
+
{ command: "test --verbose", description: "show verbose test output" },
|
|
710
|
+
{ command: "test --json --pretty", description: "print failures as JSON" },
|
|
711
|
+
],
|
|
712
|
+
};
|
|
713
|
+
//# sourceMappingURL=index.js.map
|