@@ -2,7 +2,6 @@ import { ok, strictEqual } from 'node:assert';
22import { describe , it } from 'node:test' ;
33
44import createGenerator from '../generators.mjs' ;
5- import { isAsyncGenerator } from '../streaming.mjs' ;
65
76describe ( 'createGenerator' , ( ) => {
87 // Simple mock input for testing
@@ -37,101 +36,115 @@ describe('createGenerator', () => {
3736 it ( 'should return the ast input directly when generators list is empty' , async ( ) => {
3837 const { runGenerators } = createGenerator ( mockInput ) ;
3938
40- const result = await runGenerators ( {
39+ const results = await runGenerators ( {
4140 ...mockOptions ,
4241 generators : [ 'ast' ] ,
4342 } ) ;
4443
45- // The 'ast' key should resolve to the original input
46- ok ( result ) ;
44+ // Returns array of results, first element is the 'ast' result
45+ ok ( Array . isArray ( results ) ) ;
46+ strictEqual ( results . length , 1 ) ;
47+ ok ( results [ 0 ] ) ;
4748 } ) ;
4849
4950 it ( 'should run metadata generator' , async ( ) => {
5051 const { runGenerators } = createGenerator ( mockInput ) ;
5152
52- const result = await runGenerators ( {
53+ const results = await runGenerators ( {
5354 ...mockOptions ,
5455 generators : [ 'metadata' ] ,
5556 } ) ;
5657
57- // metadata returns an async generator
58- ok ( isAsyncGenerator ( result ) ) ;
58+ // Returns array with one element - the collected metadata array
59+ ok ( Array . isArray ( results ) ) ;
60+ strictEqual ( results . length , 1 ) ;
61+ ok ( Array . isArray ( results [ 0 ] ) ) ;
5962 } ) ;
6063
6164 it ( 'should handle generator with dependency' , async ( ) => {
6265 const { runGenerators } = createGenerator ( mockInput ) ;
6366
6467 // legacy-html depends on metadata
65- const result = await runGenerators ( {
68+ const results = await runGenerators ( {
6669 ...mockOptions ,
6770 generators : [ 'legacy-html' ] ,
6871 } ) ;
6972
70- // Should complete without error
71- ok ( result !== undefined ) ;
73+ // Should complete without error - returns array of results
74+ ok ( Array . isArray ( results ) ) ;
75+ strictEqual ( results . length , 1 ) ;
7276 } ) ;
7377
7478 it ( 'should skip already scheduled generators' , async ( ) => {
7579 const { runGenerators } = createGenerator ( mockInput ) ;
7680
7781 // Running with ['metadata', 'metadata'] should skip the second
78- const result = await runGenerators ( {
82+ const results = await runGenerators ( {
7983 ...mockOptions ,
8084 generators : [ 'metadata' , 'metadata' ] ,
8185 } ) ;
8286
83- ok ( isAsyncGenerator ( result ) ) ;
87+ // Returns array with two elements (same result cached for both)
88+ ok ( Array . isArray ( results ) ) ;
89+ strictEqual ( results . length , 2 ) ;
8490 } ) ;
8591
8692 it ( 'should handle multiple generators in sequence' , async ( ) => {
8793 const { runGenerators } = createGenerator ( mockInput ) ;
8894
89- // Run metadata twice - the system should skip the already scheduled one
90- // Avoid json-simple since it writes to disk
91- const result = await runGenerators ( {
95+ // Run metadata - just one generator
96+ const results = await runGenerators ( {
9297 ...mockOptions ,
9398 generators : [ 'metadata' ] ,
9499 } ) ;
95100
96- // Result should be from the last generator
97- ok ( result !== undefined ) ;
101+ // Returns array of results
102+ ok ( Array . isArray ( results ) ) ;
103+ strictEqual ( results . length , 1 ) ;
98104 } ) ;
99105
100106 it ( 'should collect async generator results for dependents' , async ( ) => {
101107 const { runGenerators } = createGenerator ( mockInput ) ;
102108
103109 // legacy-json depends on metadata (async generator)
104- const result = await runGenerators ( {
110+ const results = await runGenerators ( {
105111 ...mockOptions ,
106112 generators : [ 'legacy-json' ] ,
107113 } ) ;
108114
109- ok ( result !== undefined ) ;
115+ ok ( Array . isArray ( results ) ) ;
116+ strictEqual ( results . length , 1 ) ;
110117 } ) ;
111118
112119 it ( 'should use multiple threads when specified' , async ( ) => {
113120 const { runGenerators } = createGenerator ( mockInput ) ;
114121
115- const result = await runGenerators ( {
122+ const results = await runGenerators ( {
116123 ...mockOptions ,
117124 threads : 4 ,
118125 generators : [ 'metadata' ] ,
119126 } ) ;
120127
121- ok ( isAsyncGenerator ( result ) ) ;
128+ // Returns array of results
129+ ok ( Array . isArray ( results ) ) ;
130+ strictEqual ( results . length , 1 ) ;
131+ ok ( Array . isArray ( results [ 0 ] ) ) ;
122132 } ) ;
123133
124134 it ( 'should pass options to generators' , async ( ) => {
125135 const { runGenerators } = createGenerator ( mockInput ) ;
126136
127137 const customTypeMap = { TestType : 'https://example.com/TestType' } ;
128138
129- const result = await runGenerators ( {
139+ const results = await runGenerators ( {
130140 ...mockOptions ,
131141 typeMap : customTypeMap ,
132142 generators : [ 'metadata' ] ,
133143 } ) ;
134144
135- ok ( isAsyncGenerator ( result ) ) ;
145+ // Returns array of results
146+ ok ( Array . isArray ( results ) ) ;
147+ strictEqual ( results . length , 1 ) ;
148+ ok ( Array . isArray ( results [ 0 ] ) ) ;
136149 } ) ;
137150} ) ;
0 commit comments