@lvce-editor/test-worker 15.2.0 → 15.4.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
@@ -162,6 +162,16 @@ export interface Dirent {
162
162
  readonly type: number;
163
163
  }
164
164
 
165
+ export interface GitInitOptions {
166
+ readonly bare?: boolean;
167
+ readonly initialBranch?: string;
168
+ readonly uri?: string;
169
+ }
170
+
171
+ export interface GitPushOptions {
172
+ readonly setUpstream?: readonly string[];
173
+ }
174
+
165
175
  export interface GitInvocation {
166
176
  readonly command: readonly string[];
167
177
  readonly cwd: string;
@@ -667,11 +677,13 @@ interface Git {
667
677
  readonly checkout: (ref: string) => Promise<void>;
668
678
  readonly clone: (repositoryUrl: string, cwd: string) => Promise<void>;
669
679
  readonly commit: (message: string) => Promise<void>;
680
+ readonly config: (values: Record<string, string>) => Promise<void>;
670
681
  readonly fetch: (remote: string) => Promise<void>;
671
- readonly init: () => Promise<void>;
682
+ readonly init: (options?: GitInitOptions) => Promise<void>;
672
683
  readonly pull: (remote: string, branch: string) => Promise<void>;
673
- readonly push: (remote: string, branch: string) => Promise<void>;
684
+ readonly push: (remoteOrOptions?: string | GitPushOptions, branch?: string) => Promise<void>;
674
685
  readonly setConfig: (key: string, value: string) => Promise<void>;
686
+ readonly shouldHaveCommit: (message: string) => Promise<void>;
675
687
  readonly shouldHaveInvocations: (invocations: readonly GitInvocation[]) => Promise<void>;
676
688
  readonly status: () => Promise<unknown>;
677
689
  }
@@ -3945,8 +3945,8 @@ const FindWidget = {
3945
3945
  toggleUseRegularExpression: toggleUseRegularExpression$1
3946
3946
  };
3947
3947
 
3948
- const init = async () => {
3949
- await invoke('ExtensionHost.executeCommand', 'git.init');
3948
+ const init = async (options = {}) => {
3949
+ await invoke('ExtensionHost.executeCommand', 'git.init', options);
3950
3950
  };
3951
3951
  const clone = async (repositoryUrl, cwd) => {
3952
3952
  await invoke('ExtensionHost.executeCommand', 'git.clone', repositoryUrl, cwd);
@@ -3957,8 +3957,14 @@ const add = async pathSpec => {
3957
3957
  const commit = async message => {
3958
3958
  await invoke('ExtensionHost.executeCommand', 'git.commit', message);
3959
3959
  };
3960
- const push$1 = async (remote, branch) => {
3961
- await invoke('ExtensionHost.executeCommand', 'git.push', remote, branch);
3960
+ const push$1 = async (remoteOrOptions, branch) => {
3961
+ if (typeof remoteOrOptions === 'string') {
3962
+ await invoke('ExtensionHost.executeCommand', 'git.push', {
3963
+ setUpstream: [remoteOrOptions, branch || '']
3964
+ });
3965
+ return;
3966
+ }
3967
+ await invoke('ExtensionHost.executeCommand', 'git.push', remoteOrOptions || {});
3962
3968
  };
3963
3969
  const pull = async (remote, branch) => {
3964
3970
  await invoke('ExtensionHost.executeCommand', 'git.pull', remote, branch);
@@ -3981,6 +3987,26 @@ const addRemote = async (name, remoteUrl) => {
3981
3987
  const setConfig = async (key, value) => {
3982
3988
  await invoke('ExtensionHost.executeCommand', 'git.setConfig', key, value);
3983
3989
  };
3990
+ const config = async values => {
3991
+ for (const [key, value] of Object.entries(values)) {
3992
+ await setConfig(key, value);
3993
+ }
3994
+ };
3995
+ const shouldHaveCommit = async message => {
3996
+ const commits = await invoke('ExtensionHost.executeCommand', 'git.getCommits');
3997
+ if (!Array.isArray(commits)) {
3998
+ throw new TypeError(`Expected commits to be an array, but got ${commits}`);
3999
+ }
4000
+ if (commits.length !== 1) {
4001
+ throw new Error(`Expected 1 commit, but got ${commits.length}`);
4002
+ }
4003
+ if (!commits[0].hash) {
4004
+ throw new Error('Expected commit hash to be defined');
4005
+ }
4006
+ if (commits[0].message !== message) {
4007
+ throw new Error(`Expected commit message to be "${message}", but got "${commits[0].message}"`);
4008
+ }
4009
+ };
3984
4010
  const shouldHaveInvocations = async invocations => {
3985
4011
  // TODO
3986
4012
  };
@@ -3992,11 +4018,13 @@ const Git = {
3992
4018
  checkout,
3993
4019
  clone,
3994
4020
  commit,
4021
+ config,
3995
4022
  fetch: fetch$1,
3996
4023
  init,
3997
4024
  pull,
3998
4025
  push: push$1,
3999
4026
  setConfig,
4027
+ shouldHaveCommit,
4000
4028
  shouldHaveInvocations,
4001
4029
  status
4002
4030
  };
@@ -5356,96 +5384,13 @@ const handleFileWatcherEvent = async event => {
5356
5384
  await hotReloadTest(lastItem, locationHref, time);
5357
5385
  };
5358
5386
 
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;
5387
+ const isAutoFixError = value => {
5388
+ if (!value) {
5389
+ return false;
5439
5390
  }
5391
+ return value.code === 'chat-debug.should-have-payload';
5440
5392
  };
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
- };
5393
+
5449
5394
  const consumeComment = (inBlockComment, inLineComment, character, nextCharacter) => {
5450
5395
  if (inLineComment) {
5451
5396
  if (character === '\n') {
@@ -5495,6 +5440,11 @@ const consumeComment = (inBlockComment, inLineComment, character, nextCharacter)
5495
5440
  inLineComment
5496
5441
  };
5497
5442
  };
5443
+
5444
+ const isStringDelimiter = character => {
5445
+ return character === "'" || character === '"' || character === '`';
5446
+ };
5447
+
5498
5448
  const consumeString = (stringDelimiter, character) => {
5499
5449
  if (!stringDelimiter) {
5500
5450
  if (isStringDelimiter(character)) {
@@ -5525,6 +5475,7 @@ const consumeString = (stringDelimiter, character) => {
5525
5475
  stringDelimiter
5526
5476
  };
5527
5477
  };
5478
+
5528
5479
  const findClosingParenthesis = (fileContent, startIndex) => {
5529
5480
  let depth = 1;
5530
5481
  let inBlockComment = false;
@@ -5570,6 +5521,8 @@ const findClosingParenthesis = (fileContent, startIndex) => {
5570
5521
  }
5571
5522
  return -1;
5572
5523
  };
5524
+
5525
+ const shouldHavePayloadSearch = 'shouldHavePayload(';
5573
5526
  const findShouldHavePayloadMatches = fileContent => {
5574
5527
  const matches = [];
5575
5528
  let searchIndex = 0;
@@ -5592,6 +5545,101 @@ const findShouldHavePayloadMatches = fileContent => {
5592
5545
  }
5593
5546
  return matches;
5594
5547
  };
5548
+
5549
+ const whitespaceRegex = /\s+/g;
5550
+ const trailingCommaRegex = /,([}\]])/g;
5551
+ const normalizeWhitespace = value => {
5552
+ return value.replaceAll(whitespaceRegex, '').replaceAll(trailingCommaRegex, '$1');
5553
+ };
5554
+
5555
+ const isObject = value => {
5556
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
5557
+ };
5558
+
5559
+ const projectActualOntoExpected = (actualValue, expectedValue) => {
5560
+ if (Array.isArray(expectedValue)) {
5561
+ if (!Array.isArray(actualValue)) {
5562
+ return actualValue;
5563
+ }
5564
+ const length = Math.min(expectedValue.length, actualValue.length);
5565
+ return actualValue.slice(0, length).map((item, index) => projectActualOntoExpected(item, expectedValue[index]));
5566
+ }
5567
+ if (isObject(expectedValue)) {
5568
+ if (!isObject(actualValue)) {
5569
+ return actualValue;
5570
+ }
5571
+ const result = {};
5572
+ for (const key of Object.keys(expectedValue)) {
5573
+ if (!Object.hasOwn(actualValue, key)) {
5574
+ continue;
5575
+ }
5576
+ result[key] = projectActualOntoExpected(actualValue[key], expectedValue[key]);
5577
+ }
5578
+ return result;
5579
+ }
5580
+ return actualValue;
5581
+ };
5582
+
5583
+ const replaceMatch = (fileContent, index, length, replacement) => {
5584
+ const before = fileContent.slice(0, index);
5585
+ const after = fileContent.slice(index + length);
5586
+ return `${before}${replacement}${after}`;
5587
+ };
5588
+
5589
+ const quoteString = value => {
5590
+ return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t')}'`;
5591
+ };
5592
+
5593
+ const validIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
5594
+ const formatObjectKey = key => {
5595
+ if (validIdentifierRegex.test(key)) {
5596
+ return key;
5597
+ }
5598
+ return quoteString(key);
5599
+ };
5600
+
5601
+ const trySerialize = (value, indent = 0) => {
5602
+ try {
5603
+ if (value === null) {
5604
+ return 'null';
5605
+ }
5606
+ if (typeof value === 'string') {
5607
+ return quoteString(value);
5608
+ }
5609
+ if (typeof value === 'number' || typeof value === 'boolean') {
5610
+ return JSON.stringify(value);
5611
+ }
5612
+ if (Array.isArray(value)) {
5613
+ if (value.length === 0) {
5614
+ return '[]';
5615
+ }
5616
+ const nextIndent = indent + 2;
5617
+ const serializedItems = value.map(item => `${' '.repeat(nextIndent)}${trySerialize(item, nextIndent)}`);
5618
+ return `[
5619
+ ${serializedItems.join(',\n')}
5620
+ ${' '.repeat(indent)}]`;
5621
+ }
5622
+ if (isObject(value)) {
5623
+ const entries = Object.entries(value);
5624
+ if (entries.length === 0) {
5625
+ return '{}';
5626
+ }
5627
+ const nextIndent = indent + 2;
5628
+ const serializedEntries = [];
5629
+ for (const entry of entries) {
5630
+ const [key, item] = entry;
5631
+ serializedEntries.push(`${' '.repeat(nextIndent)}${formatObjectKey(key)}: ${trySerialize(item, nextIndent)}`);
5632
+ }
5633
+ return `{
5634
+ ${serializedEntries.join(',\n')}
5635
+ ${' '.repeat(indent)}}`;
5636
+ }
5637
+ return undefined;
5638
+ } catch {
5639
+ return undefined;
5640
+ }
5641
+ };
5642
+
5595
5643
  const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) => {
5596
5644
  const minimalPayload = projectActualOntoExpected(actualPayload, expectedPayload);
5597
5645
  const serializedMinimalPayload = trySerialize(minimalPayload);
@@ -5623,6 +5671,7 @@ const replaceShouldHavePayload = (fileContent, expectedPayload, actualPayload) =
5623
5671
  const [candidate] = matchingCandidates;
5624
5672
  return replaceMatch(fileContent, candidate.index, candidate.length, `shouldHavePayload(${serializedMinimalPayload})`);
5625
5673
  };
5674
+
5626
5675
  const getFileUrlFromRemotePath = rawPathName => {
5627
5676
  if (!rawPathName.startsWith('/remote')) {
5628
5677
  return undefined;
@@ -5630,6 +5679,7 @@ const getFileUrlFromRemotePath = rawPathName => {
5630
5679
  const rest = rawPathName.slice('/remote'.length);
5631
5680
  return `file://${rest}`;
5632
5681
  };
5682
+
5633
5683
  const toFileUrl = (url, locationHref) => {
5634
5684
  const parsedUrl = new URL(url, locationHref);
5635
5685
  if (parsedUrl.protocol === 'file:') {
@@ -5639,68 +5689,39 @@ const toFileUrl = (url, locationHref) => {
5639
5689
  }
5640
5690
  return getFileUrlFromRemotePath(parsedUrl.pathname);
5641
5691
  };
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();
5692
+
5693
+ const tryAutoFixWith = async () => {
5694
+ const latestTestInfo = maybeLast();
5674
5695
  if (!latestTestInfo) {
5675
5696
  return;
5676
5697
  }
5677
5698
  if (latestTestInfo.inProgress) {
5678
5699
  return;
5679
5700
  }
5680
- const autoFixError = dependencies.getAutoFixError();
5701
+ const autoFixError = get$1();
5681
5702
  if (!isAutoFixError(autoFixError)) {
5682
5703
  return;
5683
5704
  }
5684
5705
  if (autoFixError.actualPayload === undefined) {
5685
5706
  return;
5686
5707
  }
5687
- const locationHref = dependencies.getLocationHref();
5688
- const fileUrl = toFileUrl(latestTestInfo.url, locationHref);
5708
+ const fileUrl = toFileUrl(latestTestInfo.url, location.href);
5689
5709
  if (!fileUrl) {
5690
5710
  return;
5691
5711
  }
5692
- const fileContent = await dependencies.readFile(fileUrl);
5712
+ const fileContent = await readFile(fileUrl);
5693
5713
  const updatedFileContent = replaceShouldHavePayload(fileContent, autoFixError.expectedPayload, autoFixError.actualPayload);
5694
5714
  if (!updatedFileContent || updatedFileContent === fileContent) {
5695
5715
  return;
5696
5716
  }
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);
5717
+ await writeFile(fileUrl, updatedFileContent);
5718
+ set$1(undefined);
5719
+ const rerunUrl = createUrlWithQueryParameter(latestTestInfo.url, location.href, Date.now());
5720
+ await execute(rerunUrl, latestTestInfo.platform, latestTestInfo.assetDir);
5701
5721
  };
5722
+
5702
5723
  const tryAutoFix = async () => {
5703
- await tryAutoFixWith(defaultDependencies);
5724
+ await tryAutoFixWith();
5704
5725
  };
5705
5726
 
5706
5727
  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.4.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",