@jsenv/test 3.7.14 → 3.7.16

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.
@@ -833,19 +833,47 @@ const setDecimalsPrecision = (
833
833
  // return numberTruncated
834
834
  // }
835
835
 
836
- const unitShort = {
837
- year: "y",
838
- month: "m",
839
- week: "w",
840
- day: "d",
841
- hour: "h",
842
- minute: "m",
843
- second: "s",
836
+ const UNIT_MS = {
837
+ year: 31_557_600_000,
838
+ month: 2_629_000_000,
839
+ week: 604_800_000,
840
+ day: 86_400_000,
841
+ hour: 3_600_000,
842
+ minute: 60_000,
843
+ second: 1000,
844
+ };
845
+ const UNIT_KEYS = Object.keys(UNIT_MS);
846
+ const SMALLEST_UNIT_NAME = UNIT_KEYS[UNIT_KEYS.length - 1];
847
+ const TIME_DICTIONARY_EN = {
848
+ year: { long: "year", plural: "years", short: "y" },
849
+ month: { long: "month", plural: "months", short: "m" },
850
+ week: { long: "week", plural: "weeks", short: "w" },
851
+ day: { long: "day", plural: "days", short: "d" },
852
+ hour: { long: "hour", plural: "hours", short: "h" },
853
+ minute: { long: "minute", plural: "minutes", short: "m" },
854
+ second: { long: "second", plural: "seconds", short: "s" },
855
+ joinDuration: (primary, remaining) => `${primary} and ${remaining}`,
856
+ };
857
+ const TIME_DICTIONARY_FR = {
858
+ year: { long: "an", plural: "ans", short: "a" },
859
+ month: { long: "mois", plural: "mois", short: "m" },
860
+ week: { long: "semaine", plural: "semaines", short: "s" },
861
+ day: { long: "jour", plural: "jours", short: "j" },
862
+ hour: { long: "heure", plural: "heures", short: "h" },
863
+ minute: { long: "minute", plural: "minutes", short: "m" },
864
+ second: { long: "seconde", plural: "secondes", short: "s" },
865
+ joinDuration: (primary, remaining) => `${primary} et ${remaining}`,
844
866
  };
845
867
 
846
868
  const humanizeDuration = (
847
869
  ms,
848
- { short, rounded = true, decimals } = {},
870
+ {
871
+ short,
872
+ rounded = true,
873
+ decimals,
874
+ lang = "en",
875
+ timeDictionnary = lang === "fr" ? TIME_DICTIONARY_FR : TIME_DICTIONARY_EN,
876
+ } = {},
849
877
  ) => {
850
878
  // ignore ms below meaningfulMs so that:
851
879
  // humanizeDuration(0.5) -> "0 second"
@@ -855,7 +883,9 @@ const humanizeDuration = (
855
883
  // yes we could return "0.1 millisecond" but we choosed consistency over precision
856
884
  // so that the prefered unit is "second" (and does not become millisecond when ms is super small)
857
885
  if (ms < 1) {
858
- return short ? "0s" : "0 second";
886
+ return short
887
+ ? `0${timeDictionnary.second.short}`
888
+ : `0 ${timeDictionnary.second.long}`;
859
889
  }
860
890
  const { primary, remaining } = parseMs(ms);
861
891
  if (!remaining) {
@@ -864,52 +894,51 @@ const humanizeDuration = (
864
894
  decimals === undefined ? (primary.name === "second" ? 1 : 0) : decimals,
865
895
  short,
866
896
  rounded,
897
+ timeDictionnary,
867
898
  });
868
899
  }
869
- return `${humanizeDurationUnit(primary, {
900
+ const primaryText = humanizeDurationUnit(primary, {
870
901
  decimals: decimals === undefined ? 0 : decimals,
871
902
  short,
872
903
  rounded,
873
- })} and ${humanizeDurationUnit(remaining, {
904
+ timeDictionnary,
905
+ });
906
+ const remainingText = humanizeDurationUnit(remaining, {
874
907
  decimals: decimals === undefined ? 0 : decimals,
875
908
  short,
876
909
  rounded,
877
- })}`;
910
+ timeDictionnary,
911
+ });
912
+ return timeDictionnary.joinDuration(primaryText, remainingText);
878
913
  };
