@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
22import { mkdtemp , readFile } from 'node:fs/promises' ;
33import { tmpdir } from 'node:os' ;
44import { join } from 'node:path' ;
5- import test from 'node:test' ;
5+ import { describe , it } from 'node:test' ;
66
77import { u } from 'unist-builder' ;
88
@@ -12,67 +12,72 @@ import {
1212 generateSectionFolderName ,
1313} from '../utils/section.mjs' ;
1414
15- test ( 'returns empty array when no code blocks match filename comment' , async ( ) => {
16- const entry = {
17- heading : { data : { name : 'Section A' } } ,
18- content : u ( 'root' , [ u ( 'code' , 'console.log("no filename header");' ) ] ) ,
19- } ;
20-
21- const result = await addon . generate ( [ entry ] , { } ) ;
22-
23- // No sections were buildable / no filenames extracted
24- assert . deepEqual ( result , [ ] ) ;
25- } ) ;
26-
27- test ( 'ignores non-buildable sections (needs both .cc and .js)' , async ( ) => {
28- // Only a .cc file present -> not buildable
29- const entry = {
30- heading : { data : { name : 'OnlyCC' } } ,
31- content : u ( 'root' , [ u ( 'code' , '// file1.cc\nint main() {}' ) ] ) ,
32- } ;
33-
34- const result = await addon . generate ( [ entry ] , { } ) ;
35-
36- assert . deepEqual ( result , [ ] ) ;
37- } ) ;
38-
39- test ( 'generates files array and writes files to disk when output provided' , async ( ) => {
40- const sectionName = 'My Addon Section' ;
41-
42- const entry = {
43- heading : { data : { name : sectionName } } ,
44- content : u ( 'root' , [
45- u ( 'code' , '// file1.cc\nint main() {}' ) ,
46- u (
47- 'code' ,
48- "// test.js\nmodule.exports = require('./build/Release/addon');"
49- ) ,
50- ] ) ,
51- } ;
52-
53- const tmp = await mkdtemp ( join ( tmpdir ( ) , 'doc-kit-' ) ) ;
54-
55- const returned = await addon . generate ( [ entry ] , { output : tmp } ) ;
56-
57- // Returned is an array of file arrays (one per section)
58- assert . equal ( Array . isArray ( returned ) , true ) ;
59- assert . equal ( returned . length , 1 ) ;
60-
61- const files = returned [ 0 ] ;
62-
63- assert . ok ( files . some ( f => f . name === 'file1.cc' ) ) ;
64- assert . ok ( files . some ( f => f . name === 'test.js' ) ) ;
65- assert . ok ( files . some ( f => f . name === 'binding.gyp' ) ) ;
66-
67- // Verify files were written to disk under the computed folder name
68- const folderName = generateSectionFolderName (
69- normalizeSectionName ( sectionName ) ,
70- 0
71- ) ;
72-
73- const file1 = await readFile ( join ( tmp , folderName , 'file1.cc' ) , 'utf-8' ) ;
74- const binding = await readFile ( join ( tmp , folderName , 'binding.gyp' ) , 'utf-8' ) ;
75-
76- assert . match ( file1 , / i n t m a i n / ) ;
77- assert . match ( binding , / t a r g e t s / ) ;
15+ describe ( 'generators/addon-verify' , ( ) => {
16+ it ( 'returns empty array when no code blocks match filename comment' , async ( ) => {
17+ const entry = {
18+ heading : { data : { name : 'Section A' } } ,
19+ content : u ( 'root' , [ u ( 'code' , 'console.log("no filename header");' ) ] ) ,
20+ } ;
21+
22+ const result = await addon . generate ( [ entry ] , { } ) ;
23+
24+ // No sections were buildable / no filenames extracted
25+ assert . deepEqual ( result , [ ] ) ;
26+ } ) ;
27+
28+ it ( 'ignores non-buildable sections (needs both .cc and .js)' , async ( ) => {
29+ // Only a .cc file present -> not buildable
30+ const entry = {
31+ heading : { data : { name : 'OnlyCC' } } ,
32+ content : u ( 'root' , [ u ( 'code' , '// file1.cc\nint main() {}' ) ] ) ,
33+ } ;
34+
35+ const result = await addon . generate ( [ entry ] , { } ) ;
36+
37+ assert . deepEqual ( result , [ ] ) ;
38+ } ) ;
39+
40+ it ( 'generates files array and writes files to disk when output provided' , async ( ) => {
41+ const sectionName = 'My Addon Section' ;
42+
43+ const entry = {
44+ heading : { data : { name : sectionName } } ,
45+ content : u ( 'root' , [
46+ u ( 'code' , '// file1.cc\nint main() {}' ) ,
47+ u (
48+ 'code' ,
49+ "// test.js\nmodule.exports = require('./build/Release/addon');"
50+ ) ,
51+ ] ) ,
52+ } ;
53+
54+ const tmp = await mkdtemp ( join ( tmpdir ( ) , 'doc-kit-' ) ) ;
55+
56+ const returned = await addon . generate ( [ entry ] , { output : tmp } ) ;
57+
58+ // Returned is an array of file arrays (one per section)
59+ assert . equal ( Array . isArray ( returned ) , true ) ;
60+ assert . equal ( returned . length , 1 ) ;
61+
62+ const files = returned [ 0 ] ;
63+
64+ assert . ok ( files . some ( f => f . name === 'file1.cc' ) ) ;
65+ assert . ok ( files . some ( f => f . name === 'test.js' ) ) ;
66+ assert . ok ( files . some ( f => f . name === 'binding.gyp' ) ) ;
67+
68+ // Verify files were written to disk under the computed folder name
69+ const folderName = generateSectionFolderName (
70+ normalizeSectionName ( sectionName ) ,
71+ 0
72+ ) ;
73+
74+ const file1 = await readFile ( join ( tmp , folderName , 'file1.cc' ) , 'utf-8' ) ;
75+ const binding = await readFile (
76+ join ( tmp , folderName , 'binding.gyp' ) ,
77+ 'utf-8'
78+ ) ;
79+
80+ assert . match ( file1 , / i n t m a i n / ) ;
81+ assert . match ( binding , / t a r g e t s / ) ;
82+ } ) ;
7883} ) ;
0 commit comments