Skip to content

Commit f1108e5

Browse files
Merge pull request #609 from HubSpot/config-cleanup
Pulling git logic out of config file
2 parents 5353cb6 + 0f38be5 commit f1108e5

File tree

9 files changed

+239
-213
lines changed

9 files changed

+239
-213
lines changed

packages/cli-lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const { ALLOWED_EXTENSIONS, Mode, DEFAULT_MODE } = require('./lib/constants');
22
const {
3-
checkAndWarnGitInclusion,
43
getAndLoadConfigIfNeeded,
54
getConfig,
5+
getConfigPath,
66
getAccountId,
77
getAccountConfig,
88
getEnv,
9-
109
findConfig,
1110
loadConfig,
1211
loadConfigFromEnvironment,
@@ -16,6 +15,7 @@ const {
1615
isTrackingAllowed,
1716
writeConfig,
1817
} = require('./lib/config');
18+
const { checkAndWarnGitInclusion } = require('./lib/git');
1919
const { uploadFolder } = require('./lib/uploadFolder');
2020
const { watch } = require('./lib/watch');
2121
const { read } = require('./lib/read');
@@ -28,6 +28,7 @@ module.exports = {
2828
checkAndWarnGitInclusion,
2929
getAndLoadConfigIfNeeded,
3030
getConfig,
31+
getConfigPath,
3132
findConfig,
3233
loadConfig,
3334
loadConfigFromEnvironment,

packages/cli-lib/lib/__tests__/config.js

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const {
1010
updateAccountConfig,
1111
validateConfig,
1212
deleteEmptyConfigFile,
13-
configFilenameIsIgnoredByGitignore,
1413
setConfigPath,
1514
createEmptyConfigFile,
1615
} = require('../config');
@@ -525,98 +524,11 @@ describe('lib/config', () => {
525524
});
526525
});
527526

