@jsenv/test 3.7.5 → 3.7.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.
@@ -527,60 +527,6 @@ const SIGINT_CALLBACK = {
527
527
  },
528
528
  };
529
529
 
530
- const isFileSystemPath = (value) => {
531
- if (typeof value !== "string") {
532
- throw new TypeError(
533
- `isFileSystemPath first arg must be a string, got ${value}`,
534
- );
535
- }
536
- if (value[0] === "/") {
537
- return true;
538
- }
539
- return startsWithWindowsDriveLetter(value);
540
- };
541
-
542
- const startsWithWindowsDriveLetter = (string) => {
543
- const firstChar = string[0];
544
- if (!/[a-zA-Z]/.test(firstChar)) return false;
545
-
546
- const secondChar = string[1];
547
- if (secondChar !== ":") return false;
548
-
549
- return true;
550
- };
551
-
552
- const fileSystemPathToUrl = (value) => {
553
- if (!isFileSystemPath(value)) {
554
- throw new Error(`value must be a filesystem path, got ${value}`);
555
- }
556
- return String(pathToFileURL(value));
557
- };
558
-
559
- const urlToFileSystemPath = (url) => {
560
- const urlObject = new URL(url);
561
- let { origin, pathname, hash } = urlObject;
562
- if (urlObject.protocol === "file:") {
563
- origin = "file://";
564
- }
565
- pathname = pathname
566
- .split("/")
567
- .map((part) => {
568
- return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
569
- })
570
- .join("/");
571
- if (hash) {
572
- pathname += `%23${encodeURIComponent(hash.slice(1))}`;
573
- }
574
- const urlString = `${origin}${pathname}`;
575
- const fileSystemPath = fileURLToPath(urlString);
576
- if (fileSystemPath[fileSystemPath.length - 1] === "/") {
577
- // remove trailing / so that nodejs path becomes predictable otherwise it logs
578
- // the trailing slash on linux but does not on windows
579
- return fileSystemPath.slice(0, -1);
580
- }
581
- return fileSystemPath;
582
- };
583
-
584
530
  const createDetailedMessage = (message, details = {}) => {
585
531
  let text = `${message}`;
586
532
  const namedSectionsText = renderNamedSections(details);
@@ -1869,6 +1815,28 @@ const moveUrl = ({ url, from, to, preferRelative }) => {
1869
1815
  return absoluteUrl;
1870
1816
  };
1871
1817
 
1818
+ const isFileSystemPath = (value) => {
1819
+ if (typeof value !== "string") {
1820
+ throw new TypeError(
1821
+ `isFileSystemPath first arg must be a string, got ${value}`,
1822
+ );
1823
+ }
1824
+ if (value[0] === "/") {
1825
+ return true;
1826
+ }
1827
+ return startsWithWindowsDriveLetter(value);
1828
+ };
1829
+
1830
+ const startsWithWindowsDriveLetter = (string) => {
1831
+ const firstChar = string[0];
1832
+ if (!/[a-zA-Z]/.test(firstChar)) return false;
1833
+
1834
+ const secondChar = string[1];
1835
+ if (secondChar !== ":") return false;
1836
+
1837
+ return true;
1838
+ };
1839
+
1872
1840
  const resolveUrl = (specifier, baseUrl) => {
1873
1841
  if (typeof baseUrl === "undefined") {
1874
1842
  throw new TypeError(`baseUrl missing to resolve ${specifier}`);
@@ -1876,7 +1844,7 @@ const resolveUrl = (specifier, baseUrl) => {
1876
1844
  return String(new URL(specifier, baseUrl));
1877
1845
  };
1878
1846
 
1879
- const urlIsInsideOf = (url, otherUrl) => {
1847
+ const urlIsOrIsInsideOf = (url, otherUrl) => {
1880
1848
  const urlObject = new URL(url);
1881
1849
  const otherUrlObject = new URL(otherUrl);
1882
1850
 
@@ -1887,13 +1855,45 @@ const urlIsInsideOf = (url, otherUrl) => {
1887
1855
  const urlPathname = urlObject.pathname;
1888
1856
  const otherUrlPathname = otherUrlObject.pathname;
1889
1857
  if (urlPathname === otherUrlPathname) {
1890
- return false;
1858
+ return true;
1891
1859
  }
1892
1860
 
1893
1861
  const isInside = urlPathname.startsWith(otherUrlPathname);
1894
1862
  return isInside;
1895
1863
  };
1896
1864
 
1865
+ const fileSystemPathToUrl = (value) => {
1866
+ if (!isFileSystemPath(value)) {
1867
+ throw new Error(`value must be a filesystem path, got ${value}`);
1868
+ }
1869
+ return String(pathToFileURL(value));
1870
+ };
1871
+
1872
+ const urlToFileSystemPath = (url) => {
1873
+ const urlObject = new URL(url);
1874
+ let { origin, pathname, hash } = urlObject;
1875
+ if (urlObject.protocol === "file:") {
1876
+ origin = "file://";
1877
+ }
1878
+ pathname = pathname
1879
+ .split("/")
1880
+ .map((part) => {
1881
+ return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
1882
+ })
1883
+ .join("/");
1884
+ if (hash) {
1885
+ pathname += `%23${encodeURIComponent(hash.slice(1))}`;
1886
+ }
1887
+ const urlString = `${origin}${pathname}`;
1888
+ const fileSystemPath = fileURLToPath(urlString);
1889
+ if (fileSystemPath[fileSystemPath.length - 1] === "/") {
1890
+ // remove trailing / so that nodejs path becomes predictable otherwise it logs
1891
+ // the trailing slash on linux but does not on windows
1892
+ return fileSystemPath.slice(0, -1);
1893
+ }
1894
+ return fileSystemPath;
1895
+ };
1896
+
1897
1897
  const validateDirectoryUrl = (value) => {
1898
1898
  let urlString;
1899
1899
 
@@ -5549,7 +5549,7 @@ const asException = (error, { rootDirectoryUrl }) => {
5549
5549
  exception.stack = replaceUrls$1(
5550
5550
  error.stack,
5551
5551
  ({ match, url, line = 1, column = 1 }) => {
5552
- if (urlIsInsideOf(url, rootDirectoryUrl)) {
5552
+ if (urlIsOrIsInsideOf(url, rootDirectoryUrl)) {
5553
5553
  const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
5554
5554
  match = stringifyUrlSite({ url: relativeUrl, line, column });
5555
5555
  }
@@ -5561,7 +5561,7 @@ const asException = (error, { rootDirectoryUrl }) => {
5561
5561
  exception.stack = replaceUrls$1(
5562
5562
  error.stack,
5563
5563
  ({ match, url, line = 1, column = 1 }) => {
5564
- if (urlIsInsideOf(url, rootDirectoryUrl)) {
5564
+ if (urlIsOrIsInsideOf(url, rootDirectoryUrl)) {
5565
5565
  const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
5566
5566
  match = stringifyUrlSite({ url: relativeUrl, line, column });
5567
5567
  }
@@ -8021,7 +8021,7 @@ To fix this warning:
8021
8021
  for (const { relativeUrl, meta } of fileResultArray) {
8022
8022
  if (onlyWithinUrl) {
8023
8023
  const fileUrl = new URL(relativeUrl, rootDirectoryUrl).href;
8024
- if (!urlIsInsideOf(fileUrl, onlyWithinUrl)) {
8024
+ if (!urlIsOrIsInsideOf(fileUrl, onlyWithinUrl)) {
8025
8025
  continue;
8026
8026
  }
8027
8027
  }
@@ -8545,7 +8545,7 @@ const memoize = (compute) => {
8545
8545
 
8546
8546
  const WEB_URL_CONVERTER = {
8547
8547
  asWebUrl: (fileUrl, webServer) => {
8548
- if (urlIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
8548
+ if (urlIsOrIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
8549
8549
  return moveUrl({
8550
8550
  url: fileUrl,
8551
8551
  from: webServer.rootDirectoryUrl,
@@ -8763,7 +8763,7 @@ const createRuntimeUsingPlaywright = ({
8763
8763
  coverageFileUrl,
8764
8764
  }) => {
8765
8765
  const fileUrl = new URL(fileRelativeUrl, rootDirectoryUrl).href;
8766
- if (!urlIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
8766
+ if (!urlIsOrIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
8767
8767
  throw new Error(`Cannot execute file that is outside web server root directory
8768
8768
  --- file ---
8769
8769
  ${fileUrl}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.7.5",
3
+ "version": "3.7.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@c88/v8-coverage": "0.1.1",
48
- "@jsenv/ast": "6.7.3",
49
- "@jsenv/plugin-supervisor": "1.7.1",
50
- "@jsenv/sourcemap": "1.3.8",
48
+ "@jsenv/ast": "6.7.6",
49
+ "@jsenv/plugin-supervisor": "1.7.3",
50
+ "@jsenv/sourcemap": "1.3.9",
51
51
  "he": "1.2.0",
52
52
  "istanbul-lib-coverage": "3.2.2",
53
53
  "istanbul-lib-instrument": "6.0.3",
@@ -27,7 +27,7 @@ import {
27
27
  startMonitoringMemoryUsage,
28
28
  } from "@jsenv/os-metrics";
29
29
  import { URL_META } from "@jsenv/url-meta";
30
- import { urlIsInsideOf } from "@jsenv/urls";
30
+ import { urlIsOrIsInsideOf } from "@jsenv/urls";
31
31
  import { existsSync } from "node:fs";
32
32
  import { takeCoverage } from "node:v8";
33
33
  import stripAnsi from "strip-ansi";
@@ -683,7 +683,7 @@ To fix this warning:
683
683
  for (const { relativeUrl, meta } of fileResultArray) {
684
684
  if (onlyWithinUrl) {
685
685
  const fileUrl = new URL(relativeUrl, rootDirectoryUrl).href;
686
- if (!urlIsInsideOf(fileUrl, onlyWithinUrl)) {
686
+ if (!urlIsOrIsInsideOf(fileUrl, onlyWithinUrl)) {
687
687
  continue;
688
688
  }
689
689
  }
@@ -1,4 +1,4 @@
1
- import { urlIsInsideOf, urlToRelativeUrl } from "@jsenv/urls";
1
+ import { urlIsOrIsInsideOf, urlToRelativeUrl } from "@jsenv/urls";
2
2
 
3
3
  export const githubAnnotationFromError = (
4
4
  error,
@@ -40,7 +40,7 @@ const asException = (error, { rootDirectoryUrl }) => {
40
40
  exception.stack = replaceUrls(
41
41
  error.stack,
42
42
  ({ match, url, line = 1, column = 1 }) => {
43
- if (urlIsInsideOf(url, rootDirectoryUrl)) {
43
+ if (urlIsOrIsInsideOf(url, rootDirectoryUrl)) {
44
44
  const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
45
45
  match = stringifyUrlSite({ url: relativeUrl, line, column });
46
46
  }
@@ -52,7 +52,7 @@ const asException = (error, { rootDirectoryUrl }) => {
52
52
  exception.stack = replaceUrls(
53
53
  error.stack,
54
54
  ({ match, url, line = 1, column = 1 }) => {
55
- if (urlIsInsideOf(url, rootDirectoryUrl)) {
55
+ if (urlIsOrIsInsideOf(url, rootDirectoryUrl)) {
56
56
  const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
57
57
  match = stringifyUrlSite({ url: relativeUrl, line, column });
58
58
  }
@@ -1,9 +1,9 @@
1
1
  import { ensureWindowsDriveLetter } from "@jsenv/filesystem";
2
- import { moveUrl, urlIsInsideOf } from "@jsenv/urls";
2
+ import { moveUrl, urlIsOrIsInsideOf } from "@jsenv/urls";
3
3
 
4
4
  export const WEB_URL_CONVERTER = {
5
5
  asWebUrl: (fileUrl, webServer) => {
6
- if (urlIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
6
+ if (urlIsOrIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
7
7
  return moveUrl({
8
8
  url: fileUrl,
9
9
  from: webServer.rootDirectoryUrl,
@@ -1,6 +1,6 @@
1
1
  import { Abort, raceCallbacks } from "@jsenv/abort";
2
2
  import { createDetailedMessage } from "@jsenv/humanize";
3
- import { urlIsInsideOf } from "@jsenv/urls";
3
+ import { urlIsOrIsInsideOf } from "@jsenv/urls";
4
4
  import { memoize } from "@jsenv/utils/src/memoize/memoize.js";
5
5
  import { readFileSync, writeFileSync } from "node:fs";
6
6
  import { composeTwoFileByFileIstanbulCoverages } from "../coverage/istanbul_coverage_composition.js";
@@ -57,7 +57,7 @@ export const createRuntimeUsingPlaywright = ({
57
57
  coverageFileUrl,
58
58
  }) => {
59
59
  const fileUrl = new URL(fileRelativeUrl, rootDirectoryUrl).href;
60
- if (!urlIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
60
+ if (!urlIsOrIsInsideOf(fileUrl, webServer.rootDirectoryUrl)) {
61
61
  throw new Error(`Cannot execute file that is outside web server root directory
62
62
  --- file ---
63
63
  ${fileUrl}