-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v0.11.0' of github.com:GoogleChromeLabs/ps-anal…
…ysis-tool into ref/gdpr-banner-acceptance
- Loading branch information
Showing
60 changed files
with
2,503 additions
and
1,490 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
|
@@ -11739,4 +11739,5 @@ export default { | |
}, | ||
}, | ||
dateTime: '24 July, 2024, 12:12:04pm Asia/Calcutta', | ||
psatVersion: '0.10.1-1', | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies. | ||
*/ | ||
import updateNotifier from 'update-notifier'; | ||
import boxen from 'boxen'; | ||
import chalk from 'chalk'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import packageJson from '../../package.json'; | ||
|
||
/** | ||
* Check latest version and show message. | ||
*/ | ||
const checkLatestVersion = async () => { | ||
// The update-notifier package doesn't display an update message on the first run, which isn't what we want. | ||
// However, we wanted to leverage its other functionalities, so we check for updates manually. | ||
const notifier = updateNotifier({ | ||
pkg: packageJson, | ||
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 * 365 * 50, // Large number to prevent check. | ||
shouldNotifyInNpmScript: true, | ||
}); | ||
|
||
// @todo Cache result somehow to prevent it running everytime. | ||
const info = await notifier.fetchInfo(); | ||
|
||
const message = | ||
'Update available ' + | ||
chalk.dim(info.current) + | ||
chalk.reset(' → ') + | ||
chalk.green(info.latest) + | ||
' \nRun ' + | ||
chalk.cyan('npm i -g @google-psat/cli') + | ||
' to update'; | ||
|
||
if (info.type !== 'latest') { | ||
console.log( | ||
boxen(message, { | ||
padding: 1, | ||
margin: 1, | ||
textAlignment: 'center', | ||
borderColor: 'yellow', | ||
borderStyle: 'round', | ||
}) | ||
); | ||
} | ||
}; | ||
|
||
export default checkLatestVersion; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies. | ||
*/ | ||
import updateNotifier from 'update-notifier'; | ||
import boxen from 'boxen'; | ||
import chalk from 'chalk'; | ||
import { noop } from '@google-psat/common'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import checkLatestVersion from '../checkLatestVersion'; | ||
|
||
jest.mock('update-notifier', () => jest.fn()); | ||
jest.mock('boxen', () => jest.fn()); | ||
jest.mock('chalk', () => ({ | ||
dim: jest.fn((text) => text), | ||
reset: jest.fn((text) => text), | ||
green: jest.fn((text) => text), | ||
cyan: jest.fn((text) => text), | ||
})); | ||
|
||
describe('checkLatestVersion', () => { | ||
let fetchInfoMock; | ||
|
||
beforeEach(() => { | ||
fetchInfoMock = jest.fn(); | ||
|
||
updateNotifier.mockReturnValue({ | ||
fetchInfo: fetchInfoMock, | ||
}); | ||
|
||
jest.spyOn(console, 'log').mockImplementation(noop); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should not show a message if the current version is the latest', async () => { | ||
// Arrange | ||
fetchInfoMock.mockResolvedValue({ | ||
current: '1.0.0', | ||
latest: '1.0.0', | ||
type: 'latest', | ||
}); | ||
|
||
await checkLatestVersion(); | ||
expect(boxen).not.toHaveBeenCalled(); | ||
expect(console.log).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should show a message if an update is available', async () => { | ||
fetchInfoMock.mockResolvedValue({ | ||
current: '1.0.0', | ||
latest: '2.0.0', | ||
type: 'major', | ||
}); | ||
|
||
const expectedMessage = | ||
'Update available ' + | ||
chalk.dim('1.0.0') + | ||
chalk.reset(' → ') + | ||
chalk.green('2.0.0') + | ||
' \nRun ' + | ||
chalk.cyan('npm i -g @google-psat/cli') + | ||
' to update'; | ||
|
||
await checkLatestVersion(); | ||
expect(boxen).toHaveBeenCalledWith(expectedMessage, { | ||
padding: 1, | ||
margin: 1, | ||
textAlignment: 'center', | ||
borderColor: 'yellow', | ||
borderStyle: 'round', | ||
}); | ||
expect(console.log).toHaveBeenCalled(); | ||
}); | ||
}); |
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
Oops, something went wrong.