@spica-devkit/testing 0.19.6 → 0.19.7

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/index.mjs CHANGED
@@ -257,6 +257,7 @@ var ChangeKind;
257
257
  ChangeKind["Update"] = "update";
258
258
  ChangeKind["Delete"] = "delete";
259
259
  })(ChangeKind || (ChangeKind = {}));
260
+ const DEFAULT_CONCURRENCY = 10;
260
261
 
261
262
  const noopProgress = {
262
263
  update() { },
@@ -11723,12 +11724,13 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
11723
11724
  return ret.join('\n') + '\n';
11724
11725
  }
11725
11726
 
11726
- async function buildPlan(modules, http, rootDir, detailed = false, detectRenames = true, reporter = silentReporter) {
11727
+ async function buildPlan(modules, http, rootDir, options = {}) {
11728
+ const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY } = options;
11727
11729
  const modulePlans = [];
11728
11730
  for (const mod of modules) {
11729
11731
  const [locals, remotes] = await Promise.all([
11730
11732
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
11731
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
11733
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
11732
11734
  ]);
11733
11735
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
11734
11736
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -11808,7 +11810,7 @@ async function buildPlan(modules, http, rootDir, detailed = false, detectRenames
11808
11810
  return { modules: modulePlans };
11809
11811
  }
11810
11812
  async function applyPlan(plan, http, opts = {}) {
11811
- const concurrency = opts.concurrency ?? 10;
11813
+ const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
11812
11814
  const reporter = opts.reporter ?? silentReporter;
11813
11815
  const errors = [];
11814
11816
  const handleErr = (label, e) => {
@@ -12008,6 +12010,14 @@ function normalizeSchema(schema) {
12008
12010
  }
12009
12011
  return normalized;
12010
12012
  }
12013
+ async function mapInBatches(items, size, fn) {
12014
+ const limit = Math.max(1, size);
12015
+ const results = [];
12016
+ for (let i = 0; i < items.length; i += limit) {
12017
+ results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
12018
+ }
12019
+ return results;
12020
+ }
12011
12021
  function isNotFoundError(error) {
12012
12022
  if (!error || typeof error !== "object")
12013
12023
  return false;
@@ -12017,6 +12027,11 @@ function isNotFoundError(error) {
12017
12027
  c.response?.status === 404 ||
12018
12028
  c.response?.statusCode === 404);
12019
12029
  }
12030
+ const emptyIfMissing = (empty) => (error) => {
12031
+ if (isNotFoundError(error))
12032
+ return empty;
12033
+ throw error;
12034
+ };
12020
12035
  const functionModule = {
12021
12036
  name: "function",
12022
12037
  displayName: "Function",
@@ -12053,17 +12068,19 @@ const functionModule = {
12053
12068
  }
12054
12069
  return results;
12055
12070
  },
12056
- async readRemote(http) {
12071
+ async readRemote(http, options = {}) {
12057
12072
  const res = await http.get("function");
12058
12073
  const fns = unwrapList(res);
12059
- return Promise.all(fns.map(async (fn) => {
12074
+ return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
12060
12075
  const id = fn._id;
12061
12076
  const [indexRes, depsRes] = await Promise.all([
12062
- http.get(`function/${id}/index`).catch(() => ({ index: "" })),
12077
+ http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
12063
12078
  http
12064
12079
  .get(`function/${id}/dependencies`)
12065
- .catch(() => [])
12066
- ]);
12080
+ .catch(emptyIfMissing([]))
12081
+ ]).catch(error => {
12082
+ throw new Error(`Could not read function "${fn.name}": ${error?.message ?? error}`);
12083
+ });
12067
12084
  const dependencies = {};
12068
12085
  for (const dep of depsRes) {
12069
12086
  dependencies[dep.name] = dep.version;
@@ -12077,7 +12094,7 @@ const functionModule = {
12077
12094
  dependencies
12078
12095
  }
12079
12096
  };
12080
- }));
12097
+ });
12081
12098
  },
12082
12099
  async create(http, local) {
12083
12100
  const id = await this.createSchema(http, local.data.schema);