Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b93c8a7

Browse filesBrowse files
Trotttargos
authored andcommitted
test: fix flaky doctool and test
Doctool tests have been failing a lot in CI on Win2008 R2. It appears async functions and callback-based functions are being used in combination such that the callback-based function cannot guarantee that it will invoke its callback. Convert the callback-based functions to async functions so we have one paradigm and reliable results. PR-URL: #29979 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent a23b5cb commit b93c8a7
Copy full SHA for b93c8a7

File tree

Expand file treeCollapse file tree

3 files changed

+19
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+19
-34
lines changed
Open diff view settings
Collapse file

‎test/doctool/test-doctool-html.js‎

Copy file name to clipboardExpand all lines: test/doctool/test-doctool-html.js
+11-21Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const remark2rehype = require('remark-rehype');
2222
const raw = require('rehype-raw');
2323
const htmlStringify = require('rehype-stringify');
2424

25-
function toHTML({ input, filename, nodeVersion }, cb) {
25+
async function toHTML({ input, filename, nodeVersion }) {
2626
const content = unified()
2727
.use(markdown)
2828
.use(html.firstHeader)
@@ -34,10 +34,7 @@ function toHTML({ input, filename, nodeVersion }, cb) {
3434
.use(htmlStringify)
3535
.processSync(input);
3636

37-
html.toHTML(
38-
{ input, content, filename, nodeVersion },
39-
cb
40-
);
37+
return html.toHTML({ input, content, filename, nodeVersion });
4138
}
4239

4340
// Test data is a list of objects with two properties.
@@ -107,23 +104,16 @@ testData.forEach(({ file, html }) => {
107104
// Normalize expected data by stripping whitespace.
108105
const expected = html.replace(spaces, '');
109106

110-
readFile(file, 'utf8', common.mustCall((err, input) => {
107+
readFile(file, 'utf8', common.mustCall(async (err, input) => {
111108
assert.ifError(err);
112-
toHTML(
113-
{
114-
input: input,
115-
filename: 'foo',
116-
nodeVersion: process.version,
117-
},
118-
common.mustCall((err, output) => {
119-
assert.ifError(err);
109+
const output = await toHTML({ input: input,
110+
filename: 'foo',
111+
nodeVersion: process.version });
120112

121-
const actual = output.replace(spaces, '');
122-
// Assert that the input stripped of all whitespace contains the
123-
// expected markup.
124-
assert(actual.includes(expected),
125-
`ACTUAL: ${actual}\nEXPECTED: ${expected}`);
126-
})
127-
);
113+
const actual = output.replace(spaces, '');
114+
// Assert that the input stripped of all whitespace contains the
115+
// expected markup.
116+
assert(actual.includes(expected),
117+
`ACTUAL: ${actual}\nEXPECTED: ${expected}`);
128118
}));
129119
});
Collapse file

‎tools/doc/generate.js‎

Copy file name to clipboardExpand all lines: tools/doc/generate.js
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if (!filename) {
6767
}
6868

6969

70-
fs.readFile(filename, 'utf8', (er, input) => {
70+
fs.readFile(filename, 'utf8', async (er, input) => {
7171
if (er) throw er;
7272

7373
const content = unified()
@@ -84,15 +84,10 @@ fs.readFile(filename, 'utf8', (er, input) => {
8484

8585
const basename = path.basename(filename, '.md');
8686

87-
html.toHTML(
88-
{ input, content, filename, nodeVersion },
89-
(err, html) => {
90-
const target = path.join(outputDir, `${basename}.html`);
91-
if (err) throw err;
92-
fs.writeFileSync(target, html);
93-
}
94-
);
87+
const myHtml = await html.toHTML({ input, content, filename, nodeVersion });
88+
const htmlTarget = path.join(outputDir, `${basename}.html`);
89+
fs.writeFileSync(htmlTarget, myHtml);
9590

96-
const target = path.join(outputDir, `${basename}.json`);
97-
fs.writeFileSync(target, JSON.stringify(content.json, null, 2));
91+
const jsonTarget = path.join(outputDir, `${basename}.json`);
92+
fs.writeFileSync(jsonTarget, JSON.stringify(content.json, null, 2));
9893
});
Collapse file

‎tools/doc/html.js‎

Copy file name to clipboardExpand all lines: tools/doc/html.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const gtocHTML = unified()
6363
const templatePath = path.join(docPath, 'template.html');
6464
const template = fs.readFileSync(templatePath, 'utf8');
6565

66-
async function toHTML({ input, content, filename, nodeVersion }, cb) {
66+
async function toHTML({ input, content, filename, nodeVersion }) {
6767
filename = path.basename(filename, '.md');
6868

6969
const id = filename.replace(/\W+/g, '-');
@@ -87,7 +87,7 @@ async function toHTML({ input, content, filename, nodeVersion }, cb) {
8787
HTML = HTML.replace('__ALTDOCS__', '');
8888
}
8989

90-
cb(null, HTML);
90+
return HTML;
9191
}
9292

9393
// Set the section name based on the first header. Default to 'Index'.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.