@specter-automation/test 1.0.107
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/core/component-registry.d.ts +12 -0
- package/dist/core/component-registry.js +25 -0
- package/dist/core/conditions/input-conditions.d.ts +81 -0
- package/dist/core/conditions/input-conditions.js +197 -0
- package/dist/core/events.d.ts +133 -0
- package/dist/core/events.js +6 -0
- package/dist/core/locators/actor-locator.d.ts +425 -0
- package/dist/core/locators/actor-locator.js +1006 -0
- package/dist/core/locators/ai-controller-locator.d.ts +6 -0
- package/dist/core/locators/ai-controller-locator.js +19 -0
- package/dist/core/locators/index.d.ts +6 -0
- package/dist/core/locators/index.js +22 -0
- package/dist/core/locators/movement-locator.d.ts +27 -0
- package/dist/core/locators/movement-locator.js +78 -0
- package/dist/core/locators/skeleton-locator.d.ts +13 -0
- package/dist/core/locators/skeleton-locator.js +35 -0
- package/dist/core/locators/specter-locator.d.ts +110 -0
- package/dist/core/locators/specter-locator.js +323 -0
- package/dist/core/locators/widget-locator.d.ts +104 -0
- package/dist/core/locators/widget-locator.js +297 -0
- package/dist/core/specter-client.d.ts +352 -0
- package/dist/core/specter-client.js +883 -0
- package/dist/core/specter-input-sequence.d.ts +96 -0
- package/dist/core/specter-input-sequence.js +180 -0
- package/dist/core/specter-keyboard.d.ts +21 -0
- package/dist/core/specter-keyboard.js +63 -0
- package/dist/core/specter-keys.d.ts +1 -0
- package/dist/core/specter-keys.js +2 -0
- package/dist/core/specter-network.d.ts +34 -0
- package/dist/core/specter-network.js +59 -0
- package/dist/core/specter-reporter.d.ts +23 -0
- package/dist/core/specter-reporter.js +403 -0
- package/dist/core/test-wrapper.d.ts +25 -0
- package/dist/core/test-wrapper.js +200 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +29 -0
- package/dist/matchers/actor-matchers.d.ts +492 -0
- package/dist/matchers/actor-matchers.js +841 -0
- package/dist/matchers/gas-matchers.d.ts +198 -0
- package/dist/matchers/gas-matchers.js +539 -0
- package/dist/matchers/locator-matchers.d.ts +80 -0
- package/dist/matchers/locator-matchers.js +214 -0
- package/dist/matchers/material-matchers.d.ts +74 -0
- package/dist/matchers/material-matchers.js +295 -0
- package/dist/matchers/widget-matchers.d.ts +81 -0
- package/dist/matchers/widget-matchers.js +110 -0
- package/package.json +33 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const ws_1 = __importDefault(require("ws"));
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
function extractLocatorFromExpectTitle(title) {
|
|
42
|
+
if (!title.startsWith('expect('))
|
|
43
|
+
return '';
|
|
44
|
+
let depth = 1;
|
|
45
|
+
let i = 7;
|
|
46
|
+
while (i < title.length && depth > 0) {
|
|
47
|
+
if (title[i] === '(')
|
|
48
|
+
depth++;
|
|
49
|
+
else if (title[i] === ')')
|
|
50
|
+
depth--;
|
|
51
|
+
i++;
|
|
52
|
+
}
|
|
53
|
+
if (depth === 0) {
|
|
54
|
+
return title.substring(7, i - 1);
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
class SpecterReporter {
|
|
59
|
+
ws = null;
|
|
60
|
+
isConnected = false;
|
|
61
|
+
queue = [];
|
|
62
|
+
testStepCounters = new Map();
|
|
63
|
+
stepIdMap = new WeakMap();
|
|
64
|
+
constructor() {
|
|
65
|
+
this.connect();
|
|
66
|
+
}
|
|
67
|
+
connect() {
|
|
68
|
+
const socket = new ws_1.default('ws://127.0.0.1:8080');
|
|
69
|
+
this.ws = socket;
|
|
70
|
+
socket.on('open', () => {
|
|
71
|
+
this.isConnected = true;
|
|
72
|
+
// Send any queued messages
|
|
73
|
+
while (this.queue.length > 0) {
|
|
74
|
+
const msg = this.queue.shift();
|
|
75
|
+
if (msg)
|
|
76
|
+
socket.send(msg);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
socket.on('error', () => {
|
|
80
|
+
// Silence connection errors to avoid crashing if UE5 is not open
|
|
81
|
+
});
|
|
82
|
+
socket.on('close', () => {
|
|
83
|
+
this.isConnected = false;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
send(payload) {
|
|
87
|
+
const msg = JSON.stringify(payload);
|
|
88
|
+
console.log(`[REPORTER WEBSOCKET SEND]: ${msg}`);
|
|
89
|
+
if (this.isConnected && this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
90
|
+
this.ws.send(msg);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.queue.push(msg);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
onBegin(config, suite) {
|
|
97
|
+
this.send({
|
|
98
|
+
event: 'run_started',
|
|
99
|
+
payload: {}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
onTestBegin(test) {
|
|
103
|
+
const uniqueTestKey = `${test.parent.title} > ${test.title}`;
|
|
104
|
+
this.testStepCounters.set(uniqueTestKey, new Map());
|
|
105
|
+
this.send({
|
|
106
|
+
event: 'test_started',
|
|
107
|
+
payload: {
|
|
108
|
+
testName: uniqueTestKey
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
isNestedExpect(step) {
|
|
113
|
+
if (step.category !== 'expect' && !step.title.startsWith('expect(')) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
let current = step.parent;
|
|
117
|
+
while (current) {
|
|
118
|
+
if (current.category === 'expect') {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
current = current.parent;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
getParentStepName(step) {
|
|
126
|
+
let current = step.parent;
|
|
127
|
+
// Categories that are allowed to act as "Parents" in your UI
|
|
128
|
+
const validParentCategories = ['test.step', 'hook', 'expect'];
|
|
129
|
+
while (current) {
|
|
130
|
+
// Skip custom expect wrapper steps so that the inner expect is nested under the outer step
|
|
131
|
+
if (current.category === 'test.step' && current.title.startsWith('expect(')) {
|
|
132
|
+
current = current.parent;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
// If the parent is a custom step OR a hook (like "Before Hooks")
|
|
136
|
+
if (validParentCategories.includes(current.category)) {
|
|
137
|
+
return this.stepIdMap.get(current) || current.title;
|
|
138
|
+
}
|
|
139
|
+
// Otherwise, keep walking up the tree
|
|
140
|
+
current = current.parent;
|
|
141
|
+
}
|
|
142
|
+
return ''; // Return empty string if no valid parent is found (makes it a Root node)
|
|
143
|
+
}
|
|
144
|
+
onStepBegin(test, result, step) {
|
|
145
|
+
console.log(`[REPORTER DEBUG] Step Begin: "${step.title}" | Category: "${step.category}" | Parent: "${step.parent ? step.parent.title : 'None'}" ("${step.parent ? step.parent.category : ''}")`);
|
|
146
|
+
const customMatchers = [
|
|
147
|
+
'Expect "toBeVisible"',
|
|
148
|
+
'Expect "toHavePropertyValue"',
|
|
149
|
+
'Expect "toHaveAttributeValue"',
|
|
150
|
+
'Expect "toHaveGameplayTag"',
|
|
151
|
+
'Expect "toHaveGameplayEffect"'
|
|
152
|
+
];
|
|
153
|
+
// 1. Ignore the outer Playwright-generated expect steps for custom matchers
|
|
154
|
+
if (step.category === 'expect' && customMatchers.includes(step.title)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// 2. Ignore custom expect wrapper steps ONLY if they are NOT custom matcher wrappers
|
|
158
|
+
const isCustomWrapper = step.category === 'test.step' && step.parent && step.parent.category === 'expect' && customMatchers.includes(step.parent.title);
|
|
159
|
+
if (step.category === 'test.step' && step.title.startsWith('expect(')) {
|
|
160
|
+
if (!isCustomWrapper) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// 3. Ignore inner expect steps nested under custom matchers
|
|
165
|
+
if (this.isNestedExpect(step) && !isCustomWrapper) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const uniqueTestKey = `${test.parent.title} > ${test.title}`;
|
|
169
|
+
let uniqueStepName = step.title;
|
|
170
|
+
let category = step.category;
|
|
171
|
+
// 4. Rewrite the title and category if this is the custom matcher wrapper step
|
|
172
|
+
if (isCustomWrapper) {
|
|
173
|
+
const parentTitle = step.parent ? step.parent.title : '';
|
|
174
|
+
let assertionName = '';
|
|
175
|
+
const match = parentTitle.match(/Expect "([^"]+)"/);
|
|
176
|
+
if (match) {
|
|
177
|
+
assertionName = match[1];
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
assertionName = parentTitle.replace(/^Expect\s+/, '');
|
|
181
|
+
}
|
|
182
|
+
let locator = '';
|
|
183
|
+
if (step.title.includes('@')) {
|
|
184
|
+
const parts = step.title.split('@');
|
|
185
|
+
locator = parts[parts.length - 1].trim();
|
|
186
|
+
}
|
|
187
|
+
else if (step.title.startsWith('expect(')) {
|
|
188
|
+
locator = extractLocatorFromExpectTitle(step.title);
|
|
189
|
+
}
|
|
190
|
+
const isNot = step.title.includes('.not.') || step.title.startsWith('not.');
|
|
191
|
+
const prefix = isNot ? `not.${assertionName}` : assertionName;
|
|
192
|
+
if (locator) {
|
|
193
|
+
uniqueStepName = `Expect "${prefix}" @ ${locator}`;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
uniqueStepName = `Expect "${prefix}"`;
|
|
197
|
+
}
|
|
198
|
+
category = 'expect';
|
|
199
|
+
// Cache the rewritten title on the parent step so we can retrieve it when the parent ends
|
|
200
|
+
this.stepIdMap.set(step.parent, uniqueStepName);
|
|
201
|
+
}
|
|
202
|
+
this.stepIdMap.set(step, uniqueStepName);
|
|
203
|
+
this.send({
|
|
204
|
+
event: 'step_started',
|
|
205
|
+
payload: {
|
|
206
|
+
testName: uniqueTestKey,
|
|
207
|
+
stepName: uniqueStepName,
|
|
208
|
+
parentStepName: this.getParentStepName(step),
|
|
209
|
+
category: category
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
customStepDurations = new WeakMap();
|
|
214
|
+
onStepEnd(test, result, step) {
|
|
215
|
+
const customMatchers = [
|
|
216
|
+
'Expect "toBeVisible"',
|
|
217
|
+
'Expect "toHavePropertyValue"',
|
|
218
|
+
'Expect "toHaveAttributeValue"',
|
|
219
|
+
'Expect "toHaveGameplayTag"',
|
|
220
|
+
'Expect "toHaveGameplayEffect"',
|
|
221
|
+
'Expect "toHaveMaterialScalarParameter"',
|
|
222
|
+
'Expect "toHaveMaterialVectorParameter"',
|
|
223
|
+
'Expect "toHaveMaterial"',
|
|
224
|
+
'Expect "toBeDynamicMaterial"',
|
|
225
|
+
'Expect "toHaveMaterialTextureParameter"'
|
|
226
|
+
];
|
|
227
|
+
// 1. Handle outer Playwright-generated expect steps for custom matchers
|
|
228
|
+
if (step.category === 'expect' && customMatchers.includes(step.title)) {
|
|
229
|
+
const rewrittenName = this.stepIdMap.get(step);
|
|
230
|
+
if (!rewrittenName) {
|
|
231
|
+
return; // Ignore if not a custom matcher we tracked
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// 2. Ignore custom expect wrapper steps entirely (they are replaced by the outer step ending)
|
|
235
|
+
const isCustomWrapper = step.category === 'test.step' && step.parent && step.parent.category === 'expect' && customMatchers.includes(step.parent.title);
|
|
236
|
+
if (isCustomWrapper || (step.category === 'test.step' && step.title.startsWith('expect('))) {
|
|
237
|
+
if (step.parent) {
|
|
238
|
+
this.customStepDurations.set(step.parent, step.duration);
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
// 3. Ignore inner expect steps nested under custom matchers
|
|
243
|
+
if (this.isNestedExpect(step) && !isCustomWrapper) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const uniqueTestKey = `${test.parent.title} > ${test.title}`;
|
|
247
|
+
const uniqueStepName = this.stepIdMap.get(step) || step.title;
|
|
248
|
+
const category = step.category;
|
|
249
|
+
let duration = step.duration || 0;
|
|
250
|
+
if (this.customStepDurations.has(step)) {
|
|
251
|
+
duration = this.customStepDurations.get(step);
|
|
252
|
+
}
|
|
253
|
+
this.send({
|
|
254
|
+
event: 'step_ended',
|
|
255
|
+
payload: {
|
|
256
|
+
testName: uniqueTestKey,
|
|
257
|
+
stepName: uniqueStepName,
|
|
258
|
+
parentStepName: this.getParentStepName(step),
|
|
259
|
+
category: category,
|
|
260
|
+
status: step.error ? 'failed' : 'passed',
|
|
261
|
+
duration: duration,
|
|
262
|
+
errorMessage: step.error ? this.formatError(step.error, result) : ''
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
formatError(error, result) {
|
|
267
|
+
let rawMessage = error.message || '';
|
|
268
|
+
let rawStack = error.stack || '';
|
|
269
|
+
// Strip ANSI escape codes
|
|
270
|
+
const ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
271
|
+
rawMessage = rawMessage.replace(ansiRegex, '');
|
|
272
|
+
rawStack = rawStack.replace(ansiRegex, '');
|
|
273
|
+
// If stack is missing, try to locate the corresponding error in the main test result
|
|
274
|
+
if (!rawStack && result && result.errors) {
|
|
275
|
+
const matchingError = result.errors.find(err => err.message && err.message.includes(rawMessage));
|
|
276
|
+
if (matchingError) {
|
|
277
|
+
rawStack = matchingError.stack || '';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
let cleanMessage = rawMessage
|
|
281
|
+
.replace(/^(Error:\s*)+/i, '')
|
|
282
|
+
.replace(/^(Specter C\+\+\s*Error:\s*)+/i, '')
|
|
283
|
+
.trim();
|
|
284
|
+
let header = 'ERROR';
|
|
285
|
+
let message = cleanMessage;
|
|
286
|
+
let source = '';
|
|
287
|
+
let codeSnippet = '';
|
|
288
|
+
// 1. Try to extract category header from first line containing a colon (e.g. "Category: Details")
|
|
289
|
+
const firstLine = cleanMessage.split('\n')[0];
|
|
290
|
+
const colonIdx = firstLine.indexOf(':');
|
|
291
|
+
if (colonIdx !== -1 && colonIdx < 40) {
|
|
292
|
+
const leftPart = firstLine.substring(0, colonIdx).trim();
|
|
293
|
+
const rightPart = cleanMessage.substring(colonIdx + 1).trim();
|
|
294
|
+
if (leftPart.length > 0 && !leftPart.includes('.') && !leftPart.includes('/') && !leftPart.includes('(')) {
|
|
295
|
+
header = `ERROR: ${leftPart.toUpperCase()}`;
|
|
296
|
+
message = rightPart;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Standardize header categorization fallback if header is still generic
|
|
300
|
+
if (header === 'ERROR') {
|
|
301
|
+
if (rawMessage.includes('Specter C++ Error')) {
|
|
302
|
+
header = 'COMMAND FAILURE';
|
|
303
|
+
}
|
|
304
|
+
else if (rawMessage.includes('expect(')) {
|
|
305
|
+
header = 'ASSERTION FAILED';
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
header = 'RUNTIME ERROR';
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// 2. Extract C++ source file path and line number if present in error message or stack
|
|
312
|
+
const cppFileRegex = /([a-zA-Z0-9_\-]+\.(cpp|h|hpp|c|cc|cxx)):(\d+)/i;
|
|
313
|
+
const cppMatch = rawMessage.match(cppFileRegex) || rawStack.match(cppFileRegex);
|
|
314
|
+
if (cppMatch) {
|
|
315
|
+
source = `${cppMatch[1].toUpperCase()}:${cppMatch[3]}`;
|
|
316
|
+
// Strip C++ source file references from the message to prevent duplication
|
|
317
|
+
const escapedMatch = cppMatch[0].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
318
|
+
const cppRefPattern = new RegExp('\\s*[\\(\\[]?\\s*' + escapedMatch + '\\s*[\\)\\]]?\\s*', 'gi');
|
|
319
|
+
message = message.replace(cppRefPattern, ' ').trim();
|
|
320
|
+
}
|
|
321
|
+
// 3. Extract TS spec file source path and line number from stack trace or message if not already set by C++
|
|
322
|
+
const fileRegex = /(\/[^:\n]+\.(spec|test)\.(ts|js|tsx|jsx)):(\d+)/;
|
|
323
|
+
const tsMatch = rawStack.match(fileRegex) || rawMessage.match(fileRegex);
|
|
324
|
+
if (tsMatch) {
|
|
325
|
+
const filePath = tsMatch[1];
|
|
326
|
+
const lineNum = parseInt(tsMatch[4], 10);
|
|
327
|
+
if (!source) {
|
|
328
|
+
source = `${filePath.split('/').pop()}:${lineNum}`;
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
if (fs.existsSync(filePath)) {
|
|
332
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
333
|
+
const lines = content.split('\n');
|
|
334
|
+
if (lineNum > 0 && lineNum <= lines.length) {
|
|
335
|
+
codeSnippet = lines[lineNum - 1].trim();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (e) {
|
|
340
|
+
console.error(`[Specter Reporter] Failed to read spec file: ${filePath}`, e);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else if (!source) {
|
|
344
|
+
// Fallback to searching stack lines manually
|
|
345
|
+
const stackLines = rawStack.split('\n');
|
|
346
|
+
const sourceLine = stackLines.find((line) => line.includes('.spec.ts') || line.includes('.test.ts') || line.includes('.spec.js'));
|
|
347
|
+
if (sourceLine) {
|
|
348
|
+
const cleanMatch = sourceLine.match(/at\s+(.+)$/);
|
|
349
|
+
source = cleanMatch ? cleanMatch[1].trim() : sourceLine.trim();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// 4. Extract code snippet from the message/stack if present in standard Playwright output
|
|
353
|
+
if (!codeSnippet) {
|
|
354
|
+
const snippetLines = rawMessage.split('\n').filter((line) => /^\s*\d+\s+\|/.test(line));
|
|
355
|
+
if (snippetLines.length > 0) {
|
|
356
|
+
codeSnippet = snippetLines.map((line) => line.replace(/^\s*\d+\s*\|\s*/, '')).join('\n');
|
|
357
|
+
// Remove the code snippet lines from the message
|
|
358
|
+
const rawSnippet = snippetLines.join('\n');
|
|
359
|
+
message = message.replace(rawSnippet, '').trim();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return `${header}|||${message}|||${source}|||${codeSnippet}`;
|
|
363
|
+
}
|
|
364
|
+
onStdOut(chunk, test, result) {
|
|
365
|
+
this.send({
|
|
366
|
+
event: 'test_log',
|
|
367
|
+
payload: {
|
|
368
|
+
testName: test ? `${test.parent.title} > ${test.title}` : '',
|
|
369
|
+
type: 'stdout',
|
|
370
|
+
message: chunk.toString().trim()
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
onStdErr(chunk, test, result) {
|
|
375
|
+
this.send({
|
|
376
|
+
event: 'test_log',
|
|
377
|
+
payload: {
|
|
378
|
+
testName: test ? `${test.parent.title} > ${test.title}` : '',
|
|
379
|
+
type: 'stderr',
|
|
380
|
+
message: chunk.toString().trim()
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
onTestEnd(test, result) {
|
|
385
|
+
const uniqueTestKey = `${test.parent.title} > ${test.title}`;
|
|
386
|
+
this.send({
|
|
387
|
+
event: 'test_ended',
|
|
388
|
+
payload: {
|
|
389
|
+
testName: uniqueTestKey,
|
|
390
|
+
status: result.status
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
onEnd(result) {
|
|
395
|
+
this.send({
|
|
396
|
+
event: 'run_ended',
|
|
397
|
+
payload: {
|
|
398
|
+
status: result.status
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
exports.default = SpecterReporter;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { expect as baseExpect } from '@playwright/test';
|
|
2
|
+
import { SpecterTransport, SpecterWorld } from './specter-client';
|
|
3
|
+
import { GasMatchers } from '../matchers/gas-matchers';
|
|
4
|
+
import { ActorMatchers } from '../matchers/actor-matchers';
|
|
5
|
+
import { LocatorMatchers } from '../matchers/locator-matchers';
|
|
6
|
+
import { WidgetMatchers } from '../matchers/widget-matchers';
|
|
7
|
+
import { MaterialMatchers } from '../matchers/material-matchers';
|
|
8
|
+
export declare const expect: typeof baseExpect & GasMatchers & ActorMatchers & LocatorMatchers & WidgetMatchers & MaterialMatchers;
|
|
9
|
+
type SpecterTestFixtures = {
|
|
10
|
+
world: SpecterWorld;
|
|
11
|
+
createWorld: (options: CreateWorldOptions) => Promise<SpecterWorld>;
|
|
12
|
+
autoScreenshot: void;
|
|
13
|
+
};
|
|
14
|
+
type SpecterWorkerFixtures = {
|
|
15
|
+
specter: SpecterTransport;
|
|
16
|
+
};
|
|
17
|
+
type CreateWorldOptions = {
|
|
18
|
+
port: number;
|
|
19
|
+
name?: string;
|
|
20
|
+
hostAddress?: string;
|
|
21
|
+
autoJoinHost?: boolean;
|
|
22
|
+
launchClient?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare const test: import("playwright/test").TestType<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & SpecterTestFixtures, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & SpecterWorkerFixtures>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.test = exports.expect = void 0;
|
|
37
|
+
const test_1 = require("@playwright/test");
|
|
38
|
+
const specter_client_1 = require("./specter-client");
|
|
39
|
+
const gas_matchers_1 = require("../matchers/gas-matchers");
|
|
40
|
+
const actor_matchers_1 = require("../matchers/actor-matchers");
|
|
41
|
+
const locator_matchers_1 = require("../matchers/locator-matchers");
|
|
42
|
+
const widget_matchers_1 = require("../matchers/widget-matchers");
|
|
43
|
+
const material_matchers_1 = require("../matchers/material-matchers");
|
|
44
|
+
exports.expect = (0, test_1.mergeExpects)(gas_matchers_1.gasExpect, actor_matchers_1.actorExpect, locator_matchers_1.locatorExpect, widget_matchers_1.widgetExpect, material_matchers_1.materialExpect);
|
|
45
|
+
// 2. Define the scopes in the extend block
|
|
46
|
+
exports.test = test_1.test.extend({
|
|
47
|
+
// WORKER FIXTURE: Boots once per Playwright worker process
|
|
48
|
+
specter: [async ({}, use) => {
|
|
49
|
+
const socket = new specter_client_1.SpecterTransport();
|
|
50
|
+
await socket.connect();
|
|
51
|
+
await use(socket);
|
|
52
|
+
socket.disconnect();
|
|
53
|
+
}, { scope: 'worker' }], // <-- This is the magic flag
|
|
54
|
+
// TEST FIXTURE: Runs before/after every single test block
|
|
55
|
+
world: async ({ specter }, use, testInfo) => {
|
|
56
|
+
const world = new specter_client_1.SpecterWorld(specter);
|
|
57
|
+
await use(world);
|
|
58
|
+
// Wipe the level clean for the next test in the queue
|
|
59
|
+
await world.cleanup();
|
|
60
|
+
},
|
|
61
|
+
// THE MULTIPLAYER FACTORY FIXTURE
|
|
62
|
+
createWorld: async ({}, use) => {
|
|
63
|
+
const activeWorlds = [];
|
|
64
|
+
const activeProcesses = [];
|
|
65
|
+
const factory = async (options) => {
|
|
66
|
+
let shouldSpawn = options.launchClient;
|
|
67
|
+
if (shouldSpawn) {
|
|
68
|
+
// Check if port is already open
|
|
69
|
+
const isPortInUse = await new Promise((resolve) => {
|
|
70
|
+
const net = require('net');
|
|
71
|
+
const socket = new net.Socket();
|
|
72
|
+
const onError = () => {
|
|
73
|
+
socket.destroy();
|
|
74
|
+
resolve(false);
|
|
75
|
+
};
|
|
76
|
+
socket.setTimeout(200);
|
|
77
|
+
socket.once('error', onError);
|
|
78
|
+
socket.once('timeout', onError);
|
|
79
|
+
socket.connect(options.port, '127.0.0.1', () => {
|
|
80
|
+
socket.end();
|
|
81
|
+
resolve(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
if (isPortInUse) {
|
|
85
|
+
console.log(`[Specter] Reusing existing client on port ${options.port}`);
|
|
86
|
+
shouldSpawn = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (shouldSpawn) {
|
|
90
|
+
const { spawn } = await Promise.resolve().then(() => __importStar(require('child_process')));
|
|
91
|
+
const fs = require('fs');
|
|
92
|
+
const path = require('path');
|
|
93
|
+
let defaultUprojectPath = "";
|
|
94
|
+
// Try to find a .uproject file in current or parent directories
|
|
95
|
+
try {
|
|
96
|
+
let searchDir = process.cwd();
|
|
97
|
+
for (let depth = 0; depth < 5; depth++) {
|
|
98
|
+
const files = fs.readdirSync(searchDir);
|
|
99
|
+
const uprojectFile = files.find((f) => typeof f === 'string' && f.endsWith('.uproject'));
|
|
100
|
+
if (uprojectFile) {
|
|
101
|
+
defaultUprojectPath = path.join(searchDir, uprojectFile);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
const parentDir = path.dirname(searchDir);
|
|
105
|
+
if (parentDir === searchDir)
|
|
106
|
+
break;
|
|
107
|
+
searchDir = parentDir;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
// Ignore fs errors
|
|
112
|
+
}
|
|
113
|
+
let defaultEditorPath = "/Users/Shared/Epic Games/UE_5.8/Engine/Binaries/Mac/UnrealEditor";
|
|
114
|
+
if (process.platform === 'win32') {
|
|
115
|
+
defaultEditorPath = "C:\\Program Files\\Epic Games\\UE_5.8\\Engine\\Binaries\\Win64\\UnrealEditor.exe";
|
|
116
|
+
}
|
|
117
|
+
const editorPath = process.env.UNREAL_EDITOR_PATH || defaultEditorPath;
|
|
118
|
+
const uprojectPath = process.env.UPROJECT_PATH || defaultUprojectPath;
|
|
119
|
+
if (!uprojectPath) {
|
|
120
|
+
throw new Error("Could not find a .uproject file in the current directory. Please set UPROJECT_PATH environment variable, or run playwright from the project root.");
|
|
121
|
+
}
|
|
122
|
+
const child = spawn(editorPath, [
|
|
123
|
+
uprojectPath,
|
|
124
|
+
'-game',
|
|
125
|
+
`-specterport=${options.port}`,
|
|
126
|
+
'-windowed',
|
|
127
|
+
'-resx=1280',
|
|
128
|
+
'-resy=720',
|
|
129
|
+
'-log'
|
|
130
|
+
], {
|
|
131
|
+
detached: true,
|
|
132
|
+
stdio: 'ignore'
|
|
133
|
+
});
|
|
134
|
+
child.unref();
|
|
135
|
+
activeProcesses.push(child);
|
|
136
|
+
}
|
|
137
|
+
// 1. Always connect Specter so we can control the engine
|
|
138
|
+
const transport = new specter_client_1.SpecterTransport(`ws://127.0.0.1:${options.port}`);
|
|
139
|
+
if (options.name) {
|
|
140
|
+
transport.clientName = options.name;
|
|
141
|
+
}
|
|
142
|
+
await transport.connect();
|
|
143
|
+
const newWorld = new specter_client_1.SpecterWorld(transport);
|
|
144
|
+
activeWorlds.push(newWorld);
|
|
145
|
+
// 2. Automatically command the engine to travel if requested
|
|
146
|
+
if (options.autoJoinHost && options.hostAddress) {
|
|
147
|
+
await newWorld.joinHost(options.hostAddress);
|
|
148
|
+
}
|
|
149
|
+
return newWorld;
|
|
150
|
+
};
|
|
151
|
+
await use(factory);
|
|
152
|
+
// TEARDOWN: When the test ends, clean up all connected multiplayer instances automatically
|
|
153
|
+
for (const world of activeWorlds) {
|
|
154
|
+
await world.cleanup();
|
|
155
|
+
await world.close(); // Disconnects that specific secondary socket
|
|
156
|
+
}
|
|
157
|
+
// Kill all spawned client processes
|
|
158
|
+
for (const child of activeProcesses) {
|
|
159
|
+
try {
|
|
160
|
+
if (process.platform === 'win32') {
|
|
161
|
+
const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
|
|
162
|
+
try {
|
|
163
|
+
execSync(`taskkill /pid ${child.pid} /f /t`, { stdio: 'ignore' });
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
// Process already dead or access denied
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
try {
|
|
175
|
+
child.kill('SIGKILL');
|
|
176
|
+
}
|
|
177
|
+
catch (err) { }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
autoScreenshot: [async ({ world }, use, testInfo) => {
|
|
182
|
+
// Yield control to run the actual test
|
|
183
|
+
await use();
|
|
184
|
+
// FIX: Catch 'failed', 'timedOut', and 'interrupted' statuses
|
|
185
|
+
if (testInfo.status !== 'passed' && testInfo.status !== 'skipped') {
|
|
186
|
+
const safeName = `Specter_Fail_${testInfo.title.replace(/[^a-zA-Z0-9]/g, '_')}`;
|
|
187
|
+
try {
|
|
188
|
+
const imagePath = await world.takeScreenshot(safeName, true);
|
|
189
|
+
testInfo.attachments.push({
|
|
190
|
+
name: 'Unreal Engine Viewport',
|
|
191
|
+
path: imagePath,
|
|
192
|
+
contentType: 'image/png'
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
console.error("[Specter] Failed to capture error screenshot:", e);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, { auto: true }]
|
|
200
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { test, expect } from './core/test-wrapper';
|
|
2
|
+
export { SpecterTransport, SpecterWorld, VectorUtils } from './core/specter-client';
|
|
3
|
+
export type { SpecterPayload, SpawnOptions, Vector3, Rotator, LinearColor, Color, Vector2D, SpecterRegistry, SpecterFunctionRegistry, LoadMapOptions } from './core/specter-client';
|
|
4
|
+
export { SpecterLocator, WidgetLocator, ActorLocator, AiControllerLocator, type WidgetGeometry } from './core/locators';
|
|
5
|
+
export { default as SpecterReporter } from './core/specter-reporter';
|
|
6
|
+
export type { UnrealKey } from './core/specter-keys';
|
|
7
|
+
export type { SpecterActorEvents, SpecterWidgetEvents, SpecterWorldEvents, CustomActorEvents, CustomWidgetEvents, CustomWorldEvents, ActorEventMap, WidgetEventMap, WorldEventMap, EventPredicate, WaitForEventOptions } from './core/events';
|
|
8
|
+
export { SpecterInputSequence } from './core/specter-input-sequence';
|
|
9
|
+
export { SpecterNetwork } from './core/specter-network';
|
|
10
|
+
export type { LocationCondition, DistanceCondition, PropertyCondition, AttributeCondition, SpecterCondition, ConditionFunction, InputConditionalOptions } from './core/conditions/input-conditions';
|
|
11
|
+
export { evaluateCondition, runConditionalInputLoop } from './core/conditions/input-conditions';
|
|
12
|
+
export type { MaterialOptions, MaterialScalarOptions, MaterialVectorOptions, ColorInput, MaterialMatchers } from './matchers/material-matchers';
|
|
13
|
+
export { materialExpect } from './matchers/material-matchers';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.materialExpect = exports.runConditionalInputLoop = exports.evaluateCondition = exports.SpecterNetwork = exports.SpecterInputSequence = exports.SpecterReporter = exports.AiControllerLocator = exports.ActorLocator = exports.WidgetLocator = exports.SpecterLocator = exports.VectorUtils = exports.SpecterWorld = exports.SpecterTransport = exports.expect = exports.test = void 0;
|
|
7
|
+
var test_wrapper_1 = require("./core/test-wrapper");
|
|
8
|
+
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_wrapper_1.test; } });
|
|
9
|
+
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_wrapper_1.expect; } });
|
|
10
|
+
var specter_client_1 = require("./core/specter-client");
|
|
11
|
+
Object.defineProperty(exports, "SpecterTransport", { enumerable: true, get: function () { return specter_client_1.SpecterTransport; } });
|
|
12
|
+
Object.defineProperty(exports, "SpecterWorld", { enumerable: true, get: function () { return specter_client_1.SpecterWorld; } });
|
|
13
|
+
Object.defineProperty(exports, "VectorUtils", { enumerable: true, get: function () { return specter_client_1.VectorUtils; } });
|
|
14
|
+
var locators_1 = require("./core/locators");
|
|
15
|
+
Object.defineProperty(exports, "SpecterLocator", { enumerable: true, get: function () { return locators_1.SpecterLocator; } });
|
|
16
|
+
Object.defineProperty(exports, "WidgetLocator", { enumerable: true, get: function () { return locators_1.WidgetLocator; } });
|
|
17
|
+
Object.defineProperty(exports, "ActorLocator", { enumerable: true, get: function () { return locators_1.ActorLocator; } });
|
|
18
|
+
Object.defineProperty(exports, "AiControllerLocator", { enumerable: true, get: function () { return locators_1.AiControllerLocator; } });
|
|
19
|
+
var specter_reporter_1 = require("./core/specter-reporter");
|
|
20
|
+
Object.defineProperty(exports, "SpecterReporter", { enumerable: true, get: function () { return __importDefault(specter_reporter_1).default; } });
|
|
21
|
+
var specter_input_sequence_1 = require("./core/specter-input-sequence");
|
|
22
|
+
Object.defineProperty(exports, "SpecterInputSequence", { enumerable: true, get: function () { return specter_input_sequence_1.SpecterInputSequence; } });
|
|
23
|
+
var specter_network_1 = require("./core/specter-network");
|
|
24
|
+
Object.defineProperty(exports, "SpecterNetwork", { enumerable: true, get: function () { return specter_network_1.SpecterNetwork; } });
|
|
25
|
+
var input_conditions_1 = require("./core/conditions/input-conditions");
|
|
26
|
+
Object.defineProperty(exports, "evaluateCondition", { enumerable: true, get: function () { return input_conditions_1.evaluateCondition; } });
|
|
27
|
+
Object.defineProperty(exports, "runConditionalInputLoop", { enumerable: true, get: function () { return input_conditions_1.runConditionalInputLoop; } });
|
|
28
|
+
var material_matchers_1 = require("./matchers/material-matchers");
|
|
29
|
+
Object.defineProperty(exports, "materialExpect", { enumerable: true, get: function () { return material_matchers_1.materialExpect; } });
|