3
0
Fork 0
mirror of https://gitea.com/actions/setup-node.git synced 2024-11-24 02:59:33 +01:00
setup-node/__tests__/mock/glob-mock.ts
Sergey Dolin 8170e22e8f
Detect cached folders from multiple directories (#735)
* Add project-dir

* Fix find lock file

* Remove package-dir input

* format & resolve conflicts

* Add unit tests

* build dist

* Apply change request fixes

* handle non-dir cache-dependency-path

* bump cache version

* run checks

* Handle globs in cacheDependencyPath

* refactor, introduce `cacheDependencyPathToProjectsDirectories`

it is necessary for the next PR related yarn optimization

* Changes requests

* Apply fixes

* review fixes

* add e2e

* Add unique

* review updates

* review updates second stage

* Review fixes 3

* imporve e2e tests
2023-06-21 17:52:17 +02:00

29 lines
680 B
TypeScript

import {Globber} from '@actions/glob';
export class MockGlobber implements Globber {
private readonly expected: string[];
constructor(expected: string[]) {
this.expected = expected;
}
getSearchPaths(): string[] {
return this.expected.slice();
}
async glob(): Promise<string[]> {
const result: string[] = [];
for await (const itemPath of this.globGenerator()) {
result.push(itemPath);
}
return result;
}
async *globGenerator(): AsyncGenerator<string, void> {
for (const e of this.expected) {
yield e;
}
}
static async create(expected: string[]): Promise<MockGlobber> {
return new MockGlobber(expected);
}
}