Skip to content

Commit 8583532

Browse files
committed
test(fmt): avoid mocking native matcher prototype
1 parent cf1bc97 commit 8583532

1 file changed

Lines changed: 6 additions & 25 deletions

File tree

‎packages/rstack/tests/fmt/discoverPaths.test.ts‎

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { symlinkSync } from 'node:fs';
22
import path from 'node:path';
33
import { expect, rs, test } from 'rstack/test';
44
import { discoverFmtPaths } from '../../src/fmt/discoverPaths.ts';
5-
import { loadNativeBinding } from '../../src/native/index.ts';
5+
import * as nativeBinding from '../../src/native/index.ts';
66
import { withTempProject, writeProjectFile } from './helpers.ts';
77

88
const relativePaths = (rootPath: string, files: string[]): string[] =>
@@ -166,40 +166,21 @@ test('keeps valid nested gitignore rules around normalized and malformed lines',
166166
});
167167
});
168168

169-
test.sequential('propagates errors while loading a nested gitignore', async () => {
169+
test('propagates native binding errors while loading a nested gitignore', async () => {
170170
await withTempProject(async (rootPath) => {
171171
writeProjectFile(rootPath, 'src/.gitignore', '*.js\n');
172172
writeProjectFile(rootPath, 'src/index.js');
173-
const nativeError = new Error('Failed to add nested gitignore source');
174-
const addSource = rs
175-
.spyOn(loadNativeBinding().GitIgnoreMatcher.prototype, 'addSource')
173+
const nativeError = new Error('Failed to load native binding');
174+
const loadNativeBinding = rs
175+
.spyOn(nativeBinding, 'loadNativeBinding')
176176
.mockImplementation(() => {
177177
throw nativeError;
178178
});
179179

180180
try {
181181
await expect(discoverFmtPaths({ cwd: rootPath })).rejects.toBe(nativeError);
182182
} finally {
183-
addSource.mockRestore();
184-
}
185-
});
186-
});
187-
188-
test.sequential('propagates errors from batched native gitignore matching', async () => {
189-
await withTempProject(async (rootPath) => {
190-
writeProjectFile(rootPath, '.gitignore', '*.js\n');
191-
writeProjectFile(rootPath, 'index.js');
192-
const nativeError = new Error('Failed to match gitignore entries');
193-
const matchBatch = rs
194-
.spyOn(loadNativeBinding().GitIgnoreMatcher.prototype, 'isIgnoredBatchMask')
195-
.mockImplementation(() => {
196-
throw nativeError;
197-
});
198-
199-
try {
200-
await expect(discoverFmtPaths({ cwd: rootPath })).rejects.toBe(nativeError);
201-
} finally {
202-
matchBatch.mockRestore();
183+
loadNativeBinding.mockRestore();
203184
}
204185
});
205186
});

0 commit comments

Comments
 (0)