Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: inject fetcher instead of using global #5502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { LogData } from '../../utils';
*/
export class GithubDependencyResolver implements DependencyResolver {
#fm: FileManager;
#fetch: typeof fetch;
#log;

constructor(fm: FileManager) {
constructor(fm: FileManager, fetcher: typeof fetch) {
this.#fm = fm;
this.#fetch = fetcher;
this.#log = (msg: string, _data?: LogData) => {
console.log(msg);
};
Expand Down Expand Up @@ -56,7 +58,7 @@ export class GithubDependencyResolver implements DependencyResolver {
return localArchivePath;
}

const response = await fetch(url, {
const response = await this.#fetch(url, {
method: 'GET',
});

Expand Down
3 changes: 2 additions & 1 deletion noir/noir-repo/compiler/wasm/src/noir/noir-wasm-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class NoirWasmCompiler {
const dependencyManager = new DependencyManager(
[
new LocalDependencyResolver(fileManager),
new GithubCodeArchiveDependencyResolver(fileManager),
// use node's global fetch
new GithubCodeArchiveDependencyResolver(fileManager, fetch),
// TODO support actual Git repositories
],
noirPackage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('GithubDependencyResolver', () => {
let fetchStub: SinonStub | undefined;

beforeEach(() => {
fetchStub = Sinon.stub(globalThis, 'fetch');
fetchStub = Sinon.stub();
fm = createMemFSFileManager(createFsFromVolume(new Volume()), '/');

libDependency = {
Expand All @@ -50,16 +50,12 @@ describe('GithubDependencyResolver', () => {
},
});

resolver = new GithubDependencyResolver(fm);
resolver = new GithubDependencyResolver(fm, fetchStub);

// cut off outside access
fetchStub.onCall(0).throws(new Error());
});

afterEach(() => {
fetchStub?.restore();
});

it("returns null if it can't resolve a dependency", async () => {
const dep = await resolver.resolveDependency(pkg, {
path: '/lib-c',
Expand Down
Loading