528-
describe('configFilenameIsIgnoredByGitignore method', () => {
529-
const fs = require('fs-extra');
530-
531-
afterAll(() => {
527+
describe('getConfigPath method', () => {
528+
beforeAll(() => {
532529
setConfigPath(CONFIG_PATHS.default);
533-
mockedConfigPath = CONFIG_PATHS.default;
534-
});
535-
536-
it('returns false if the config file is not ignored', () => {
537-
const gitignoreContent = '';
538-
setConfigPath(`/Users/fakeuser/someproject/hubspot.config.yml`);
539-
jest.spyOn(fs, 'readFileSync').mockImplementation(() => {
540-
return Buffer.from(gitignoreContent);
541-
});
542-
543-
expect(
544-
configFilenameIsIgnoredByGitignore([
545-
'/Users/fakeuser/someproject/.gitignore',
546-
])
547-
).toBe(false);
548-
});
549-
550-
it('identifies if a config file is ignored with a specific ignore statement', () => {
551-
const gitignoreContent = 'hubspot.config.yml';
552-
setConfigPath(`/Users/fakeuser/someproject/hubspot.config.yml`);
553-
const readFileSyncSpy = jest
554-
.spyOn(fs, 'readFileSync')
555-
.mockImplementation(() => {
556-
return Buffer.from(gitignoreContent);
557-
});
558-
559-
expect(
560-
configFilenameIsIgnoredByGitignore([
561-
'/Users/fakeuser/someproject/.gitignore',
562-
])
563-
).toBe(true);
564-
readFileSyncSpy.mockReset();
565-
});
566-
567-
it('identifies if a config file is ignored with a wildcard statement', () => {
568-
const gitignoreContent = 'hubspot.config.*';
569-
setConfigPath(`/Users/fakeuser/someproject/hubspot.config.yml`);
570-
const readFileSyncSpy = jest
571-
.spyOn(fs, 'readFileSync')
572-
.mockImplementation(() => {
573-
return Buffer.from(gitignoreContent);
574-
});
575-
576-
expect(
577-
configFilenameIsIgnoredByGitignore([
578-
'/Users/fakeuser/someproject/.gitignore',
579-
])
580-
).toBe(true);
581-
readFileSyncSpy.mockReset();
582-
});
583-
584-
it('identifies if a non-standard named config file is not ignored', () => {
585-
const gitignoreContent = 'hubspot.config.yml';
586-
setConfigPath('/Users/fakeuser/someproject/config/my.custom.name.yml');
587-
const readFileSyncSpy = jest
588-
.spyOn(fs, 'readFileSync')
589-
.mockImplementation(() => {
590-
return Buffer.from(gitignoreContent);
591-
});
592-
593-
expect(
594-
configFilenameIsIgnoredByGitignore([
595-
'/Users/fakeuser/someproject/.gitignore',
596-
])
597-
).toBe(false);
598-
readFileSyncSpy.mockReset();
599530
});
600531

601-
it('identifies if a non-standard named config file is ignored', () => {
602-
const gitignoreContent = 'my.custom.name.yml';
603-
setConfigPath('/Users/fakeuser/someproject/config/my.custom.name.yml');
604-
const readFileSyncSpy = jest
605-
.spyOn(fs, 'readFileSync')
606-
.mockImplementation(() => {
607-
return Buffer.from(gitignoreContent);
608-
});
609-
610-
expect(
611-
configFilenameIsIgnoredByGitignore([
612-
'/Users/fakeuser/someproject/.gitignore',
613-
])
614-
).toBe(true);
615-
readFileSyncSpy.mockReset();
616-
});
617-
});
618-
619-
describe('getConfigPath method', () => {
620532
describe('when a standard config is present', () => {
621533
it('returns the standard config path', () => {
622534
const configPath = getConfigPath();

packages/cli-lib/lib/__tests__/git.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
const { configFilenameIsIgnoredByGitignore } = require('../git');
2+
3+
describe('lib/git', () => {
4+
describe('configFilenameIsIgnoredByGitignore method', () => {
5+
const fs = require('fs-extra');
6+
7+
it('returns false if the config file is not ignored', () => {
8+
const gitignoreContent = '';
9+
const configPath = `/Users/fakeuser/someproject/hubspot.config.yml`;
10+
jest.mock('findup-sync', () => jest.fn(() => configPath));
11+
12+
jest.spyOn(fs, 'readFileSync').mockImplementation(() => {
13+
return Buffer.from(gitignoreContent);
14+
});
15+
16+
expect(
17+
configFilenameIsIgnoredByGitignore(
18+
['/Users/fakeuser/someproject/.gitignore'],
19+
configPath
20+
)
21+
).toBe(false);
22+
});
23+
24+
it('identifies if a config file is ignored with a specific ignore statement', () => {
25+
const gitignoreContent = 'hubspot.config.yml';
26+
const configPath = `/Users/fakeuser/someproject/hubspot.config.yml`;
27+
jest.mock('findup-sync', () => jest.fn(() => configPath));
28+
29+
const readFileSyncSpy = jest
30+
.spyOn(fs, 'readFileSync')
31+
.mockImplementation(() => {
32+
return Buffer.from(gitignoreContent);
33+
});
34+
35+
expect(
36+
configFilenameIsIgnoredByGitignore(
37+
['/Users/fakeuser/someproject/.gitignore'],
38+
configPath
39+
)
40+
).toBe(true);
41+
readFileSyncSpy.mockReset();
42+
});
43+
44+
it('identifies if a config file is ignored with a wildcard statement', () => {
45+
const gitignoreContent = 'hubspot.config.*';
46+
const configPath = `/Users/fakeuser/someproject/hubspot.config.yml`;
47+
jest.mock('findup-sync', () => jest.fn(() => configPath));
48+
49+
const readFileSyncSpy = jest
50+
.spyOn(fs, 'readFileSync')
51+
.mockImplementation(() => {
52+
return Buffer.from(gitignoreContent);
53+
});
54+
55+
expect(
56+
configFilenameIsIgnoredByGitignore(
57+
['/Users/fakeuser/someproject/.gitignore'],
58+
configPath
59+
)
60+
).toBe(true);
61+
readFileSyncSpy.mockReset();
62+
});
63+
64+
it('identifies if a non-standard named config file is not ignored', () => {
65+
const gitignoreContent = 'hubspot.config.yml';
66+
const configPath =
67+
'/Users/fakeuser/someproject/config/my.custom.name.yml';
68+
jest.mock('findup-sync', () => jest.fn(() => configPath));
69+
70+
const readFileSyncSpy = jest
71+
.spyOn(fs, 'readFileSync')
72+
.mockImplementation(() => {
73+
return Buffer.from(gitignoreContent);
74+
});
75+
76+
expect(
77+
configFilenameIsIgnoredByGitignore(
78+
['/Users/fakeuser/someproject/.gitignore'],
79+
configPath
80+
)
81+
).toBe(false);
82+
readFileSyncSpy.mockReset();
83+
});
84+
85+
it('identifies if a non-standard named config file is ignored', () => {
86+
const gitignoreContent = 'my.custom.name.yml';
87+
const configPath =
88+
'/Users/fakeuser/someproject/config/my.custom.name.yml';
89+
jest.mock('findup-sync', () => jest.fn(() => configPath));
90+
91+
const readFileSyncSpy = jest
92+
.spyOn(fs, 'readFileSync')
93+
.mockImplementation(() => {
94+
return Buffer.from(gitignoreContent);
95+
});
96+
97+
expect(
98+
configFilenameIsIgnoredByGitignore(
99+
['/Users/fakeuser/someproject/.gitignore'],
100+
configPath
101+
)
102+
).toBe(true);
103+
readFileSyncSpy.mockReset();
104+
});
105+
});
106+
});

0 commit comments

Comments
 (0)