879
- const humanizeDurationUnit = (unit, { decimals, short, rounded }) => {
914
+ const humanizeDurationUnit = (
915
+ unit,
916
+ { decimals, short, rounded, timeDictionnary },
917
+ ) => {
880
918
  const count = rounded
881
919
  ? setRoundedPrecision(unit.count, { decimals })
882
920
  : setPrecision(unit.count, { decimals });
883
- let name = unit.name;
921
+ const name = unit.name;
884
922
  if (short) {
885
- name = unitShort[name];
886
- return `${count}${name}`;
923
+ const unitText = timeDictionnary[name].short;
924
+ return `${count}${unitText}`;
887
925
  }
888
926
  if (count <= 1) {
889
- return `${count} ${name}`;
927
+ const unitText = timeDictionnary[name].long;
928
+ return `${count} ${unitText}`;
890
929
  }
891
- return `${count} ${name}s`;
892
- };
893
- const MS_PER_UNITS = {
894
- year: 31_557_600_000,
895
- month: 2_629_000_000,
896
- week: 604_800_000,
897
- day: 86_400_000,
898
- hour: 3_600_000,
899
- minute: 60_000,
900
- second: 1000,
930
+ const unitText = timeDictionnary[name].plural;
931
+ return `${count} ${unitText}`;
901
932
  };
902
933
 
903
934
  const parseMs = (ms) => {
904
- const unitNames = Object.keys(MS_PER_UNITS);
905
- const smallestUnitName = unitNames[unitNames.length - 1];
906
- let firstUnitName = smallestUnitName;
907
- let firstUnitCount = ms / MS_PER_UNITS[smallestUnitName];
908
- const firstUnitIndex = unitNames.findIndex((unitName) => {
909
- if (unitName === smallestUnitName) {
935
+ let firstUnitName = SMALLEST_UNIT_NAME;
936
+ let firstUnitCount = ms / UNIT_MS[SMALLEST_UNIT_NAME];
937
+ const firstUnitIndex = UNIT_KEYS.findIndex((unitName) => {
938
+ if (unitName === SMALLEST_UNIT_NAME) {
910
939
  return false;
911
940
  }
912
- const msPerUnit = MS_PER_UNITS[unitName];
941
+ const msPerUnit = UNIT_MS[unitName];
913
942
  const unitCount = Math.floor(ms / msPerUnit);
914
943
  if (unitCount) {
915
944
  firstUnitName = unitName;
@@ -918,7 +947,7 @@ const parseMs = (ms) => {
918
947
  }
919
948
  return false;
920
949
  });
921
- if (firstUnitName === smallestUnitName) {
950
+ if (firstUnitName === SMALLEST_UNIT_NAME) {
922
951
  return {
923
952
  primary: {
924
953
  name: firstUnitName,
@@ -926,9 +955,9 @@ const parseMs = (ms) => {
926
955
  },
927
956
  };
928
957
  }
929
- const remainingMs = ms - firstUnitCount * MS_PER_UNITS[firstUnitName];
930
- const remainingUnitName = unitNames[firstUnitIndex + 1];
931
- const remainingUnitCount = remainingMs / MS_PER_UNITS[remainingUnitName];
958
+ const remainingMs = ms - firstUnitCount * UNIT_MS[firstUnitName];
959
+ const remainingUnitName = UNIT_KEYS[firstUnitIndex + 1];
960
+ const remainingUnitCount = remainingMs / UNIT_MS[remainingUnitName];
932
961
  // - 1 year and 1 second is too much information
933
962
  // so we don't check the remaining units
934
963
  // - 1 year and 0.0001 week is awful
@@ -9214,9 +9243,8 @@ ${webServer.rootDirectoryUrl}`);
9214
9243
 
9215
9244
  // see also https://github.com/microsoft/playwright/releases
9216
9245
  const getBrowserVersion = (browserName) => {
9217
- const playwrightPackageJsonFileUrl = import.meta.resolve(
9218
- "playwright-core/package.json",
9219
- );
9246
+ const playwrightPackageJsonFileUrl = import.meta
9247
+ .resolve("playwright-core/package.json");
9220
9248
  const playwrightBrowsersJsonFileUrl = new URL(
9221
9249
  "./browsers.json",
9222
9250
  playwrightPackageJsonFileUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.7.14",
3
+ "version": "3.7.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/jsenv/core",
@@ -35,9 +35,9 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@c88/v8-coverage": "0.1.1",
38
- "@jsenv/ast": "6.7.16",
39
- "@jsenv/plugin-supervisor": "1.7.10",
40
- "@jsenv/sourcemap": "1.3.12",
38
+ "@jsenv/ast": "6.7.18",
39
+ "@jsenv/plugin-supervisor": "1.7.12",
40
+ "@jsenv/sourcemap": "1.3.14",
41
41
  "he": "1.2.0",
42
42
  "istanbul-lib-coverage": "3.2.2",
43
43
  "istanbul-lib-instrument": "6.0.3",
@@ -65,7 +65,7 @@
65
65
  "@jsenv/url-meta": "../../tooling/url-meta",
66
66
  "@jsenv/urls": "../../tooling/urls",
67
67
  "@jsenv/utils": "../../tooling/utils",
68
- "prettier": "3.6.2",
68
+ "prettier": "3.7.4",
69
69
  "strip-ansi": "7.1.2",
70
70
  "supports-color": "10.2.2"
71
71
  },
@@ -494,9 +494,8 @@ ${webServer.rootDirectoryUrl}`);
494
494
 
495
495
  // see also https://github.com/microsoft/playwright/releases
496
496
  const getBrowserVersion = (browserName) => {
497
- const playwrightPackageJsonFileUrl = import.meta.resolve(
498
- "playwright-core/package.json",
499
- );
497
+ const playwrightPackageJsonFileUrl = import.meta
498
+ .resolve("playwright-core/package.json");
500
499
  const playwrightBrowsersJsonFileUrl = new URL(
501
500
  "./browsers.json",
502
501
  playwrightPackageJsonFileUrl,