-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Quan Nguyen Ba
committed
Nov 11, 2024
1 parent
93bd3e9
commit 57441db
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/cli/src/actions/new.action.is-latest-version.spec.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,46 @@ | ||
import { execSync } from 'child_process' | ||
|
||
import { exportsForTesting } from './new.action' | ||
|
||
const { isLatestCli } = exportsForTesting | ||
|
||
jest.mock('child_process', () => ({ | ||
execSync: jest.fn(), | ||
})) | ||
|
||
jest.mock('fs', () => ({ | ||
readFileSync: jest.fn(() => JSON.stringify({ version: '1.0.0' })), | ||
})) | ||
jest.mock('path', () => ({ | ||
join: jest.fn(() => '/mocked/path/to/package.json'), | ||
})) | ||
|
||
describe('isLatestCli', () => { | ||
const mockExecSync = execSync as jest.MockedFunction<typeof execSync> | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should return true if the current version matches the latest version', () => { | ||
const mockLatestVersion = ['1.0.0'] | ||
mockExecSync.mockReturnValue(Buffer.from(`${mockLatestVersion}\n`)) | ||
|
||
// Run the function | ||
const result = isLatestCli() | ||
|
||
// Assert that the result is true | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it('should return false if the current version does not match the latest version', () => { | ||
const mockLatestVersion = ['1.2.3'] | ||
mockExecSync.mockReturnValue(Buffer.from(`${mockLatestVersion}\n`)) | ||
|
||
// Run the function | ||
const result = isLatestCli() | ||
|
||
// Assert that the result is true | ||
expect(result).toBe(false) | ||
}) | ||
}) |
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