@lvce-editor/test-worker 14.17.0 → 14.19.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/api.d.ts +3 -1
- package/dist/testWorkerMain.js +298 -21
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -329,7 +329,9 @@ interface ChatDebug {
|
|
|
329
329
|
readonly setShowInputEvents: (enabled: boolean) => Promise<void>;
|
|
330
330
|
readonly setShowResponsePartEvents: (enabled: boolean) => Promise<void>;
|
|
331
331
|
readonly setTimelineRangePreset: (value: string) => Promise<void>;
|
|
332
|
-
readonly shouldHavePayload: (expectedPayload:
|
|
332
|
+
readonly shouldHavePayload: (expectedPayload: unknown) => Promise<void>;
|
|
333
|
+
readonly shouldHavePayload2: (expectedPayload: unknown) => Promise<void>;
|
|
334
|
+
readonly shouldHaveResponse: (expectedPayload: unknown) => Promise<void>;
|
|
333
335
|
readonly toggleHeadersSection: (sectionId: string) => Promise<void>;
|
|
334
336
|
readonly useDevtoolsLayout: () => Promise<void>;
|
|
335
337
|
}
|
package/dist/testWorkerMain.js
CHANGED
|
@@ -2147,6 +2147,51 @@ const Chat = {
|
|
|
2147
2147
|
useMockApi
|
|
2148
2148
|
};
|
|
2149
2149
|
|
|
2150
|
+
const isObject$3 = value => {
|
|
2151
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2152
|
+
};
|
|
2153
|
+
const formatValue = value => {
|
|
2154
|
+
return JSON.stringify(value);
|
|
2155
|
+
};
|
|
2156
|
+
const assertArrayMatches = (actual, expected, path) => {
|
|
2157
|
+
if (!Array.isArray(actual)) {
|
|
2158
|
+
throw new TypeError(`Expected ${path} to be an array but got ${formatValue(actual)}`);
|
|
2159
|
+
}
|
|
2160
|
+
if (actual.length < expected.length) {
|
|
2161
|
+
throw new Error(`Expected ${path} to have at least ${expected.length} items but got ${actual.length}`);
|
|
2162
|
+
}
|
|
2163
|
+
for (let index = 0; index < expected.length; index++) {
|
|
2164
|
+
assertPayloadMatches(actual[index], expected[index], `${path}[${index}]`);
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
const assertObjectMatches = (actual, expected, path) => {
|
|
2168
|
+
if (!isObject$3(actual)) {
|
|
2169
|
+
throw new TypeError(`Expected ${path} to be an object but got ${formatValue(actual)}`);
|
|
2170
|
+
}
|
|
2171
|
+
for (const key of Object.keys(expected)) {
|
|
2172
|
+
if (!Object.hasOwn(actual, key)) {
|
|
2173
|
+
throw new Error(`Expected ${path}.${key} to exist`);
|
|
2174
|
+
}
|
|
2175
|
+
assertPayloadMatches(actual[key], expected[key], `${path}.${key}`);
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
const assertPrimitiveMatches = (actual, expected, path) => {
|
|
2179
|
+
if (!Object.is(actual, expected)) {
|
|
2180
|
+
throw new Error(`Expected ${path} to equal ${formatValue(expected)} but got ${formatValue(actual)}`);
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
const assertPayloadMatches = (actual, expected, path) => {
|
|
2184
|
+
if (Array.isArray(expected)) {
|
|
2185
|
+
assertArrayMatches(actual, expected, path);
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
if (isObject$3(expected)) {
|
|
2189
|
+
assertObjectMatches(actual, expected, path);
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
assertPrimitiveMatches(actual, expected, path);
|
|
2193
|
+
};
|
|
2194
|
+
|
|
2150
2195
|
const defaultMessage = 'ChatDebug.shouldHavePayload assertion failed';
|
|
2151
2196
|
const getMessage = cause => {
|
|
2152
2197
|
if (!cause || typeof cause !== 'object') {
|
|
@@ -2224,6 +2269,23 @@ const shouldHavePayload = async expectedPayload => {
|
|
|
2224
2269
|
throw new ChatDebugShouldHavePayloadError(expectedPayload, actualPayload, error);
|
|
2225
2270
|
}
|
|
2226
2271
|
};
|
|
2272
|
+
const shouldHavePayload2 = async expectedPayload => {
|
|
2273
|
+
const actualPayload = await invoke('ChatDebug.getPayload');
|
|
2274
|
+
try {
|
|
2275
|
+
assertPayloadMatches(actualPayload, expectedPayload, 'payload');
|
|
2276
|
+
} catch (error) {
|
|
2277
|
+
throw new ChatDebugShouldHavePayloadError(expectedPayload, actualPayload, error);
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
const shouldHaveResponse = async expectedPayload => {
|
|
2281
|
+
const actualPayload = await invoke('ChatDebug.getResponse');
|
|
2282
|
+
try {
|
|
2283
|
+
assertPayloadMatches(actualPayload, expectedPayload, 'response');
|
|
2284
|
+
} catch (error) {
|
|
2285
|
+
// TODO maybe rename class
|
|
2286
|
+
throw new ChatDebugShouldHavePayloadError(expectedPayload, actualPayload, error);
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2227
2289
|
const handleInput$7 = async (name, value, checked) => {
|
|
2228
2290
|
await invoke('ChatDebug.handleInput', name, value, checked);
|
|
2229
2291
|
};
|
|
@@ -2338,6 +2400,8 @@ const ChatDebug = {
|
|
|
2338
2400
|
setShowResponsePartEvents,
|
|
2339
2401
|
setTimelineRangePreset,
|
|
2340
2402
|
shouldHavePayload,
|
|
2403
|
+
shouldHavePayload2,
|
|
2404
|
+
shouldHaveResponse,
|
|
2341
2405
|
toggleHeadersSection,
|
|
2342
2406
|
useDevtoolsLayout
|
|
2343
2407
|
};
|
|
@@ -2473,7 +2537,7 @@ const directionMap = {
|
|
|
2473
2537
|
horizontal: 1,
|
|
2474
2538
|
vertical: 2
|
|
2475
2539
|
};
|
|
2476
|
-
const isObject$
|
|
2540
|
+
const isObject$2 = value => {
|
|
2477
2541
|
return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof RegExp);
|
|
2478
2542
|
};
|
|
2479
2543
|
const matchesExpectedArray = (actual, expected) => {
|
|
@@ -2488,7 +2552,7 @@ const matchesExpectedArray = (actual, expected) => {
|
|
|
2488
2552
|
return true;
|
|
2489
2553
|
};
|
|
2490
2554
|
const matchesExpectedObject = (actual, expected) => {
|
|
2491
|
-
if (!isObject$
|
|
2555
|
+
if (!isObject$2(actual)) {
|
|
2492
2556
|
return false;
|
|
2493
2557
|
}
|
|
2494
2558
|
for (const [childKey, childExpectedValue] of Object.entries(expected)) {
|
|
@@ -2511,7 +2575,7 @@ const matchesExpected = (actual, expected, key = '') => {
|
|
|
2511
2575
|
if (Array.isArray(expected)) {
|
|
2512
2576
|
return matchesExpectedArray(actual, expected);
|
|
2513
2577
|
}
|
|
2514
|
-
if (isObject$
|
|
2578
|
+
if (isObject$2(expected)) {
|
|
2515
2579
|
return matchesExpectedObject(actual, expected);
|
|
2516
2580
|
}
|
|
2517
2581
|
return Object.is(actual, expected);
|
|
@@ -3576,11 +3640,11 @@ const getFileMapNode = async url => {
|
|
|
3576
3640
|
return fileMap;
|
|
3577
3641
|
};
|
|
3578
3642
|
|
|
3579
|
-
const isObject = value => {
|
|
3643
|
+
const isObject$1 = value => {
|
|
3580
3644
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
3581
3645
|
};
|
|
3582
3646
|
const isValidFileMap = value => {
|
|
3583
|
-
if (!isObject(value)) {
|
|
3647
|
+
if (!isObject$1(value)) {
|
|
3584
3648
|
return false;
|
|
3585
3649
|
}
|
|
3586
3650
|
for (const key in value) {
|
|
@@ -5156,13 +5220,83 @@ const handleFileWatcherEvent = async event => {
|
|
|
5156
5220
|
};
|
|
5157
5221
|
|
|
5158
5222
|
const whitespaceRegex = /\s+/g;
|
|
5159
|
-
const
|
|
5223
|
+
const shouldHavePayloadSearch = 'shouldHavePayload(';
|
|
5224
|
+
const validIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
5160
5225
|
const normalizeWhitespace = value => {
|
|
5161
5226
|
return value.replaceAll(whitespaceRegex, '');
|
|
5162
5227
|
};
|
|
5163
|
-
const
|
|
5228
|
+
const isObject = value => {
|
|
5229
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5230
|
+
};
|
|
5231
|
+
const projectActualOntoExpected = (actualValue, expectedValue) => {
|
|
5232
|
+
if (Array.isArray(expectedValue)) {
|
|
5233
|
+
if (!Array.isArray(actualValue)) {
|
|
5234
|
+
return actualValue;
|
|
5235
|
+
}
|
|
5236
|
+
const length = Math.min(expectedValue.length, actualValue.length);
|
|
5237
|
+
return actualValue.slice(0, length).map((item, index) => projectActualOntoExpected(item, expectedValue[index]));
|
|
5238
|
+
}
|
|
5239
|
+
if (isObject(expectedValue)) {
|
|
5240
|
+
if (!isObject(actualValue)) {
|
|
5241
|
+
return actualValue;
|
|
5242
|
+
}
|
|
5243
|
+
const result = {};
|
|
5244
|
+
for (const key of Object.keys(expectedValue)) {
|
|
5245
|
+
if (!Object.hasOwn(actualValue, key)) {
|
|
5246
|
+
continue;
|
|
5247
|
+
}
|
|
5248
|
+
result[key] = projectActualOntoExpected(actualValue[key], expectedValue[key]);
|
|
5249
|
+
}
|
|
5250
|
+
return result;
|
|
5251
|
+
}
|
|
5252
|
+
return actualValue;
|
|
5253
|
+
};
|
|
5254
|
+
const quoteString = value => {
|
|
5255
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t')}'`;
|
|
5256
|
+
};
|
|
5257
|
+
const formatObjectKey = key => {
|
|
5258
|
+
if (validIdentifierRegex.test(key)) {
|
|
5259
|
+
return key;
|
|
5260
|
+
}
|
|
5261
|
+
return quoteString(key);
|
|
5262
|
+
};
|
|
5263
|
+
const trySerialize = (value, indent = 0) => {
|
|
5164
5264
|
try {
|
|
5165
|
-
|
|
5265
|
+
if (value === null) {
|
|
5266
|
+
return 'null';
|
|
5267
|
+
}
|
|
5268
|
+
if (typeof value === 'string') {
|
|
5269
|
+
return quoteString(value);
|
|
5270
|
+
}
|
|
5271
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
5272
|
+
return JSON.stringify(value);
|
|
5273
|
+
}
|
|
5274
|
+
if (Array.isArray(value)) {
|
|
5275
|
+
if (value.length === 0) {
|
|
5276
|
+
return '[]';
|
|
5277
|
+
}
|
|
5278
|
+
const nextIndent = indent + 2;
|
|
5279
|
+
const serializedItems = value.map(item => `${' '.repeat(nextIndent)}${trySerialize(item, nextIndent)}`);
|
|
5280
|
+
return `[
|
|
5281
|
+
${serializedItems.join(',\n')}
|
|
5282
|
+
${' '.repeat(indent)}]`;
|
|
5283
|
+
}
|
|
5284
|
+
if (isObject(value)) {
|
|
5285
|
+
const entries = Object.entries(value);
|
|
5286
|
+
if (entries.length === 0) {
|
|
5287
|
+
return '{}';
|
|
5288
|
+
}
|
|
5289
|
+
const nextIndent = indent + 2;
|
|
5290
|
+
const serializedEntries = [];
|
|
5291
|
+
for (const entry of entries) {
|
|
5292
|
+
const [key, item] = entry;
|
|
5293
|
+
serializedEntries.push(`${' '.repeat(nextIndent)}${formatObjectKey(key)}: ${trySerialize(item, nextIndent)}`);
|
|
5294
|
+
}
|
|
5295
|
+
return `{
|
|
5296
|
+
${serializedEntries.join(',\n')}
|
|
5297
|
+
${' '.repeat(indent)}}`;
|
|
5298
|
+
}
|
|
5299
|
+
return undefined;
|
|
5166
5300
|
} catch {
|
|
5167
5301
|
return undefined;
|
|
5168
5302
|
}
|
|
@@ -5172,21 +5306,168 @@ const replaceMatch = (fileContent, index, length, replacement) => {
|
|
|
5172
5306
|
const after = fileContent.slice(index + length);
|
|
5173
5307
|
return `${before}${replacement}${after}`;
|
|
5174
5308
|
};
|
|
5309
|
+
const isStringDelimiter = character => {
|
|
5310
|
+
return character === "'" || character === '"' || character === '`';
|
|
5311
|
+
};
|
|
5312
|
+
const consumeComment = (inBlockComment, inLineComment, character, nextCharacter) => {
|
|
5313
|
+
if (inLineComment) {
|
|
5314
|
+
if (character === '\n') {
|
|
5315
|
+
return {
|
|
5316
|
+
consumed: 1,
|
|
5317
|
+
inBlockComment,
|
|
5318
|
+
inLineComment: false
|
|
5319
|
+
};
|
|
5320
|
+
}
|
|
5321
|
+
return {
|
|
5322
|
+
consumed: 1,
|
|
5323
|
+
inBlockComment,
|
|
5324
|
+
inLineComment
|
|
5325
|
+
};
|
|
5326
|
+
}
|
|
5327
|
+
if (inBlockComment) {
|
|
5328
|
+
if (character === '*' && nextCharacter === '/') {
|
|
5329
|
+
return {
|
|
5330
|
+
consumed: 2,
|
|
5331
|
+
inBlockComment: false,
|
|
5332
|
+
inLineComment
|
|
5333
|
+
};
|
|
5334
|
+
}
|
|
5335
|
+
return {
|
|
5336
|
+
consumed: 1,
|
|
5337
|
+
inBlockComment,
|
|
5338
|
+
inLineComment
|
|
5339
|
+
};
|
|
5340
|
+
}
|
|
5341
|
+
if (character === '/' && nextCharacter === '/') {
|
|
5342
|
+
return {
|
|
5343
|
+
consumed: 2,
|
|
5344
|
+
inBlockComment,
|
|
5345
|
+
inLineComment: true
|
|
5346
|
+
};
|
|
5347
|
+
}
|
|
5348
|
+
if (character === '/' && nextCharacter === '*') {
|
|
5349
|
+
return {
|
|
5350
|
+
consumed: 2,
|
|
5351
|
+
inBlockComment: true,
|
|
5352
|
+
inLineComment
|
|
5353
|
+
};
|
|
5354
|
+
}
|
|
5355
|
+
return {
|
|
5356
|
+
consumed: 0,
|
|
5357
|
+
inBlockComment,
|
|
5358
|
+
inLineComment
|
|
5359
|
+
};
|
|
5360
|
+
};
|
|
5361
|
+
const consumeString = (stringDelimiter, character) => {
|
|
5362
|
+
if (!stringDelimiter) {
|
|
5363
|
+
if (isStringDelimiter(character)) {
|
|
5364
|
+
return {
|
|
5365
|
+
consumed: 1,
|
|
5366
|
+
stringDelimiter: character
|
|
5367
|
+
};
|
|
5368
|
+
}
|
|
5369
|
+
return {
|
|
5370
|
+
consumed: 0,
|
|
5371
|
+
stringDelimiter
|
|
5372
|
+
};
|
|
5373
|
+
}
|
|
5374
|
+
if (character === '\\') {
|
|
5375
|
+
return {
|
|
5376
|
+
consumed: 2,
|
|
5377
|
+
stringDelimiter
|
|
5378
|
+
};
|
|
5379
|
+
}
|
|
5380
|
+
if (character === stringDelimiter) {
|
|
5381
|
+
return {
|
|
5382
|
+
consumed: 1,
|
|
5383
|
+
stringDelimiter: ''
|
|
5384
|
+
};
|
|
5385
|
+
}
|
|
5386
|
+
return {
|
|
5387
|
+
consumed: 1,
|
|
5388
|
+
stringDelimiter
|
|
5389
|
+
};
|
|
5390
|
+
};
|
|
5391
|
+
const findClosingParenthesis = (fileContent, startIndex) => {
|
|
5392
|
+
let depth = 1;
|
|
5393
|
+
let inBlockComment = false;
|
|
5394
|
+
let inLineComment = false;
|
|
5395
|
+
let stringDelimiter = '';
|
|
5396
|
+
for (let index = startIndex; index < fileContent.length;) {
|
|
5397
|
+
const character = fileContent[index];
|
|
5398
|
+
const nextCharacter = fileContent[index + 1];
|
|
5399
|
+
const stringState = consumeString(stringDelimiter, character);
|
|
5400
|
+
const {
|
|
5401
|
+
consumed: consumedString,
|
|
5402
|
+
stringDelimiter: nextStringDelimiter
|
|
5403
|
+
} = stringState;
|
|
5404
|
+
stringDelimiter = nextStringDelimiter;
|
|
5405
|
+
if (consumedString > 0) {
|
|
5406
|
+
index += consumedString;
|
|
5407
|
+
continue;
|
|
5408
|
+
}
|
|
5409
|
+
const commentState = consumeComment(inBlockComment, inLineComment, character, nextCharacter);
|
|
5410
|
+
const {
|
|
5411
|
+
consumed: consumedComment,
|
|
5412
|
+
inBlockComment: nextInBlockComment,
|
|
5413
|
+
inLineComment: nextInLineComment
|
|
5414
|
+
} = commentState;
|
|
5415
|
+
inBlockComment = nextInBlockComment;
|
|
5416
|
+
inLineComment = nextInLineComment;
|
|
5417
|
+
if (consumedComment > 0) {
|
|
5418
|
+
index += consumedComment;
|
|
5419
|
+
continue;
|
|
5420
|
+
}
|
|
5421
|
+
if (character === '(') {
|
|
5422
|
+
depth++;
|
|
5423
|
+
index++;
|
|
5424
|
+
continue;
|
|
5425
|
+
}
|
|
5426
|
+
if (character === ')') {
|
|
5427
|
+
depth--;
|
|
5428
|
+
if (depth === 0) {
|
|
5429
|
+
return index;
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
index++;
|
|
5433
|
+
}
|
|
5434
|
+
return -1;
|
|
5435
|
+
};
|
|
5436
|
+
const findShouldHavePayloadMatches = fileContent => {
|
|
5437
|
+
const matches = [];
|
|
5438
|
+
let searchIndex = 0;
|
|
5439
|
+
while (searchIndex < fileContent.length) {
|
|
5440
|
+
const matchIndex = fileContent.indexOf(shouldHavePayloadSearch, searchIndex);
|
|
5441
|
+
if (matchIndex === -1) {
|
|
5442
|
+
break;
|
|
5443
|
+
}
|
|
5444
|
+
const argumentStart = matchIndex + shouldHavePayloadSearch.length;
|
|
5445
|
+
const closingParenthesisIndex = findClosingParenthesis(fileContent, argumentStart);
|
|
5446
|
+
if (closingParenthesisIndex === -1) {
|
|
5447
|
+
break;
|
|
5448
|
+
}
|
|
5449
|
+
matches.push({
|
|
5450
|
+
argument: fileContent.slice(argumentStart, closingParenthesisIndex),
|
|
5451
|
+
index: matchIndex,
|
|
5452
|
+
length: closingParenthesisIndex - matchIndex + 1
|
|
5453
|
+
});
|
|
5454
|
+
searchIndex = closingParenthesisIndex + 1;
|
|
5455
|
+
}
|
|
5456
|
+
return matches;
|
|
5457
|
+
};
|
|
5175
5458
|
const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) => {
|
|
5176
|
-
const
|
|
5177
|
-
|
|
5459
|
+
const minimalPayload = projectActualOntoExpected(actualPayload, expectedPayload);
|
|
5460
|
+
const serializedMinimalPayload = trySerialize(minimalPayload);
|
|
5461
|
+
if (!serializedMinimalPayload) {
|
|
5178
5462
|
return undefined;
|
|
5179
5463
|
}
|
|
5180
|
-
const matches =
|
|
5464
|
+
const matches = findShouldHavePayloadMatches(fileContent);
|
|
5181
5465
|
if (matches.length === 0) {
|
|
5182
5466
|
return undefined;
|
|
5183
5467
|
}
|
|
5184
5468
|
if (matches.length === 1) {
|
|
5185
5469
|
const [match] = matches;
|
|
5186
|
-
|
|
5187
|
-
return undefined;
|
|
5188
|
-
}
|
|
5189
|
-
return replaceMatch(fileContent, match.index, match[0].length, `shouldHavePayload(${serializedActual})`);
|
|
5470
|
+
return replaceMatch(fileContent, match.index, match.length, `shouldHavePayload(${serializedMinimalPayload})`);
|
|
5190
5471
|
}
|
|
5191
5472
|
const serializedExpected = trySerialize(expectedPayload);
|
|
5192
5473
|
if (!serializedExpected) {
|
|
@@ -5195,8 +5476,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
|
|
|
5195
5476
|
const normalizedExpected = normalizeWhitespace(serializedExpected);
|
|
5196
5477
|
const matchingCandidates = [];
|
|
5197
5478
|
for (const match of matches) {
|
|
5198
|
-
|
|
5199
|
-
if (normalizeWhitespace(currentArgument) === normalizedExpected) {
|
|
5479
|
+
if (normalizeWhitespace(match.argument) === normalizedExpected) {
|
|
5200
5480
|
matchingCandidates.push(match);
|
|
5201
5481
|
}
|
|
5202
5482
|
}
|
|
@@ -5204,10 +5484,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
|
|
|
5204
5484
|
return undefined;
|
|
5205
5485
|
}
|
|
5206
5486
|
const [candidate] = matchingCandidates;
|
|
5207
|
-
|
|
5208
|
-
return undefined;
|
|
5209
|
-
}
|
|
5210
|
-
return replaceMatch(fileContent, candidate.index, candidate[0].length, `shouldHavePayload(${serializedActual})`);
|
|
5487
|
+
return replaceMatch(fileContent, candidate.index, candidate.length, `shouldHavePayload(${serializedMinimalPayload})`);
|
|
5211
5488
|
};
|
|
5212
5489
|
const getFileUrlFromRemotePath = rawPathName => {
|
|
5213
5490
|
if (!rawPathName.startsWith('/remote')) {
|