Skip to content

Commit 1ea70d6

Browse files
TrottBethGriggs
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. Backport-PR-URL: #32642 PR-URL: #29979 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 0177464 commit 1ea70d6

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const remark2rehype = require('remark-rehype');
2222
constraw=require('rehype-raw');
2323
consthtmlStringify=require('rehype-stringify');
2424

25-
functiontoHTML({ input, filename, nodeVersion },cb){
25+
asyncfunctiontoHTML({ input, filename, nodeVersion }){
2626
constcontent=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+
returnhtml.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
constexpected=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+
constoutput=awaittoHTML({input: input,
110+
filename: 'foo',
111+
nodeVersion: process.version});
120112

121-
constactual=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+
constactual=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
});

‎tools/doc/generate.js‎

Lines 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)thrower;
7272

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

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

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

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

‎tools/doc/html.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const gtocHTML = unified()
6363
consttemplatePath=path.join(docPath,'template.html');
6464
consttemplate=fs.readFileSync(templatePath,'utf8');
6565

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

6969
constid=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+
returnHTML;
9191
}
9292

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

0 commit comments

Comments
(0)