-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@rpidanny/darwin", | ||
"description": "An elegant CLI wizard enhancing biotech research efficiency, with adaptable features for other domains, albeit with minor constraints.", | ||
"version": "1.27.0", | ||
"version": "1.28.0", | ||
"author": "Abhishek <[email protected]>", | ||
"bin": { | ||
"darwin": "./bin/run.js" | ||
|
@@ -61,6 +61,7 @@ | |
"playwright": "^1.44.1", | ||
"pretty-ms": "^9.0.0", | ||
"reflect-metadata": "^0.2.2", | ||
"semver": "^7.6.2", | ||
"tough-cookie": "^4.1.4", | ||
"typedi": "^0.10.0" | ||
}, | ||
|
@@ -150,7 +151,8 @@ | |
"hooks": { | ||
"init": [ | ||
"./dist/hooks/init/analytics", | ||
"./dist/hooks/init/banner" | ||
"./dist/hooks/init/banner", | ||
"./dist/hooks/init/check-update" | ||
], | ||
"postrun": "./dist/hooks/postrun/analytics" | ||
}, | ||
|
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,86 @@ | ||
import { jest } from '@jest/globals' | ||
import { Hook } from '@oclif/core' | ||
import nock from 'nock' | ||
|
||
import { getMockConfig } from '../../../test/fixtures/config.js' | ||
import { getMockHooksContext } from '../../../test/fixtures/hooks.js' | ||
import uiOutput from '../../utils/ui/output' | ||
import checkUpdateHook from './check-update.js' | ||
|
||
describe('Hooks - init:check-update', () => { | ||
const latest = '2.1.0' | ||
const current = '1.27.1' | ||
const mockConfig = getMockConfig({ version: current }) | ||
|
||
let hookContext: Hook.Context | ||
|
||
beforeEach(() => { | ||
nock('https://registry.npmjs.org') | ||
.get('/@rpidanny/darwin/latest') | ||
.reply(200, { version: latest }) | ||
|
||
hookContext = getMockHooksContext({ config: mockConfig }) | ||
|
||
jest.spyOn(uiOutput, 'printUpdateBanner').mockImplementation(() => {}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should call uiOutput.printUpdateBanner when current version is lower than latest version', async () => { | ||
await checkUpdateHook.call(hookContext, { | ||
id: 'some-command', | ||
argv: [], | ||
config: mockConfig, | ||
context: hookContext, | ||
}) | ||
|
||
expect(uiOutput.printUpdateBanner).toHaveBeenCalledTimes(1) | ||
expect(uiOutput.printUpdateBanner).toHaveBeenCalledWith(latest, hookContext.log) | ||
}) | ||
|
||
it('should not call uiOutput.printUpdateBanner when current version is the latest version', async () => { | ||
const config = getMockConfig({ version: latest }) | ||
const context = getMockHooksContext({ config }) | ||
|
||
await checkUpdateHook.call(context, { | ||
id: 'some-command', | ||
argv: [], | ||
config, | ||
context, | ||
}) | ||
|
||
expect(uiOutput.printUpdateBanner).not.toHaveBeenCalled() | ||
}) | ||
|
||
it.each` | ||
command | ||
${'autocomplete:script'} | ||
${'readme'} | ||
`('should not call uiOutput.printUpdateBanner if command is $command', async ({ command }) => { | ||
await checkUpdateHook.call(hookContext, { | ||
id: command, | ||
argv: [], | ||
config: mockConfig, | ||
context: hookContext, | ||
}) | ||
|
||
expect(uiOutput.printUpdateBanner).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should not throw an error if the request fails', async () => { | ||
nock.cleanAll() | ||
nock('https://registry.npmjs.org').get('/@rpidanny/darwin/latest').reply(500) | ||
|
||
await expect( | ||
checkUpdateHook.call(hookContext, { | ||
id: 'some-command', | ||
argv: [], | ||
config: mockConfig, | ||
context: hookContext, | ||
}), | ||
).resolves.not.toThrow() | ||
}) | ||
}) |
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,28 @@ | ||
import { Hook } from '@oclif/core' | ||
import got from 'got' | ||
import semver from 'semver' | ||
|
||
import ui from '../../utils/ui/output.js' | ||
|
||
const hook: Hook<'init'> = async function (opts) { | ||
if (opts.id && ['autocomplete:script', 'readme'].includes(opts.id)) return | ||
|
||
try { | ||
const { version: latestVersion } = await got( | ||
'https://registry.npmjs.org/@rpidanny/darwin/latest', | ||
{ | ||
responseType: 'json', | ||
timeout: 1_000, | ||
}, | ||
).json<{ version: string }>() | ||
|
||
if (semver.gt(latestVersion, this.config.version)) { | ||
ui.printUpdateBanner(latestVersion, this.log) | ||
} | ||
} catch (error) { | ||
// Silence errors | ||
return | ||
} | ||
} | ||
|
||
export default hook |
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
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