@markedjs/testutils 9.1.0-0 → 9.1.0-1

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/README.md CHANGED
@@ -1,3 +1,96 @@
1
1
  # @markedjs/testutils
2
2
 
3
3
  Test utilities for marked and marked extensions
4
+
5
+ ## API
6
+
7
+ ### `getAllMarkedSpecTests()`
8
+
9
+ Get all marked [Tests](#tests)
10
+
11
+ ### `getTests(dirs)`
12
+
13
+ Get [Tests](#tests) from a directory or file.
14
+ `dirs` can be a string, an array of strings, or an object with string values.
15
+ The return type is the same as the input a Tests object, an array of Tests objects, or an object with Tests object values.
16
+
17
+ ### `htmlIsEqual(actual, expected)`
18
+
19
+ Check if html will display the same.
20
+
21
+ ### `firstDiff(actual, expected, padding)`
22
+
23
+ Get the first difference between actual and expected HTML. Returns an object with the characters around the index of the first difference in the expected and actual strings.
24
+
25
+ ### `outputCompletionTable(title, tests)`
26
+
27
+ Display a table in stdout that lists the sections and what percentage of the tests are not marked shouldFail.
28
+
29
+ ### `runTests({tests, defaultMarkedOptions, parse, addExtension, isEqual, diff})`
30
+
31
+ Run spec tests
32
+
33
+ ### `runAllMarkedSpecTests({addExtension, outputCompletionTables})`
34
+
35
+ Run all marked specs with an added extension and optionally output completion table.
36
+
37
+ ## Arguments
38
+
39
+ ### tests
40
+
41
+ ```ts
42
+ interface Tests {
43
+ total: number;
44
+ pass: number;
45
+ specs: Spec[];
46
+ }
47
+
48
+ interface Spec {
49
+ section?: string;
50
+ markdown: string;
51
+ html: string;
52
+ example?: number;
53
+ options?: MarkedOptions;
54
+ only?: boolean;
55
+ skip?: boolean;
56
+ shouldFail?: boolean;
57
+ }
58
+ ```
59
+
60
+ ### defaultMarkedOptions
61
+
62
+ ```ts
63
+ type defaultMarkedOptions = MarkedOptions;
64
+ ```
65
+
66
+ ### parse
67
+
68
+ ```ts
69
+ function parse(
70
+ markdown: string,
71
+ options: MarkedOptions,
72
+ addExtension: addExtension,
73
+ ): string;
74
+ ```
75
+
76
+ ### addExtension
77
+
78
+ ```ts
79
+ function addExtension(marked: Marked): void;
80
+ ```
81
+
82
+ ### isEqual
83
+
84
+ ```ts
85
+ function isEqual(actual: string, expected: string): boolean;
86
+ ```
87
+
88
+ ### diff
89
+
90
+ ```ts
91
+ function diff(
92
+ actual: string,
93
+ expected: string,
94
+ padding: number,
95
+ ): { expected: string; actual: string };
96
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markedjs/testutils",
3
- "version": "9.1.0-0",
3
+ "version": "9.1.0-1",
4
4
  "description": "Test utilities for marked and marked extensions",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/get-tests.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { loadTests } from "./load-tests.js";
2
2
  import { resolvePath } from "./helpers.js";
3
3
 
4
+ /**
5
+ * Get tests from a directory or file
6
+ * @param {string | [string] | {key: string}} dirs Can be a string, array of strings, or an object with string values
7
+ * @returns {Tests | [Tests] | {key: Tests}} The return type will match the input, a tests object, array of tests objects, or an object with tests objects values
8
+ */
4
9
  export async function getTests(dirs) {
5
10
  if (typeof dirs === "string") {
6
11
  return await loadTests(dirs);
@@ -20,6 +25,16 @@ export async function getTests(dirs) {
20
25
  return testsObj;
21
26
  }
22
27
 
28
+ /**
29
+ * Get all marked tests
30
+ * @returns {{
31
+ * CommonMark: Tests,
32
+ * GFM: Tests,
33
+ * New: Tests,
34
+ * Original: Tests,
35
+ * ReDOS: Tests,
36
+ * }} All marked spec tests
37
+ */
23
38
  export async function getAllMarkedSpecTests() {
24
39
  return await getTests({
25
40
  CommonMark: resolvePath(
@@ -5,7 +5,26 @@ const htmlDiffer = new HtmlDiffer({
5
5
  ignoreComments: false,
6
6
  });
7
7
 
8
- export const htmlIsEqual = htmlDiffer.isEqual.bind(htmlDiffer);
8
+ /**
9
+ * Check if html will display the same
10
+ * @param {string} actual The actual HTML
11
+ * @param {string} expected The expected HTML
12
+ * @returns {boolean} HTML is the same
13
+ */
14
+ export function htmlIsEqual(actual, expected) {
15
+ return htmlDiffer.isEqual(actual, expected);
16
+ }
17
+
18
+ /**
19
+ * Get the first difference between actual and expected HTML
20
+ * @param {string} actual The actual HTML
21
+ * @param {string} expected The expected HTML
22
+ * @param {number} padding The number of characters to show around the first difference
23
+ * @returns {{
24
+ * actual: string,
25
+ * expected: string,
26
+ * }} An object with the characters around the index of the first difference in the expected and actual strings
27
+ */
9
28
  export async function firstDiff(actual, expected, padding) {
10
29
  padding = padding || 30;
11
30
  const diffHtml = await htmlDiffer.diffHtml(actual, expected);
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Display a table in stdout that lists the sections and what percentage of the tests are not marked shouldFail
3
+ * @param {string} title The title to display above the table
4
+ * @param {Tests} tests The tests to display a table for
5
+ */
1
6
  export function outputCompletionTable(title, tests) {
2
7
  let longestName = 0;
3
8
  let maxTests = 0;
package/src/run-tests.js CHANGED
@@ -5,6 +5,17 @@ import assert from "node:assert";
5
5
  import { Marked } from "marked";
6
6
  import { outputCompletionTable } from "./output-table.js";
7
7
 
8
+ /**
9
+ * Run spec tests
10
+ * @param {{
11
+ * tests: Tests
12
+ * defaultMarkedOptions: MarkedOptions,
13
+ * parse: (marked: Marked, options: MarkedOptions, addExtension: (marked: Marked) => void) => string,
14
+ * addExtension: (marked: Marked) => void,
15
+ * isEqual: (actual: string, expected: string) => boolean,
16
+ * diff: (actual: string, expected: string, padding: number) => {firstDiff: number, actual: string, expected: string},
17
+ * }} options
18
+ */
8
19
  export async function runTests({
9
20
  tests = {},
10
21
  defaultMarkedOptions = {},
@@ -71,6 +82,13 @@ export async function runTests({
71
82
  }
72
83
  }
73
84
 
85
+ /**
86
+ * Run all marked specs with an added extension and optionally output completion table
87
+ * @param {{
88
+ * addExtension: (marked: Marked) => void,
89
+ * outputCompletionTable: boolean,
90
+ * }} options
91
+ */
74
92
  export async function runAllMarkedSpecTests({
75
93
  addExtension = () => {},
76
94
  outputCompletionTables = true,
package/types/index.d.ts CHANGED
@@ -0,0 +1,18 @@
1
+ import type { MarkedOptions } from "marked";
2
+
3
+ export interface Spec {
4
+ section?: string;
5
+ markdown: string;
6
+ html: string;
7
+ example?: number;
8
+ options?: MarkedOptions;
9
+ only?: boolean;
10
+ skip?: boolean;
11
+ shouldFail?: boolean;
12
+ }
13
+
14
+ export interface Tests {
15
+ total: number;
16
+ pass: number;
17
+ specs: Spec[];
18
+ }