Skip to content

Commit

Permalink
tests: read target cache beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianRomanski committed Dec 12, 2024
1 parent b649d40 commit 5528725
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions projects/nx-verdaccio/src/plugin/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function setCacheRecord<T>(
export function readTargetsCache(
cachePath: string
): Record<string, Partial<ProjectConfiguration>> {
// that part is ready
const mockedExistsSync = existsSync(cachePath);
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && existsSync(cachePath)
? readJsonFile(cachePath)
: {};
Expand Down
31 changes: 28 additions & 3 deletions projects/nx-verdaccio/src/plugin/caching.unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { afterEach, beforeEach, describe, expect } from 'vitest';
import * as moduleUnderTest from './caching';
import * as cachingUtils from './utils/caching.utils';
import { setCacheRecord } from './caching';
import * as nodeFs from 'node:fs';
import { readTargetsCache, setCacheRecord } from './caching';
import { cacheKey } from './utils/caching.utils';

describe('caching', () => {
Expand Down Expand Up @@ -78,7 +79,31 @@ describe('caching', () => {
});
});

})

//export function readTargetsCache(
// cachePath: string
// ): Record<string, Partial<ProjectConfiguration>> {
// return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && existsSync(cachePath)
// ? readJsonFile(cachePath)
// : {};
// }
describe('readTargetsCache', (): void => {
const existsSyncSpy = vi
.spyOn(nodeFs, 'existsSync')
.mockImplementation((): boolean => true);

// beforeEach((): void => {
// existsSyncSpy = vi.spyOn(cachingUtils, 'cacheKey');
// });

afterEach((): void => {
existsSyncSpy.mockRestore();
});

it('should call cacheKey with the correct arguments', (): void => {
readTargetsCache('test');

expect(existsSyncSpy).toHaveBeenCalledWith('test');
expect(existsSyncSpy).toHaveBeenCalledTimes(1);
});
});
})

0 comments on commit 5528725

Please sign in to comment.