-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a validator module to Bubblewrap #134
Changes from 6 commits
96b36e8
ac7a9e8
8e10032
be8210a
71a74c4
40e80fe
dc17f72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ module.exports = (): void => { | |
const log = new Log('cli'); | ||
const args = process.argv.slice(2); | ||
cli.run(args) | ||
.then((result) => { | ||
if (!result) { | ||
process.exit(1); | ||
} | ||
}) | ||
.catch((err: Error) => { | ||
log.error(err.message); | ||
process.exit(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure what you're doing here. Isn't this the last code to be called in the execution of the program? Why would you need to call process.exit() ? Is it just to make the return code 1? I'm dubious about using process.exit in general since it's not obvious from the caller of this method that the entire program could terminate. Is there some way to make the method return the exit code - so 1 in the two cases you call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we instead do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the code. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2020 Google Inc. All Rights Reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
import {PwaValidator} from '@bubblewrap/validator'; | ||
import {Log} from '@bubblewrap/core'; | ||
import {ParsedArgs} from 'minimist'; | ||
import {printValidationResult} from '../pwaValidationHelper'; | ||
|
||
const log = new Log('validate'); | ||
|
||
/** | ||
* Runs the PwaValidator to check a given URL agains the Quality criteria. More information on the | ||
* Quality Criteria available at: https://web.dev/using-a-pwa-in-your-android-app/#quality-criteria | ||
* @param {ParsedArgs} args | ||
*/ | ||
export async function validate(args: ParsedArgs): Promise<boolean> { | ||
log.info('Validating URL: ', args.url); | ||
const validationResult = await PwaValidator.validate(new URL(args.url)); | ||
printValidationResult(validationResult, log); | ||
return validationResult.status === 'PASS'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {PwaValidationResult} from '@bubblewrap/validator'; | ||
import {red, green, bold, underline, gray} from 'colors'; | ||
import {Log} from '@bubblewrap/core'; | ||
|
||
export function printValidationResult(validationResult: PwaValidationResult, log: Log): void { | ||
log.info(''); | ||
log.info('Check the full PageSpeed Insights report at:'); | ||
log.info(`- ${validationResult.psiWebUrl}`); | ||
log.info(''); | ||
|
||
const performanceValue = validationResult.scores.performance.status === 'PASS' ? | ||
green(validationResult.scores.performance.printValue) : | ||
red(validationResult.scores.performance.printValue); | ||
|
||
const pwaValue = validationResult.scores.pwa.status === 'PASS' ? | ||
green(validationResult.scores.pwa.printValue) : | ||
red(validationResult.scores.pwa.printValue); | ||
|
||
const overallStatus = validationResult.status === 'PASS' ? | ||
green(validationResult.status) : red(validationResult.status); | ||
|
||
const accessibilityValue = gray(validationResult.scores.accessibility.printValue); | ||
|
||
log.info(''); | ||
log.info(underline('Quality Criteria scores')); | ||
log.info(`Lighthouse Performance score: ......... ${performanceValue}`); | ||
log.info(`Lighthouse PWA check: ................. ${pwaValue}`); | ||
log.info(''); | ||
log.info(underline('Other scores')); | ||
log.info(`Lighthouse Accessibility score......... ${accessibilityValue}`); | ||
log.info(''); | ||
log.info(underline('Summary')); | ||
log.info(bold(`Overall result: ....................... ${overallStatus}`)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!--- | ||
|
||
Copyright 2019 Google Inc. All Rights Reserved. | ||
|
||
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 | ||
|
||
http://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. | ||
--> | ||
# Bubblewrap Validator | ||
|
||
Bubblewrap Validator is a JavaScript library that helps developers to verify if their | ||
andreban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[Trusted Web Activity][1] project is well formed as well as validating if the Progressive Web | ||
App(PWA) used inside it matchs the [minimun quality criteria][2]. | ||
|
||
[1]: https://developers.google.com/web/android/trusted-web-activity/ | ||
[2]: https://web.dev/using-a-pwa-in-your-android-app/#quality-criteria |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"spec_dir": "dist/spec", | ||
"spec_files": [ | ||
"**/*[sS]pec.js" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.js" | ||
], | ||
"stopSpecOnExpectationFailure": false, | ||
"random": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiniest nit: could you say "a library to...", so that the sentence has the same form as the previous two bullet points?