Skip to content

Commit

Permalink
feat: move cache under node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 15, 2021
1 parent dc5580c commit 83cb6e5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 10 deletions.
24 changes: 23 additions & 1 deletion lib/file-client/file-constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import fs from 'fs';

const ROOT = '.';
const CACHE_DIR = '/.cache-eslint-remote-tester';
const NODE_MODULES = '/node_modules';
const ESLINT_REMOTE_TESTER = '/eslint-remote-tester';

function initializeCacheDirectory() {
if (fs.existsSync(ROOT + NODE_MODULES + ESLINT_REMOTE_TESTER)) {
// Has eslint-remote-tester installed under node_modules
return ROOT + NODE_MODULES + ESLINT_REMOTE_TESTER + CACHE_DIR;
}

if (fs.existsSync(ROOT + NODE_MODULES)) {
// Has node_modules but no eslint-remote-tester installed locally
return ROOT + NODE_MODULES + CACHE_DIR;
}

// Has no node_modules
return ROOT + CACHE_DIR;
}

/** Directory where repositories are cloned to */
export const CACHE_LOCATION = './.cache-eslint-remote-tester';
export const CACHE_LOCATION = initializeCacheDirectory();

/** Directory where results are generated in to */
export const RESULTS_LOCATION = './eslint-remote-tester-results';
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration.action-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('integration - compare action exports', () => {
expect(
actionExports.RESULTS_COMPARISON_CACHE_LOCATION
).toMatchInlineSnapshot(
`"./.cache-eslint-remote-tester/.comparison-cache.json"`
`"./node_modules/.cache-eslint-remote-tester/.comparison-cache.json"`
);
});

Expand Down
10 changes: 5 additions & 5 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('integration', () => {
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
"
`);
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('integration', () => {
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
"
`);
Expand All @@ -257,11 +257,11 @@ describe('integration', () => {

expect(cachedRun.output.pop()).toMatchInlineSnapshot(`
"Full log:
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target crashed: unable-to-parse-rule-id
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 5 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
"
`);
Expand Down Expand Up @@ -1092,7 +1092,7 @@ describe('integration', () => {
eol-last - AriPerkkio/eslint-remote-tester-integration-test-target
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 21 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
"
`);
Expand Down
4 changes: 2 additions & 2 deletions test/smoke/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe('smoke', () => {

expect(output.pop()).toMatchInlineSnapshot(`
"Full log:
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
[ERROR] AriPerkkio/eslint-remote-tester-integration-test-target 56000 errors
[DONE] Finished scan of 1 repositories
[INFO] Cached repositories (1) at ./.cache-eslint-remote-tester
[INFO] Cached repositories (1) at ./node_modules/.cache-eslint-remote-tester
[DONE] Result comparison: Added 56000. Removed 56000.
"
Expand Down
39 changes: 39 additions & 0 deletions test/unit/file-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ function createComparisonResults(): void {
);
}

function getCacheLocation() {
let location = '';

jest.resetModuleRegistry();
jest.isolateModules(() => {
location = require('../../lib/file-client/file-constants')
.CACHE_LOCATION;
});

return location;
}

describe('file-client', () => {
describe('prepareResultsDirectory', () => {
afterEach(() => {
Expand Down Expand Up @@ -244,4 +256,31 @@ describe('file-client', () => {
]);
});
});

describe('CACHE_LOCATION', () => {
test('is initialized under package in node_modules', () => {
jest.mock('fs', () => ({ existsSync: () => true }));

expect(getCacheLocation()).toBe(
'./node_modules/eslint-remote-tester/.cache-eslint-remote-tester'
);
});

test('is initialized under node_modules when package is not installed', () => {
jest.mock('fs', () => ({
existsSync: (path: string) =>
path !== './node_modules/eslint-remote-tester',
}));

expect(getCacheLocation()).toBe(
'./node_modules/.cache-eslint-remote-tester'
);
});

test('is initialized in root when node_modules is not available', () => {
jest.mock('fs', () => ({ existsSync: () => false }));

expect(getCacheLocation()).toBe('./.cache-eslint-remote-tester');
});
});
});
2 changes: 1 addition & 1 deletion test/unit/repository-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@file-client/repository-client';
import SimpleGit from '__mocks__/simple-git';

const EXPECTED_CACHE = './.cache-eslint-remote-tester';
const EXPECTED_CACHE = './node_modules/.cache-eslint-remote-tester';

describe('repository-client', () => {
beforeEach(() => {
Expand Down

0 comments on commit 83cb6e5

Please sign in to comment.