Skip to content

Commit 7dd752a

Browse files
committed
test: merge createLazyGenerator delegation tests to avoid ESM cache collision
1 parent a58774c commit 7dd752a

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/utils/__tests__/generators.test.mjs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,30 +153,23 @@ describe('createLazyGenerator', () => {
153153
assert.equal(gen.version, '1.0.0');
154154
});
155155

156-
it('exposes a generate function that delegates to the lazily loaded module', async () => {
157-
// The dynamic import inside createLazyGenerator resolves relative to generators.mjs
158-
// which is at src/utils/ so '../generators/ast/generate.mjs' → src/generators/ast/generate.mjs
156+
it('exposes generate and processChunk functions that delegate to the lazily loaded module', async () => {
157+
// Both exports are mocked in a single mock.module() call to avoid ESM import
158+
// cache collisions that occur when re-mocking the same specifier across two it() blocks.
159159
const specifier = import.meta.resolve('../../generators/ast/generate.mjs');
160160
const fakeGenerate = async input => `processed:${input}`;
161-
mock.module(specifier, {
162-
namedExports: { generate: fakeGenerate },
163-
});
164-
165-
const gen = createLazyGenerator({ name: 'ast' });
166-
const result = await gen.generate('hello');
167-
assert.equal(result, 'processed:hello');
168-
});
169-
170-
it('exposes a processChunk function that delegates to the lazily loaded module', async () => {
171-
const specifier = import.meta.resolve('../../generators/ast/generate.mjs');
172161
const fakeProcessChunk = async (input, indices) =>
173162
indices.map(i => input[i]);
174163
mock.module(specifier, {
175-
namedExports: { processChunk: fakeProcessChunk },
164+
namedExports: { generate: fakeGenerate, processChunk: fakeProcessChunk },
176165
});
177166

178167
const gen = createLazyGenerator({ name: 'ast' });
179-
const result = await gen.processChunk(['a', 'b', 'c'], [0, 2]);
180-
assert.deepStrictEqual(result, ['a', 'c']);
168+
169+
const generateResult = await gen.generate('hello');
170+
assert.equal(generateResult, 'processed:hello');
171+
172+
const processChunkResult = await gen.processChunk(['a', 'b', 'c'], [0, 2]);
173+
assert.deepStrictEqual(processChunkResult, ['a', 'c']);
181174
});
182175
});

0 commit comments

Comments
 (0)