@vendure-io/docs-provider 0.6.0 → 0.7.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/testing/test-manifest.d.ts +3 -1
- package/dist/testing/test-manifest.d.ts.map +1 -1
- package/dist/testing/types.d.ts +0 -5
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing.cjs +4 -4
- package/dist/testing.js +119 -120
- package/docs/mdx-testing.md +3 -17
- package/package.json +1 -1
|
@@ -7,6 +7,9 @@ import { MdxTestReport, TestManifestOptions } from './types';
|
|
|
7
7
|
* manifest's navigation tree and attempts to compile each MDX file using
|
|
8
8
|
* the same plugins as @apps/docs.
|
|
9
9
|
*
|
|
10
|
+
* Note: Manifests must contain absolute file paths. The function reads
|
|
11
|
+
* files directly from the paths specified in the navigation nodes.
|
|
12
|
+
*
|
|
10
13
|
* @param manifest - The documentation package manifest to test
|
|
11
14
|
* @param options - Optional configuration for testing
|
|
12
15
|
* @returns A report containing results for each file
|
|
@@ -17,7 +20,6 @@ import { MdxTestReport, TestManifestOptions } from './types';
|
|
|
17
20
|
* import { testManifestMdx, formatTestReport } from '@vendure-io/docs-provider/testing'
|
|
18
21
|
*
|
|
19
22
|
* const report = await testManifestMdx(manifest, {
|
|
20
|
-
* basePath: __dirname,
|
|
21
23
|
* onProgress: (current, total, result) => {
|
|
22
24
|
* console.log(`[${current}/${total}] ${result.success ? '✓' : '✗'} ${result.filePath}`)
|
|
23
25
|
* },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-manifest.d.ts","sourceRoot":"","sources":["../../src/testing/test-manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-manifest.d.ts","sourceRoot":"","sources":["../../src/testing/test-manifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAGnD,OAAO,KAAK,EAAwB,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,aAAa,CAAC,CA4ExB"}
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -37,11 +37,6 @@ export interface MdxTestReport {
|
|
|
37
37
|
* Options for testing a manifest's MDX files
|
|
38
38
|
*/
|
|
39
39
|
export interface TestManifestOptions {
|
|
40
|
-
/**
|
|
41
|
-
* Base path for resolving file paths.
|
|
42
|
-
* If not provided, uses the manifest's basePath or current working directory.
|
|
43
|
-
*/
|
|
44
|
-
basePath?: string;
|
|
45
40
|
/**
|
|
46
41
|
* Stop on first failure.
|
|
47
42
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAA;IAClB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,uCAAuC;IACvC,OAAO,EAAE,oBAAoB,EAAE,CAAA;IAC/B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAA;IAClB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,uCAAuC;IACvC,OAAO,EAAE,oBAAoB,EAAE,CAAA;IAC/B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAA;CACpF;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B"}
|
package/dist/testing.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
${
|
|
3
|
-
`)}function
|
|
4
|
-
`)}}exports.compileMdx=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@mdx-js/mdx"),F=require("rehype-slug"),w=require("remark-directive"),M=require("remark-gfm"),p=require("unist-util-visit"),x=require("fs/promises"),R=require("./manifest-D-EWZlSh.cjs"),$={info:"info",note:"note",tip:"tip",warning:"warning",caution:"caution",danger:"danger"},D={info:"Info",note:"Note",tip:"Tip",warning:"Warning",caution:"Caution",danger:"Danger"},I=()=>s=>{p.visit(s,"containerDirective",t=>{var a;const e=t.name.toLowerCase();if(!(e in $))return;const i=$[e];let r;if(t.children.length>0){const l=t.children[0];if(l.type==="paragraph"&&"data"in l&&((a=l.data)==null?void 0:a.directiveLabel)===!0){const u=[];for(const o of l.children)o.type==="text"&&u.push(o.value);u.length>0&&(r=u.join("")),t.children=t.children.slice(1)}}const n=r||D[e],c=t.data||(t.data={});c.hName="Callout",c.hProperties={type:i,title:n}})};function E(){return s=>{p.visit(s,"code",t=>{if(!t.meta)return;const e=t.meta.match(/(?:title|filename)=["']([^"']+)["']/);if(!e)return;const i=e[1];t.value.trim().startsWith("// filename:")||(t.value=`// filename: ${i}
|
|
2
|
+
${t.value}`)})}}const S=()=>s=>{const t=[];p.visit(s,"html",(e,i,r)=>{i!==void 0&&r&&typeof e.value=="string"&&e.value.trim().startsWith("<!--")&&e.value.trim().endsWith("-->")&&t.push(i)});for(const e of t.reverse())s.children.splice(e,1)},b=["@theme/Tabs","@theme/TabItem"],C=()=>s=>{const t=[];p.visit(s,"mdxjsEsm",e=>{const i=e.value;b.some(n=>i.includes(`from '${n}'`)||i.includes(`from "${n}"`))&&t.push(e)});for(const e of t){const i=s.children.indexOf(e);i!==-1&&s.children.splice(i,1)}};function v(){return[M,w,I,E,C,S]}function T(){return[F]}async function y(s,t,e){var c,a,l,u;const i=performance.now(),r=(e==null?void 0:e.remarkPlugins)??v(),n=(e==null?void 0:e.rehypePlugins)??T();try{return await k.compile(s,{remarkPlugins:r,rehypePlugins:n,outputFormat:"function-body",development:!1}),{filePath:t,success:!0,compilationTime:performance.now()-i}}catch(o){const f=performance.now()-i;let h="Unknown compilation error",d,g;if(o instanceof Error){h=o.message;const m=o;if(m.line!==void 0?d=m.line:((a=(c=m.position)==null?void 0:c.start)==null?void 0:a.line)!==void 0&&(d=m.position.start.line),m.column!==void 0?g=m.column:((u=(l=m.position)==null?void 0:l.start)==null?void 0:u.column)!==void 0&&(g=m.position.start.column),d===void 0){const P=h.match(/\((\d+):(\d+)\)/);P&&(d=parseInt(P[1],10),g=parseInt(P[2],10))}}return{filePath:t,success:!1,error:h,line:d,column:g,compilationTime:f}}}async function L(s,t){const e=performance.now(),i=R.getLeafNodes(s),r=[];let n=0,c=0;for(let a=0;a<i.length;a++){const l=i[a];if(!l.file)continue;const u=l.file;try{const o=await x.readFile(u,"utf-8"),f=await y(o,l.file,{remarkPlugins:t==null?void 0:t.remarkPlugins,rehypePlugins:t==null?void 0:t.rehypePlugins});if(r.push(f),f.success?n++:c++,t!=null&&t.onProgress&&t.onProgress(a+1,i.length,f),t!=null&&t.failFast&&!f.success)break}catch(o){const f=o instanceof Error?o.message:"Unknown error reading file",h={filePath:l.file,success:!1,error:`Failed to read file: ${f}`,compilationTime:0};if(r.push(h),c++,t!=null&&t.onProgress&&t.onProgress(a+1,i.length,h),t!=null&&t.failFast)break}}return{packageId:s.id,totalFiles:r.length,passed:n,failed:c,results:r,totalTime:performance.now()-e}}function q(s,t=!1){const e=[];e.push(""),e.push(`MDX Compilation Report: ${s.packageId}`),e.push("=".repeat(50)),e.push("");const i=s.totalFiles>0?(s.passed/s.totalFiles*100).toFixed(1):"0";if(e.push(`Total files: ${s.totalFiles}`),e.push(`Passed: ${s.passed} (${i}%)`),e.push(`Failed: ${s.failed}`),e.push(`Total time: ${s.totalTime.toFixed(2)}ms`),e.push(""),t){e.push("Results:"),e.push("-".repeat(50));for(const r of s.results){const n=r.success?"[PASS]":"[FAIL]",c=`(${r.compilationTime.toFixed(2)}ms)`;if(e.push(`${n} ${r.filePath} ${c}`),!r.success&&r.error){const a=r.line?` (line ${r.line}${r.column?`:${r.column}`:""})`:"";e.push(` Error${a}: ${r.error}`)}}}else if(s.failed>0){e.push("Failures:"),e.push("-".repeat(50));for(const r of s.results.filter(n=>!n.success))if(e.push(`[FAIL] ${r.filePath}`),r.error){const n=r.line?` (line ${r.line}${r.column?`:${r.column}`:""})`:"";e.push(` Error${n}: ${r.error}`)}}return e.push(""),s.failed===0?e.push("All MDX files compiled successfully!"):e.push(`${s.failed} file(s) failed to compile.`),e.push(""),e.join(`
|
|
3
|
+
`)}function A(){return(s,t,e)=>{const i=e.success?"✓":"✗",r=(s/t*100).toFixed(0);process.stdout.write(`\r[${s}/${t}] (${r}%) ${i} ${e.filePath}`),process.stdout.write("\x1B[K"),s===t&&process.stdout.write(`
|
|
4
|
+
`)}}exports.compileMdx=y;exports.createProgressReporter=A;exports.formatTestReport=q;exports.getDefaultRehypePlugins=T;exports.getDefaultRemarkPlugins=v;exports.testManifestMdx=L;
|
package/dist/testing.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { compile as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { compile as T } from "@mdx-js/mdx";
|
|
2
|
+
import v from "rehype-slug";
|
|
3
|
+
import F from "remark-directive";
|
|
4
|
+
import k from "remark-gfm";
|
|
5
5
|
import { visit as g } from "unist-util-visit";
|
|
6
|
-
import { readFile as
|
|
7
|
-
import {
|
|
8
|
-
import { h as I } from "./manifest-ZCrzbFSf.js";
|
|
6
|
+
import { readFile as w } from "fs/promises";
|
|
7
|
+
import { h as y } from "./manifest-ZCrzbFSf.js";
|
|
9
8
|
const P = {
|
|
10
9
|
info: "info",
|
|
11
10
|
note: "note",
|
|
@@ -13,190 +12,190 @@ const P = {
|
|
|
13
12
|
warning: "warning",
|
|
14
13
|
caution: "caution",
|
|
15
14
|
danger: "danger"
|
|
16
|
-
},
|
|
15
|
+
}, x = {
|
|
17
16
|
info: "Info",
|
|
18
17
|
note: "Note",
|
|
19
18
|
tip: "Tip",
|
|
20
19
|
warning: "Warning",
|
|
21
20
|
caution: "Caution",
|
|
22
21
|
danger: "Danger"
|
|
23
|
-
},
|
|
24
|
-
g(r, "containerDirective", (
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
if (!(
|
|
22
|
+
}, I = () => (r) => {
|
|
23
|
+
g(r, "containerDirective", (t) => {
|
|
24
|
+
var a;
|
|
25
|
+
const e = t.name.toLowerCase();
|
|
26
|
+
if (!(e in P))
|
|
28
27
|
return;
|
|
29
|
-
const i = P[
|
|
28
|
+
const i = P[e];
|
|
30
29
|
let s;
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
const
|
|
35
|
-
for (const
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (t.children.length > 0) {
|
|
31
|
+
const l = t.children[0];
|
|
32
|
+
if (l.type === "paragraph" && "data" in l && ((a = l.data) == null ? void 0 : a.directiveLabel) === !0) {
|
|
33
|
+
const u = [];
|
|
34
|
+
for (const o of l.children)
|
|
35
|
+
o.type === "text" && u.push(o.value);
|
|
36
|
+
u.length > 0 && (s = u.join("")), t.children = t.children.slice(1);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
39
|
+
const n = s || x[e], c = t.data || (t.data = {});
|
|
40
|
+
c.hName = "Callout", c.hProperties = {
|
|
42
41
|
type: i,
|
|
43
|
-
title:
|
|
42
|
+
title: n
|
|
44
43
|
};
|
|
45
44
|
});
|
|
46
45
|
};
|
|
47
|
-
function
|
|
46
|
+
function E() {
|
|
48
47
|
return (r) => {
|
|
49
|
-
g(r, "code", (
|
|
50
|
-
if (!
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
53
|
-
const i =
|
|
54
|
-
|
|
55
|
-
${
|
|
48
|
+
g(r, "code", (t) => {
|
|
49
|
+
if (!t.meta) return;
|
|
50
|
+
const e = t.meta.match(/(?:title|filename)=["']([^"']+)["']/);
|
|
51
|
+
if (!e) return;
|
|
52
|
+
const i = e[1];
|
|
53
|
+
t.value.trim().startsWith("// filename:") || (t.value = `// filename: ${i}
|
|
54
|
+
${t.value}`);
|
|
56
55
|
});
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
g(r, "html", (
|
|
62
|
-
i !== void 0 && s && typeof
|
|
58
|
+
const M = () => (r) => {
|
|
59
|
+
const t = [];
|
|
60
|
+
g(r, "html", (e, i, s) => {
|
|
61
|
+
i !== void 0 && s && typeof e.value == "string" && e.value.trim().startsWith("<!--") && e.value.trim().endsWith("-->") && t.push(i);
|
|
63
62
|
});
|
|
64
|
-
for (const
|
|
65
|
-
r.children.splice(
|
|
66
|
-
},
|
|
67
|
-
const
|
|
68
|
-
g(r, "mdxjsEsm", (
|
|
69
|
-
const i =
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
) &&
|
|
63
|
+
for (const e of t.reverse())
|
|
64
|
+
r.children.splice(e, 1);
|
|
65
|
+
}, D = ["@theme/Tabs", "@theme/TabItem"], R = () => (r) => {
|
|
66
|
+
const t = [];
|
|
67
|
+
g(r, "mdxjsEsm", (e) => {
|
|
68
|
+
const i = e.value;
|
|
69
|
+
D.some(
|
|
70
|
+
(n) => i.includes(`from '${n}'`) || i.includes(`from "${n}"`)
|
|
71
|
+
) && t.push(e);
|
|
73
72
|
});
|
|
74
|
-
for (const
|
|
75
|
-
const i = r.children.indexOf(
|
|
73
|
+
for (const e of t) {
|
|
74
|
+
const i = r.children.indexOf(e);
|
|
76
75
|
i !== -1 && r.children.splice(i, 1);
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
|
-
function
|
|
78
|
+
function S() {
|
|
80
79
|
return [
|
|
80
|
+
k,
|
|
81
81
|
F,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
R
|
|
82
|
+
I,
|
|
83
|
+
E,
|
|
84
|
+
R,
|
|
85
|
+
M
|
|
87
86
|
];
|
|
88
87
|
}
|
|
89
|
-
function
|
|
90
|
-
return [
|
|
88
|
+
function C() {
|
|
89
|
+
return [v];
|
|
91
90
|
}
|
|
92
|
-
async function
|
|
93
|
-
var
|
|
94
|
-
const i = performance.now(), s = (
|
|
91
|
+
async function L(r, t, e) {
|
|
92
|
+
var c, a, l, u;
|
|
93
|
+
const i = performance.now(), s = (e == null ? void 0 : e.remarkPlugins) ?? S(), n = (e == null ? void 0 : e.rehypePlugins) ?? C();
|
|
95
94
|
try {
|
|
96
|
-
return await
|
|
95
|
+
return await T(r, {
|
|
97
96
|
remarkPlugins: s,
|
|
98
|
-
rehypePlugins:
|
|
97
|
+
rehypePlugins: n,
|
|
99
98
|
// Don't output to JS, just compile to check for errors
|
|
100
99
|
outputFormat: "function-body",
|
|
101
100
|
// Suppress development warnings about missing 'development' option
|
|
102
101
|
development: !1
|
|
103
102
|
}), {
|
|
104
|
-
filePath:
|
|
103
|
+
filePath: t,
|
|
105
104
|
success: !0,
|
|
106
105
|
compilationTime: performance.now() - i
|
|
107
106
|
};
|
|
108
|
-
} catch (
|
|
109
|
-
const
|
|
110
|
-
let
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
const $ =
|
|
116
|
-
$ && (
|
|
107
|
+
} catch (o) {
|
|
108
|
+
const f = performance.now() - i;
|
|
109
|
+
let h = "Unknown compilation error", d, p;
|
|
110
|
+
if (o instanceof Error) {
|
|
111
|
+
h = o.message;
|
|
112
|
+
const m = o;
|
|
113
|
+
if (m.line !== void 0 ? d = m.line : ((a = (c = m.position) == null ? void 0 : c.start) == null ? void 0 : a.line) !== void 0 && (d = m.position.start.line), m.column !== void 0 ? p = m.column : ((u = (l = m.position) == null ? void 0 : l.start) == null ? void 0 : u.column) !== void 0 && (p = m.position.start.column), d === void 0) {
|
|
114
|
+
const $ = h.match(/\((\d+):(\d+)\)/);
|
|
115
|
+
$ && (d = parseInt($[1], 10), p = parseInt($[2], 10));
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
return {
|
|
120
|
-
filePath:
|
|
119
|
+
filePath: t,
|
|
121
120
|
success: !1,
|
|
122
|
-
error:
|
|
123
|
-
line:
|
|
121
|
+
error: h,
|
|
122
|
+
line: d,
|
|
124
123
|
column: p,
|
|
125
|
-
compilationTime:
|
|
124
|
+
compilationTime: f
|
|
126
125
|
};
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
|
-
async function
|
|
130
|
-
const
|
|
131
|
-
let
|
|
132
|
-
for (let
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
128
|
+
async function O(r, t) {
|
|
129
|
+
const e = performance.now(), i = y(r), s = [];
|
|
130
|
+
let n = 0, c = 0;
|
|
131
|
+
for (let a = 0; a < i.length; a++) {
|
|
132
|
+
const l = i[a];
|
|
133
|
+
if (!l.file)
|
|
135
134
|
continue;
|
|
136
|
-
const
|
|
135
|
+
const u = l.file;
|
|
137
136
|
try {
|
|
138
|
-
const
|
|
139
|
-
remarkPlugins:
|
|
140
|
-
rehypePlugins:
|
|
137
|
+
const o = await w(u, "utf-8"), f = await L(o, l.file, {
|
|
138
|
+
remarkPlugins: t == null ? void 0 : t.remarkPlugins,
|
|
139
|
+
rehypePlugins: t == null ? void 0 : t.rehypePlugins
|
|
141
140
|
});
|
|
142
|
-
if (
|
|
141
|
+
if (s.push(f), f.success ? n++ : c++, t != null && t.onProgress && t.onProgress(a + 1, i.length, f), t != null && t.failFast && !f.success)
|
|
143
142
|
break;
|
|
144
|
-
} catch (
|
|
145
|
-
const
|
|
146
|
-
filePath:
|
|
143
|
+
} catch (o) {
|
|
144
|
+
const f = o instanceof Error ? o.message : "Unknown error reading file", h = {
|
|
145
|
+
filePath: l.file,
|
|
147
146
|
success: !1,
|
|
148
|
-
error: `Failed to read file: ${
|
|
147
|
+
error: `Failed to read file: ${f}`,
|
|
149
148
|
compilationTime: 0
|
|
150
149
|
};
|
|
151
|
-
if (
|
|
150
|
+
if (s.push(h), c++, t != null && t.onProgress && t.onProgress(a + 1, i.length, h), t != null && t.failFast)
|
|
152
151
|
break;
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
154
|
return {
|
|
156
155
|
packageId: r.id,
|
|
157
|
-
totalFiles:
|
|
158
|
-
passed:
|
|
159
|
-
failed:
|
|
160
|
-
results:
|
|
161
|
-
totalTime: performance.now() -
|
|
156
|
+
totalFiles: s.length,
|
|
157
|
+
passed: n,
|
|
158
|
+
failed: c,
|
|
159
|
+
results: s,
|
|
160
|
+
totalTime: performance.now() - e
|
|
162
161
|
};
|
|
163
162
|
}
|
|
164
|
-
function
|
|
165
|
-
const
|
|
166
|
-
|
|
163
|
+
function X(r, t = !1) {
|
|
164
|
+
const e = [];
|
|
165
|
+
e.push(""), e.push(`MDX Compilation Report: ${r.packageId}`), e.push("=".repeat(50)), e.push("");
|
|
167
166
|
const i = r.totalFiles > 0 ? (r.passed / r.totalFiles * 100).toFixed(1) : "0";
|
|
168
|
-
if (
|
|
169
|
-
|
|
167
|
+
if (e.push(`Total files: ${r.totalFiles}`), e.push(`Passed: ${r.passed} (${i}%)`), e.push(`Failed: ${r.failed}`), e.push(`Total time: ${r.totalTime.toFixed(2)}ms`), e.push(""), t) {
|
|
168
|
+
e.push("Results:"), e.push("-".repeat(50));
|
|
170
169
|
for (const s of r.results) {
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
const
|
|
174
|
-
|
|
170
|
+
const n = s.success ? "[PASS]" : "[FAIL]", c = `(${s.compilationTime.toFixed(2)}ms)`;
|
|
171
|
+
if (e.push(`${n} ${s.filePath} ${c}`), !s.success && s.error) {
|
|
172
|
+
const a = s.line ? ` (line ${s.line}${s.column ? `:${s.column}` : ""})` : "";
|
|
173
|
+
e.push(` Error${a}: ${s.error}`);
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
} else if (r.failed > 0) {
|
|
178
|
-
|
|
179
|
-
for (const s of r.results.filter((
|
|
180
|
-
if (
|
|
181
|
-
const
|
|
182
|
-
|
|
177
|
+
e.push("Failures:"), e.push("-".repeat(50));
|
|
178
|
+
for (const s of r.results.filter((n) => !n.success))
|
|
179
|
+
if (e.push(`[FAIL] ${s.filePath}`), s.error) {
|
|
180
|
+
const n = s.line ? ` (line ${s.line}${s.column ? `:${s.column}` : ""})` : "";
|
|
181
|
+
e.push(` Error${n}: ${s.error}`);
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
|
-
return
|
|
184
|
+
return e.push(""), r.failed === 0 ? e.push("All MDX files compiled successfully!") : e.push(`${r.failed} file(s) failed to compile.`), e.push(""), e.join(`
|
|
186
185
|
`);
|
|
187
186
|
}
|
|
188
|
-
function
|
|
189
|
-
return (r,
|
|
190
|
-
const i =
|
|
191
|
-
process.stdout.write(`\r[${r}/${
|
|
187
|
+
function B() {
|
|
188
|
+
return (r, t, e) => {
|
|
189
|
+
const i = e.success ? "✓" : "✗", s = (r / t * 100).toFixed(0);
|
|
190
|
+
process.stdout.write(`\r[${r}/${t}] (${s}%) ${i} ${e.filePath}`), process.stdout.write("\x1B[K"), r === t && process.stdout.write(`
|
|
192
191
|
`);
|
|
193
192
|
};
|
|
194
193
|
}
|
|
195
194
|
export {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
L as compileMdx,
|
|
196
|
+
B as createProgressReporter,
|
|
197
|
+
X as formatTestReport,
|
|
198
|
+
C as getDefaultRehypePlugins,
|
|
199
|
+
S as getDefaultRemarkPlugins,
|
|
200
|
+
O as testManifestMdx
|
|
202
201
|
};
|
package/docs/mdx-testing.md
CHANGED
|
@@ -36,9 +36,7 @@ import { manifest } from './src/manifest'
|
|
|
36
36
|
import { testManifestMdx, formatTestReport } from '@vendure-io/docs-provider/testing'
|
|
37
37
|
|
|
38
38
|
async function main() {
|
|
39
|
-
const report = await testManifestMdx(manifest
|
|
40
|
-
basePath: __dirname,
|
|
41
|
-
})
|
|
39
|
+
const report = await testManifestMdx(manifest)
|
|
42
40
|
|
|
43
41
|
console.log(formatTestReport(report))
|
|
44
42
|
process.exit(report.failed > 0 ? 1 : 0)
|
|
@@ -85,14 +83,13 @@ async function testManifestMdx(
|
|
|
85
83
|
|
|
86
84
|
**Parameters:**
|
|
87
85
|
|
|
88
|
-
- `manifest` - The documentation package manifest to test
|
|
86
|
+
- `manifest` - The documentation package manifest to test (must contain absolute file paths)
|
|
89
87
|
- `options` - Optional configuration (see below)
|
|
90
88
|
|
|
91
89
|
**Options:**
|
|
92
90
|
|
|
93
91
|
| Option | Type | Default | Description |
|
|
94
92
|
|--------|------|---------|-------------|
|
|
95
|
-
| `basePath` | `string` | `manifest.basePath` or `cwd()` | Base path for resolving file paths |
|
|
96
93
|
| `failFast` | `boolean` | `false` | Stop on first failure |
|
|
97
94
|
| `remarkPlugins` | `PluggableList` | Default plugins | Custom remark plugins |
|
|
98
95
|
| `rehypePlugins` | `PluggableList` | Default plugins | Custom rehype plugins |
|
|
@@ -102,7 +99,6 @@ async function testManifestMdx(
|
|
|
102
99
|
|
|
103
100
|
```typescript
|
|
104
101
|
const report = await testManifestMdx(manifest, {
|
|
105
|
-
basePath: __dirname,
|
|
106
102
|
onProgress: (current, total, result) => {
|
|
107
103
|
const status = result.success ? '✓' : '✗'
|
|
108
104
|
console.log(`[${current}/${total}] ${status} ${result.filePath}`)
|
|
@@ -200,7 +196,6 @@ function createProgressReporter(): (
|
|
|
200
196
|
import { testManifestMdx, createProgressReporter } from '@vendure-io/docs-provider/testing'
|
|
201
197
|
|
|
202
198
|
const report = await testManifestMdx(manifest, {
|
|
203
|
-
basePath: __dirname,
|
|
204
199
|
onProgress: createProgressReporter(),
|
|
205
200
|
})
|
|
206
201
|
```
|
|
@@ -225,7 +220,6 @@ import {
|
|
|
225
220
|
import myCustomPlugin from './my-plugin'
|
|
226
221
|
|
|
227
222
|
const report = await testManifestMdx(manifest, {
|
|
228
|
-
basePath: __dirname,
|
|
229
223
|
remarkPlugins: [...getDefaultRemarkPlugins(), myCustomPlugin],
|
|
230
224
|
rehypePlugins: getDefaultRehypePlugins(),
|
|
231
225
|
})
|
|
@@ -283,9 +277,7 @@ import { testManifestMdx } from '@vendure-io/docs-provider/testing'
|
|
|
283
277
|
|
|
284
278
|
describe('MDX Compilation', () => {
|
|
285
279
|
it('should compile all MDX files without errors', async () => {
|
|
286
|
-
const report = await testManifestMdx(manifest
|
|
287
|
-
basePath: __dirname + '/..',
|
|
288
|
-
})
|
|
280
|
+
const report = await testManifestMdx(manifest)
|
|
289
281
|
|
|
290
282
|
expect(report.failed).toBe(0)
|
|
291
283
|
}, 30000) // Increase timeout for large doc sets
|
|
@@ -392,8 +384,6 @@ Here's a complete test script with all features:
|
|
|
392
384
|
|
|
393
385
|
```typescript
|
|
394
386
|
// scripts/test-mdx.ts
|
|
395
|
-
import { dirname, join } from 'path'
|
|
396
|
-
import { fileURLToPath } from 'url'
|
|
397
387
|
import { manifest } from '../src/manifest'
|
|
398
388
|
import {
|
|
399
389
|
testManifestMdx,
|
|
@@ -401,14 +391,10 @@ import {
|
|
|
401
391
|
createProgressReporter,
|
|
402
392
|
} from '@vendure-io/docs-provider/testing'
|
|
403
393
|
|
|
404
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
405
|
-
const projectRoot = join(__dirname, '..')
|
|
406
|
-
|
|
407
394
|
async function main() {
|
|
408
395
|
console.log('Testing MDX files...\n')
|
|
409
396
|
|
|
410
397
|
const report = await testManifestMdx(manifest, {
|
|
411
|
-
basePath: projectRoot,
|
|
412
398
|
onProgress: createProgressReporter(),
|
|
413
399
|
})
|
|
414
400
|
|