-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli-logger): code and tests for log file path generator (#13088
) * refactor(amplify-cli-logger): tests for baseLogFilePath * refactor(amplify-cli-logger): simplify baseLogFilePath test * refactor: log file path code and tests * refactor: use old filename for tests * refactor: move spy inside the test suite * refactor: change project path var name * refactor: rename file
- Loading branch information
1 parent
066d4ed
commit fe043d5
Showing
5 changed files
with
79 additions
and
93 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
packages/amplify-cli-logger/src/__tests__/TestBasePath.test.ts
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
packages/amplify-cli-logger/src/__tests__/TestFilePath.test.ts
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
packages/amplify-cli-logger/src/__tests__/getLogFilePath.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import path from 'path'; | ||
import os from 'os'; | ||
import { constants as c } from '../constants'; | ||
import { getLogFilePath, getLocalLogFilePath, getLogAuditFilePath, getLocalAuditLogFile } from '../getLogFilePath'; | ||
|
||
describe('test log file path creation', () => { | ||
const slash = path.sep; | ||
const projectPath = 'myProj'; | ||
const homeDir = 'home'; | ||
|
||
jest.spyOn(os, 'homedir').mockReturnValue(homeDir); | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('log audit file in a specified directory', () => { | ||
const result = getLocalAuditLogFile(projectPath); | ||
const expected = projectPath + slash + c.LOG_DIRECTORY + slash + c.LOG_AUDIT_FOLDER + slash + c.LOG_AUDIT_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
it('log file in a specified directory', () => { | ||
const result = getLocalLogFilePath(projectPath); | ||
const expected = projectPath + slash + c.LOG_DIRECTORY + slash + c.LOG_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
it('log audit file in home directory', () => { | ||
jest.replaceProperty(process, 'argv', ['node', '']); | ||
const result = getLogAuditFilePath(); | ||
const expected = homeDir + slash + c.DOT_AMPLIFY + slash + c.LOG_DIRECTORY + slash + c.LOG_AUDIT_FOLDER + slash + c.LOG_AUDIT_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
it('log file in home directory', () => { | ||
jest.replaceProperty(process, 'argv', ['node', '']); | ||
const result = getLogFilePath(); | ||
const expected = homeDir + slash + c.DOT_AMPLIFY + slash + c.LOG_DIRECTORY + slash + c.LOG_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
it('logs-dev folder in home directory for dev build audit file', () => { | ||
jest.replaceProperty(process, 'argv', ['node', 'dev']); | ||
const result = getLogAuditFilePath(); | ||
const expected = | ||
homeDir + slash + c.DOT_AMPLIFY + slash + c.LOG_DIRECTORY + '-dev' + slash + c.LOG_AUDIT_FOLDER + slash + c.LOG_AUDIT_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
it('logs-dev folder in home directory for dev build log file', () => { | ||
jest.replaceProperty(process, 'argv', ['node', 'dev']); | ||
const result = getLogFilePath(); | ||
const expected = homeDir + slash + c.DOT_AMPLIFY + slash + c.LOG_DIRECTORY + '-dev' + slash + c.LOG_FILENAME; | ||
expect(result).toBe(expected); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters