@lvce-editor/test-worker 14.17.0 → 14.18.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 +2 -1
- package/dist/testWorkerMain.js +288 -21
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -329,7 +329,8 @@ 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>;
|
|
333
334
|
readonly toggleHeadersSection: (sectionId: string) => Promise<void>;
|
|
334
335
|
readonly useDevtoolsLayout: () => Promise<void>;
|
|
335
336
|
}
|
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,14 @@ 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
|
+
};
|
|
2227
2280
|
const handleInput$7 = async (name, value, checked) => {
|
|
2228
2281
|
await invoke('ChatDebug.handleInput', name, value, checked);
|
|
2229
2282
|
};
|
|
@@ -2338,6 +2391,7 @@ const ChatDebug = {
|
|
|
2338
2391
|
setShowResponsePartEvents,
|
|
2339
2392
|
setTimelineRangePreset,
|
|
2340
2393
|
shouldHavePayload,
|
|
2394
|
+
shouldHavePayload2,
|
|
2341
2395
|
toggleHeadersSection,
|
|
2342
2396
|
useDevtoolsLayout
|
|
2343
2397
|
};
|
|
@@ -2473,7 +2527,7 @@ const directionMap = {
|
|
|
2473
2527
|
horizontal: 1,
|
|
2474
2528
|
vertical: 2
|
|
2475
2529
|
};
|
|
2476
|
-
const isObject$
|
|
2530
|
+
const isObject$2 = value => {
|
|
2477
2531
|
return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof RegExp);
|
|
2478
2532
|
};
|
|
2479
2533
|
const matchesExpectedArray = (actual, expected) => {
|
|
@@ -2488,7 +2542,7 @@ const matchesExpectedArray = (actual, expected) => {
|
|
|
2488
2542
|
return true;
|
|
2489
2543
|
};
|
|
2490
2544
|
const matchesExpectedObject = (actual, expected) => {
|
|
2491
|
-
if (!isObject$
|
|
2545
|
+
if (!isObject$2(actual)) {
|
|
2492
2546
|
return false;
|
|
2493
2547
|
}
|
|
2494
2548
|
for (const [childKey, childExpectedValue] of Object.entries(expected)) {
|
|
@@ -2511,7 +2565,7 @@ const matchesExpected = (actual, expected, key = '') => {
|
|
|
2511
2565
|
if (Array.isArray(expected)) {
|
|
2512
2566
|
return matchesExpectedArray(actual, expected);
|
|
2513
2567
|
}
|
|
2514
|
-
if (isObject$
|
|
2568
|
+
if (isObject$2(expected)) {
|
|
2515
2569
|
return matchesExpectedObject(actual, expected);
|
|
2516
2570
|
}
|
|
2517
2571
|
return Object.is(actual, expected);
|
|
@@ -3576,11 +3630,11 @@ const getFileMapNode = async url => {
|
|
|
3576
3630
|
return fileMap;
|
|
3577
3631
|
};
|
|
3578
3632
|
|
|
3579
|
-
const isObject = value => {
|
|
3633
|
+
const isObject$1 = value => {
|
|
3580
3634
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
3581
3635
|
};
|
|
3582
3636
|
const isValidFileMap = value => {
|
|
3583
|
-
if (!isObject(value)) {
|
|
3637
|
+
if (!isObject$1(value)) {
|
|
3584
3638
|
return false;
|
|
3585
3639
|
}
|
|
3586
3640
|
for (const key in value) {
|
|
@@ -5156,13 +5210,83 @@ const handleFileWatcherEvent = async event => {
|
|
|
5156
5210
|
};
|
|
5157
5211
|
|
|
5158
5212
|
const whitespaceRegex = /\s+/g;
|
|
5159
|
-
const
|
|
5213
|
+
const shouldHavePayloadSearch = 'shouldHavePayload(';
|
|
5214
|
+
const validIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
5160
5215
|
const normalizeWhitespace = value => {
|
|
5161
5216
|
return value.replaceAll(whitespaceRegex, '');
|
|
5162
5217
|
};
|
|
5163
|
-
const
|
|
5218
|
+
const isObject = value => {
|
|
5219
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5220
|
+
};
|
|
5221
|
+
const projectActualOntoExpected = (actualValue, expectedValue) => {
|
|
5222
|
+
if (Array.isArray(expectedValue)) {
|
|
5223
|
+
if (!Array.isArray(actualValue)) {
|
|
5224
|
+
return actualValue;
|
|
5225
|
+
}
|
|
5226
|
+
const length = Math.min(expectedValue.length, actualValue.length);
|
|
5227
|
+
return actualValue.slice(0, length).map((item, index) => projectActualOntoExpected(item, expectedValue[index]));
|
|
5228
|
+
}
|
|
5229
|
+
if (isObject(expectedValue)) {
|
|
5230
|
+
if (!isObject(actualValue)) {
|
|
5231
|
+
return actualValue;
|
|
5232
|
+
}
|
|
5233
|
+
const result = {};
|
|
5234
|
+
for (const key of Object.keys(expectedValue)) {
|
|
5235
|
+
if (!Object.hasOwn(actualValue, key)) {
|
|
5236
|
+
continue;
|
|
5237
|
+
}
|
|
5238
|
+
result[key] = projectActualOntoExpected(actualValue[key], expectedValue[key]);
|
|
5239
|
+
}
|
|
5240
|
+
return result;
|
|
5241
|
+
}
|
|
5242
|
+
return actualValue;
|
|
5243
|
+
};
|
|
5244
|
+
const quoteString = value => {
|
|
5245
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t')}'`;
|
|
5246
|
+
};
|
|
5247
|
+
const formatObjectKey = key => {
|
|
5248
|
+
if (validIdentifierRegex.test(key)) {
|
|
5249
|
+
return key;
|
|
5250
|
+
}
|
|
5251
|
+
return quoteString(key);
|
|
5252
|
+
};
|
|
5253
|
+
const trySerialize = (value, indent = 0) => {
|
|
5164
5254
|
try {
|
|
5165
|
-
|
|
5255
|
+
if (value === null) {
|
|
5256
|
+
return 'null';
|
|
5257
|
+
}
|
|
5258
|
+
if (typeof value === 'string') {
|
|
5259
|
+
return quoteString(value);
|
|
5260
|
+
}
|
|
5261
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
5262
|
+
return JSON.stringify(value);
|
|
5263
|
+
}
|
|
5264
|
+
if (Array.isArray(value)) {
|
|
5265
|
+
if (value.length === 0) {
|
|
5266
|
+
return '[]';
|
|
5267
|
+
}
|
|
5268
|
+
const nextIndent = indent + 2;
|
|
5269
|
+
const serializedItems = value.map(item => `${' '.repeat(nextIndent)}${trySerialize(item, nextIndent)}`);
|
|
5270
|
+
return `[
|
|
5271
|
+
${serializedItems.join(',\n')}
|
|
5272
|
+
${' '.repeat(indent)}]`;
|
|
5273
|
+
}
|
|
5274
|
+
if (isObject(value)) {
|
|
5275
|
+
const entries = Object.entries(value);
|
|
5276
|
+
if (entries.length === 0) {
|
|
5277
|
+
return '{}';
|
|
5278
|
+
}
|
|
5279
|
+
const nextIndent = indent + 2;
|
|
5280
|
+
const serializedEntries = [];
|
|
5281
|
+
for (const entry of entries) {
|
|
5282
|
+
const [key, item] = entry;
|
|
5283
|
+
serializedEntries.push(`${' '.repeat(nextIndent)}${formatObjectKey(key)}: ${trySerialize(item, nextIndent)}`);
|
|
5284
|
+
}
|
|
5285
|
+
return `{
|
|
5286
|
+
${serializedEntries.join(',\n')}
|
|
5287
|
+
${' '.repeat(indent)}}`;
|
|
5288
|
+
}
|
|
5289
|
+
return undefined;
|
|
5166
5290
|
} catch {
|
|
5167
5291
|
return undefined;
|
|
5168
5292
|
}
|
|
@@ -5172,21 +5296,168 @@ const replaceMatch = (fileContent, index, length, replacement) => {
|
|
|
5172
5296
|
const after = fileContent.slice(index + length);
|
|
5173
5297
|
return `${before}${replacement}${after}`;
|
|
5174
5298
|
};
|
|
5299
|
+
const isStringDelimiter = character => {
|
|
5300
|
+
return character === "'" || character === '"' || character === '`';
|
|
5301
|
+
};
|
|
5302
|
+
const consumeComment = (inBlockComment, inLineComment, character, nextCharacter) => {
|
|
5303
|
+
if (inLineComment) {
|
|
5304
|
+
if (character === '\n') {
|
|
5305
|
+
return {
|
|
5306
|
+
consumed: 1,
|
|
5307
|
+
inBlockComment,
|
|
5308
|
+
inLineComment: false
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
return {
|
|
5312
|
+
consumed: 1,
|
|
5313
|
+
inBlockComment,
|
|
5314
|
+
inLineComment
|
|
5315
|
+
};
|
|
5316
|
+
}
|
|
5317
|
+
if (inBlockComment) {
|
|
5318
|
+
if (character === '*' && nextCharacter === '/') {
|
|
5319
|
+
return {
|
|
5320
|
+
consumed: 2,
|
|
5321
|
+
inBlockComment: false,
|
|
5322
|
+
inLineComment
|
|
5323
|
+
};
|
|
5324
|
+
}
|
|
5325
|
+
return {
|
|
5326
|
+
consumed: 1,
|
|
5327
|
+
inBlockComment,
|
|
5328
|
+
inLineComment
|
|
5329
|
+
};
|
|
5330
|
+
}
|
|
5331
|
+
if (character === '/' && nextCharacter === '/') {
|
|
5332
|
+
return {
|
|
5333
|
+
consumed: 2,
|
|
5334
|
+
inBlockComment,
|
|
5335
|
+
inLineComment: true
|
|
5336
|
+
};
|
|
5337
|
+
}
|
|
5338
|
+
if (character === '/' && nextCharacter === '*') {
|
|
5339
|
+
return {
|
|
5340
|
+
consumed: 2,
|
|
5341
|
+
inBlockComment: true,
|
|
5342
|
+
inLineComment
|
|
5343
|
+
};
|
|
5344
|
+
}
|
|
5345
|
+
return {
|
|
5346
|
+
consumed: 0,
|
|
5347
|
+
inBlockComment,
|
|
5348
|
+
inLineComment
|
|
5349
|
+
};
|
|
5350
|
+
};
|
|
5351
|
+
const consumeString = (stringDelimiter, character) => {
|
|
5352
|
+
if (!stringDelimiter) {
|
|
5353
|
+
if (isStringDelimiter(character)) {
|
|
5354
|
+
return {
|
|
5355
|
+
consumed: 1,
|
|
5356
|
+
stringDelimiter: character
|
|
5357
|
+
};
|
|
5358
|
+
}
|
|
5359
|
+
return {
|
|
5360
|
+
consumed: 0,
|
|
5361
|
+
stringDelimiter
|
|
5362
|
+
};
|
|
5363
|
+
}
|
|
5364
|
+
if (character === '\\') {
|
|
5365
|
+
return {
|
|
5366
|
+
consumed: 2,
|
|
5367
|
+
stringDelimiter
|
|
5368
|
+
};
|
|
5369
|
+
}
|
|
5370
|
+
if (character === stringDelimiter) {
|
|
5371
|
+
return {
|
|
5372
|
+
consumed: 1,
|
|
5373
|
+
stringDelimiter: ''
|
|
5374
|
+
};
|
|
5375
|
+
}
|
|
5376
|
+
return {
|
|
5377
|
+
consumed: 1,
|
|
5378
|
+
stringDelimiter
|
|
5379
|
+
};
|
|
5380
|
+
};
|
|
5381
|
+
const findClosingParenthesis = (fileContent, startIndex) => {
|
|
5382
|
+
let depth = 1;
|
|
5383
|
+
let inBlockComment = false;
|
|
5384
|
+
let inLineComment = false;
|
|
5385
|
+
let stringDelimiter = '';
|
|
5386
|
+
for (let index = startIndex; index < fileContent.length;) {
|
|
5387
|
+
const character = fileContent[index];
|
|
5388
|
+
const nextCharacter = fileContent[index + 1];
|
|
5389
|
+
const stringState = consumeString(stringDelimiter, character);
|
|
5390
|
+
const {
|
|
5391
|
+
consumed: consumedString,
|
|
5392
|
+
stringDelimiter: nextStringDelimiter
|
|
5393
|
+
} = stringState;
|
|
5394
|
+
stringDelimiter = nextStringDelimiter;
|
|
5395
|
+
if (consumedString > 0) {
|
|
5396
|
+
index += consumedString;
|
|
5397
|
+
continue;
|
|
5398
|
+
}
|
|
5399
|
+
const commentState = consumeComment(inBlockComment, inLineComment, character, nextCharacter);
|
|
5400
|
+
const {
|
|
5401
|
+
consumed: consumedComment,
|
|
5402
|
+
inBlockComment: nextInBlockComment,
|
|
5403
|
+
inLineComment: nextInLineComment
|
|
5404
|
+
} = commentState;
|
|
5405
|
+
inBlockComment = nextInBlockComment;
|
|
5406
|
+
inLineComment = nextInLineComment;
|
|
5407
|
+
if (consumedComment > 0) {
|
|
5408
|
+
index += consumedComment;
|
|
5409
|
+
continue;
|
|
5410
|
+
}
|
|
5411
|
+
if (character === '(') {
|
|
5412
|
+
depth++;
|
|
5413
|
+
index++;
|
|
5414
|
+
continue;
|
|
5415
|
+
}
|
|
5416
|
+
if (character === ')') {
|
|
5417
|
+
depth--;
|
|
5418
|
+
if (depth === 0) {
|
|
5419
|
+
return index;
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5422
|
+
index++;
|
|
5423
|
+
}
|
|
5424
|
+
return -1;
|
|
5425
|
+
};
|
|
5426
|
+
const findShouldHavePayloadMatches = fileContent => {
|
|
5427
|
+
const matches = [];
|
|
5428
|
+
let searchIndex = 0;
|
|
5429
|
+
while (searchIndex < fileContent.length) {
|
|
5430
|
+
const matchIndex = fileContent.indexOf(shouldHavePayloadSearch, searchIndex);
|
|
5431
|
+
if (matchIndex === -1) {
|
|
5432
|
+
break;
|
|
5433
|
+
}
|
|
5434
|
+
const argumentStart = matchIndex + shouldHavePayloadSearch.length;
|
|
5435
|
+
const closingParenthesisIndex = findClosingParenthesis(fileContent, argumentStart);
|
|
5436
|
+
if (closingParenthesisIndex === -1) {
|
|
5437
|
+
break;
|
|
5438
|
+
}
|
|
5439
|
+
matches.push({
|
|
5440
|
+
argument: fileContent.slice(argumentStart, closingParenthesisIndex),
|
|
5441
|
+
index: matchIndex,
|
|
5442
|
+
length: closingParenthesisIndex - matchIndex + 1
|
|
5443
|
+
});
|
|
5444
|
+
searchIndex = closingParenthesisIndex + 1;
|
|
5445
|
+
}
|
|
5446
|
+
return matches;
|
|
5447
|
+
};
|
|
5175
5448
|
const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) => {
|
|
5176
|
-
const
|
|
5177
|
-
|
|
5449
|
+
const minimalPayload = projectActualOntoExpected(actualPayload, expectedPayload);
|
|
5450
|
+
const serializedMinimalPayload = trySerialize(minimalPayload);
|
|
5451
|
+
if (!serializedMinimalPayload) {
|
|
5178
5452
|
return undefined;
|
|
5179
5453
|
}
|
|
5180
|
-
const matches =
|
|
5454
|
+
const matches = findShouldHavePayloadMatches(fileContent);
|
|
5181
5455
|
if (matches.length === 0) {
|
|
5182
5456
|
return undefined;
|
|
5183
5457
|
}
|
|
5184
5458
|
if (matches.length === 1) {
|
|
5185
5459
|
const [match] = matches;
|
|
5186
|
-
|
|
5187
|
-
return undefined;
|
|
5188
|
-
}
|
|
5189
|
-
return replaceMatch(fileContent, match.index, match[0].length, `shouldHavePayload(${serializedActual})`);
|
|
5460
|
+
return replaceMatch(fileContent, match.index, match.length, `shouldHavePayload(${serializedMinimalPayload})`);
|
|
5190
5461
|
}
|
|
5191
5462
|
const serializedExpected = trySerialize(expectedPayload);
|
|
5192
5463
|
if (!serializedExpected) {
|
|
@@ -5195,8 +5466,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
|
|
|
5195
5466
|
const normalizedExpected = normalizeWhitespace(serializedExpected);
|
|
5196
5467
|
const matchingCandidates = [];
|
|
5197
5468
|
for (const match of matches) {
|
|
5198
|
-
|
|
5199
|
-
if (normalizeWhitespace(currentArgument) === normalizedExpected) {
|
|
5469
|
+
if (normalizeWhitespace(match.argument) === normalizedExpected) {
|
|
5200
5470
|
matchingCandidates.push(match);
|
|
5201
5471
|
}
|
|
5202
5472
|
}
|
|
@@ -5204,10 +5474,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
|
|
|
5204
5474
|
return undefined;
|
|
5205
5475
|
}
|
|
5206
5476
|
const [candidate] = matchingCandidates;
|
|
5207
|
-
|
|
5208
|
-
return undefined;
|
|
5209
|
-
}
|
|
5210
|
-
return replaceMatch(fileContent, candidate.index, candidate[0].length, `shouldHavePayload(${serializedActual})`);
|
|
5477
|
+
return replaceMatch(fileContent, candidate.index, candidate.length, `shouldHavePayload(${serializedMinimalPayload})`);
|
|
5211
5478
|
};
|
|
5212
5479
|
const getFileUrlFromRemotePath = rawPathName => {
|
|
5213
5480
|
if (!rawPathName.startsWith('/remote')) {
|