@lvce-editor/test-worker 15.2.0 → 15.3.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 CHANGED
@@ -672,6 +672,7 @@ interface Git {
672
672
  readonly pull: (remote: string, branch: string) => Promise<void>;
673
673
  readonly push: (remote: string, branch: string) => Promise<void>;
674
674
  readonly setConfig: (key: string, value: string) => Promise<void>;
675
+ readonly shouldHaveCommit: (message: string) => Promise<void>;
675
676
  readonly shouldHaveInvocations: (invocations: readonly GitInvocation[]) => Promise<void>;
676
677
  readonly status: () => Promise<unknown>;
677
678
  }
@@ -3981,6 +3981,21 @@ const addRemote = async (name, remoteUrl) => {
3981
3981
  const setConfig = async (key, value) => {
3982
3982
  await invoke('ExtensionHost.executeCommand', 'git.setConfig', key, value);
3983
3983
  };
3984
+ const shouldHaveCommit = async message => {
3985
+ const commits = await invoke('ExtensionHost.executeCommand', 'git.getCommits');
3986
+ if (!Array.isArray(commits)) {
3987
+ throw new TypeError(`Expected commits to be an array, but got ${commits}`);
3988
+ }
3989
+ if (commits.length !== 1) {
3990
+ throw new Error(`Expected 1 commit, but got ${commits.length}`);
3991
+ }
3992
+ if (!commits[0].hash) {
3993
+ throw new Error('Expected commit hash to be defined');
3994
+ }
3995
+ if (commits[0].message !== message) {
3996
+ throw new Error(`Expected commit message to be "${message}", but got "${commits[0].message}"`);
3997
+ }
3998
+ };
3984
3999
  const shouldHaveInvocations = async invocations => {
3985
4000
  // TODO
3986
4001
  };
@@ -3997,6 +4012,7 @@ const Git = {
3997
4012
  pull,
3998
4013
  push: push$1,
3999
4014
  setConfig,
4015
+ shouldHaveCommit,
4000
4016
  shouldHaveInvocations,
4001
4017
  status
4002
4018
  };
@@ -5356,96 +5372,13 @@ const handleFileWatcherEvent = async event => {
5356
5372
  await hotReloadTest(lastItem, locationHref, time);
5357
5373
  };
5358
5374
 
5359
- const whitespaceRegex = /\s+/g;
5360
- const shouldHavePayloadSearch = 'shouldHavePayload(';
5361
- const validIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5362
- const normalizeWhitespace = value => {
5363
- return value.replaceAll(whitespaceRegex, '');
5364
- };
5365
- const isObject = value => {
5366
- return typeof value === 'object' && value !== null && !Array.isArray(value);
5367
- };
5368
- const projectActualOntoExpected = (actualValue, expectedValue) => {
5369
- if (Array.isArray(expectedValue)) {
5370
- if (!Array.isArray(actualValue)) {
5371
- return actualValue;
5372
- }
5373
- const length = Math.min(expectedValue.length, actualValue.length);
5374
- return actualValue.slice(0, length).map((item, index) => projectActualOntoExpected(item, expectedValue[index]));
5375
- }
5376
- if (isObject(expectedValue)) {
5377
- if (!isObject(actualValue)) {
5378
- return actualValue;
5379
- }
5380
- const result = {};
5381
- for (const key of Object.keys(expectedValue)) {
5382
- if (!Object.hasOwn(actualValue, key)) {
5383
- continue;
5384
- }
5385
- result[key] = projectActualOntoExpected(actualValue[key], expectedValue[key]);
5386
- }
5387
- return result;
5388
- }
5389
- return actualValue;
5390
- };
5391
- const quoteString = value => {
5392
- return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t')}'`;
5393
- };
5394
- const formatObjectKey = key => {
5395
- if (validIdentifierRegex.test(key)) {
5396
- return key;
5397
- }
5398
- return quoteString(key);
5399
- };
5400
- const trySerialize = (value, indent = 0) => {
5401
- try {
5402
- if (value === null) {
5403
- return 'null';
5404
- }
5405
- if (typeof value === 'string') {
5406
- return quoteString(value);
5407
- }
5408
- if (typeof value === 'number' || typeof value === 'boolean') {
5409
- return JSON.stringify(value);
5410
- }
5411
- if (Array.isArray(value)) {
5412
- if (value.length === 0) {
5413
- return '[]';
5414
- }
5415
- const nextIndent = indent + 2;
5416
- const serializedItems = value.map(item => `${' '.repeat(nextIndent)}${trySerialize(item, nextIndent)}`);
5417
- return `[
5418
- ${serializedItems.join(',\n')}
5419
- ${' '.repeat(indent)}]`;
5420
- }
5421
- if (isObject(value)) {
5422
- const entries = Object.entries(value);
5423
- if (entries.length === 0) {
5424
- return '{}';
5425
- }
5426
- const nextIndent = indent + 2;
5427
- const serializedEntries = [];
5428
- for (const entry of entries) {
5429
- const [key, item] = entry;
5430
- serializedEntries.push(`${' '.repeat(nextIndent)}${formatObjectKey(key)}: ${trySerialize(item, nextIndent)}`);
5431
- }
5432
- return `{
5433
- ${serializedEntries.join(',\n')}
5434
- ${' '.repeat(indent)}}`;
5435
- }
5436
- return undefined;
5437
- } catch {
5438
- return undefined;
5375
+ const isAutoFixError = value => {
5376
+ if (!value) {
5377
+ return false;
5439
5378
  }
5379
+ return value.code === 'chat-debug.should-have-payload';
5440
5380
  };
5441
- const replaceMatch = (fileContent, index, length, replacement) => {
5442
- const before = fileContent.slice(0, index);
5443
- const after = fileContent.slice(index + length);
5444
- return `${before}${replacement}${after}`;
5445
- };
5446
- const isStringDelimiter = character => {
5447
- return character === "'" || character === '"' || character === '`';
5448
- };
5381
+
5449
5382
  const consumeComment = (inBlockComment, inLineComment, character, nextCharacter) => {
5450
5383
  if (inLineComment) {
5451
5384
  if (character === '\n') {
@@ -5495,6 +5428,11 @@ const consumeComment = (inBlockComment, inLineComment, character, nextCharacter)
5495
5428
  inLineComment
5496
5429
  };
5497
5430
  };
5431
+
5432
+ const isStringDelimiter = character => {
5433
+ return character === "'" || character === '"' || character === '`';
5434
+ };
5435
+
5498
5436
  const consumeString = (stringDelimiter, character) => {
5499
5437
  if (!stringDelimiter) {
5500
5438
  if (isStringDelimiter(character)) {
@@ -5525,6 +5463,7 @@ const consumeString = (stringDelimiter, character) => {
5525
5463
  stringDelimiter
5526
5464
  };
5527
5465
  };
5466
+
5528
5467
  const findClosingParenthesis = (fileContent, startIndex) => {
5529
5468
  let depth = 1;
5530
5469
  let inBlockComment = false;
@@ -5570,6 +5509,8 @@ const findClosingParenthesis = (fileContent, startIndex) => {
5570
5509
  }
5571
5510
  return -1;
5572
5511
  };
5512
+
5513
+ const shouldHavePayloadSearch = 'shouldHavePayload(';
5573
5514
  const findShouldHavePayloadMatches = fileContent => {
5574
5515
  const matches = [];
5575
5516
  let searchIndex = 0;
@@ -5592,6 +5533,101 @@ const findShouldHavePayloadMatches = fileContent => {
5592
5533
  }
5593
5534
  return matches;
5594
5535
  };
5536
+
5537
+ const whitespaceRegex = /\s+/g;
5538
+ const trailingCommaRegex = /,([}\]])/g;
5539
+ const normalizeWhitespace = value => {
5540
+ return value.replaceAll(whitespaceRegex, '').replaceAll(trailingCommaRegex, '$1');
5541
+ };
5542
+
5543
+ const isObject = value => {
5544
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
5545
+ };
5546
+
5547
+ const projectActualOntoExpected = (actualValue, expectedValue) => {
5548
+ if (Array.isArray(expectedValue)) {
5549
+ if (!Array.isArray(actualValue)) {
5550
+ return actualValue;
5551
+ }
5552
+ const length = Math.min(expectedValue.length, actualValue.length);
5553
+ return actualValue.slice(0, length).map((item, index) => projectActualOntoExpected(item, expectedValue[index]));
5554
+ }
5555
+ if (isObject(expectedValue)) {
5556
+ if (!isObject(actualValue)) {
5557
+ return actualValue;
5558
+ }
5559
+ const result = {};
5560
+ for (const key of Object.keys(expectedValue)) {
5561
+ if (!Object.hasOwn(actualValue, key)) {
5562
+ continue;
5563
+ }
5564
+ result[key] = projectActualOntoExpected(actualValue[key], expectedValue[key]);
5565
+ }
5566
+ return result;
5567
+ }
5568
+ return actualValue;
5569
+ };
5570
+
5571
+ const replaceMatch = (fileContent, index, length, replacement) => {
5572
+ const before = fileContent.slice(0, index);
5573
+ const after = fileContent.slice(index + length);
5574
+ return `${before}${replacement}${after}`;
5575
+ };
5576
+
5577
+ const quoteString = value => {
5578
+ return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t')}'`;
5579
+ };
5580
+
5581
+ const validIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5582
+ const formatObjectKey = key => {
5583
+ if (validIdentifierRegex.test(key)) {
5584
+ return key;
5585
+ }
5586
+ return quoteString(key);
5587
+ };
5588
+
5589
+ const trySerialize = (value, indent = 0) => {
5590
+ try {
5591
+ if (value === null) {
5592
+ return 'null';
5593
+ }
5594
+ if (typeof value === 'string') {
5595
+ return quoteString(value);
5596
+ }
5597
+ if (typeof value === 'number' || typeof value === 'boolean') {
5598
+ return JSON.stringify(value);
5599
+ }
5600
+ if (Array.isArray(value)) {
5601
+ if (value.length === 0) {
5602
+ return '[]';
5603
+ }
5604
+ const nextIndent = indent + 2;
5605
+ const serializedItems = value.map(item => `${' '.repeat(nextIndent)}${trySerialize(item, nextIndent)}`);
5606
+ return `[
5607
+ ${serializedItems.join(',\n')}
5608
+ ${' '.repeat(indent)}]`;
5609
+ }
5610
+ if (isObject(value)) {
5611
+ const entries = Object.entries(value);
5612
+ if (entries.length === 0) {
5613
+ return '{}';
5614
+ }
5615
+ const nextIndent = indent + 2;
5616
+ const serializedEntries = [];
5617
+ for (const entry of entries) {
5618
+ const [key, item] = entry;
5619
+ serializedEntries.push(`${' '.repeat(nextIndent)}${formatObjectKey(key)}: ${trySerialize(item, nextIndent)}`);
5620
+ }
5621
+ return `{
5622
+ ${serializedEntries.join(',\n')}
5623
+ ${' '.repeat(indent)}}`;
5624
+ }
5625
+ return undefined;
5626
+ } catch {
5627
+ return undefined;
5628
+ }
5629
+ };
5630
+
5595
5631
  const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) => {
5596
5632
  const minimalPayload = projectActualOntoExpected(actualPayload, expectedPayload);
5597
5633
  const serializedMinimalPayload = trySerialize(minimalPayload);
@@ -5623,6 +5659,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
5623
5659
  const [candidate] = matchingCandidates;
5624
5660
  return replaceMatch(fileContent, candidate.index, candidate.length, `shouldHavePayload(${serializedMinimalPayload})`);
5625
5661
  };
5662
+
5626
5663
  const getFileUrlFromRemotePath = rawPathName => {
5627
5664
  if (!rawPathName.startsWith('/remote')) {
5628
5665
  return undefined;
@@ -5630,6 +5667,7 @@ const getFileUrlFromRemotePath = rawPathName => {
5630
5667
  const rest = rawPathName.slice('/remote'.length);
5631
5668
  return `file://${rest}`;
5632
5669
  };
5670
+
5633
5671
  const toFileUrl = (url, locationHref) => {
5634
5672
  const parsedUrl = new URL(url, locationHref);
5635
5673
  if (parsedUrl.protocol === 'file:') {
@@ -5639,68 +5677,39 @@ const toFileUrl = (url, locationHref) => {
5639
5677
  }
5640
5678
  return getFileUrlFromRemotePath(parsedUrl.pathname);
5641
5679
  };
5642
- const isAutoFixError = value => {
5643
- if (!value) {
5644
- return false;
5645
- }
5646
- return value.code === 'chat-debug.should-have-payload';
5647
- };
5648
- const defaultDependencies = {
5649
- getAutoFixError() {
5650
- return get$1();
5651
- },
5652
- getLatestTestInfo() {
5653
- return maybeLast();
5654
- },
5655
- getLocationHref() {
5656
- return location.href;
5657
- },
5658
- now: Date.now,
5659
- readFile(uri) {
5660
- return readFile(uri);
5661
- },
5662
- rerun(url, platform, assetDir) {
5663
- return execute(url, platform, assetDir);
5664
- },
5665
- setAutoFixError(value) {
5666
- set$1(value);
5667
- },
5668
- writeFile(uri, content) {
5669
- return writeFile(uri, content);
5670
- }
5671
- };
5672
- const tryAutoFixWith = async dependencies => {
5673
- const latestTestInfo = dependencies.getLatestTestInfo();
5680
+
5681
+ const tryAutoFixWith = async () => {
5682
+ const latestTestInfo = maybeLast();
5674
5683
  if (!latestTestInfo) {
5675
5684
  return;
5676
5685
  }
5677
5686
  if (latestTestInfo.inProgress) {
5678
5687
  return;
5679
5688
  }
5680
- const autoFixError = dependencies.getAutoFixError();
5689
+ const autoFixError = get$1();
5681
5690
  if (!isAutoFixError(autoFixError)) {
5682
5691
  return;
5683
5692
  }
5684
5693
  if (autoFixError.actualPayload === undefined) {
5685
5694
  return;
5686
5695
  }
5687
- const locationHref = dependencies.getLocationHref();
5688
- const fileUrl = toFileUrl(latestTestInfo.url, locationHref);
5696
+ const fileUrl = toFileUrl(latestTestInfo.url, location.href);
5689
5697
  if (!fileUrl) {
5690
5698
  return;
5691
5699
  }
5692
- const fileContent = await dependencies.readFile(fileUrl);
5700
+ const fileContent = await readFile(fileUrl);
5693
5701
  const updatedFileContent = replaceShouldHavePayload(fileContent, autoFixError.expectedPayload, autoFixError.actualPayload);
5694
5702
  if (!updatedFileContent || updatedFileContent === fileContent) {
5695
5703
  return;
5696
5704
  }
5697
- await dependencies.writeFile(fileUrl, updatedFileContent);
5698
- dependencies.setAutoFixError(undefined);
5699
- const rerunUrl = createUrlWithQueryParameter(latestTestInfo.url, locationHref, dependencies.now());
5700
- await dependencies.rerun(rerunUrl, latestTestInfo.platform, latestTestInfo.assetDir);
5705
+ await writeFile(fileUrl, updatedFileContent);
5706
+ set$1(undefined);
5707
+ const rerunUrl = createUrlWithQueryParameter(latestTestInfo.url, location.href, Date.now());
5708
+ await execute(rerunUrl, latestTestInfo.platform, latestTestInfo.assetDir);
5701
5709
  };
5710
+
5702
5711
  const tryAutoFix = async () => {
5703
- await tryAutoFixWith(defaultDependencies);
5712
+ await tryAutoFixWith();
5704
5713
  };
5705
5714
 
5706
5715
  const commandMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "15.2.0",
3
+ "version": "15.3.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",