From 3fb2c6d7fba2c9139d385858a6a58a369072051a Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Thu, 11 Jul 2019 15:59:45 -0700 Subject: [PATCH] clients(devtools): audits2->audits and defer reading resources (#9344) --- clients/devtools-report-assets.js | 20 ++++++++++++++++---- lighthouse-core/scripts/roll-to-devtools.sh | 8 +++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/clients/devtools-report-assets.js b/clients/devtools-report-assets.js index 58b80f645f2b..a7ff67f7ada0 100644 --- a/clients/devtools-report-assets.js +++ b/clients/devtools-report-assets.js @@ -16,9 +16,21 @@ // @ts-ignore: Runtime exists in Devtools. const cachedResources = Runtime.cachedResources; +// Getters are necessary because the DevTools bundling processes +// resources after this module is resolved. These properties are not +// read from immediately, so we can defer reading with getters and everything +// is going to be OK. module.exports = { - REPORT_CSS: cachedResources['audits/lighthouse/report.css'], - REPORT_JAVASCRIPT: cachedResources['audits/lighthouse/report.js'], - REPORT_TEMPLATE: cachedResources['audits/lighthouse/template.html'], - REPORT_TEMPLATES: cachedResources['audits/lighthouse/templates.html'], + get REPORT_CSS() { + return cachedResources['audits/lighthouse/report.css']; + }, + get REPORT_JAVASCRIPT() { + return cachedResources['audits/lighthouse/report.js']; + }, + get REPORT_TEMPLATE() { + return cachedResources['audits/lighthouse/template.html']; + }, + get REPORT_TEMPLATES() { + return cachedResources['audits/lighthouse/templates.html']; + }, }; diff --git a/lighthouse-core/scripts/roll-to-devtools.sh b/lighthouse-core/scripts/roll-to-devtools.sh index 5959fd902182..826c3cefdb57 100755 --- a/lighthouse-core/scripts/roll-to-devtools.sh +++ b/lighthouse-core/scripts/roll-to-devtools.sh @@ -21,7 +21,7 @@ else frontend_dir="$chromium_dir/third_party/blink/renderer/devtools/front_end" fi -tests_dir="$frontend_dir/../../../web_tests/http/tests/devtools/audits2" +tests_dir="$frontend_dir/../../../web_tests/http/tests/devtools/audits" if [[ ! -d "$frontend_dir" || ! -a "$frontend_dir/Runtime.js" ]]; then echo -e "\033[31m✖ Error!\033[39m" @@ -43,10 +43,12 @@ cp -pPR "$lh_bg_js" "$lh_worker_dir/lighthouse-dt-bundle.js" echo -e "\033[96m ✓\033[39m (Potentially stale) lighthouse-dt-bundle copied." # copy report generator + cached resources into $fe_lh_dir -cp -r dist/dt-report-resources/ $fe_lh_dir +# use dir/* format to copy over all files in dt-report-resources directly to $fe_lh_dir +# dir/ format behavior changes based on if their exists a folder named dir, which can get weird +cp -r dist/dt-report-resources/* $fe_lh_dir # update expected version string in tests VERSION=$(node -e "console.log(require('./package.json').version)") sed -i '' -e "s/Version:.*/Version: $VERSION/g" "$tests_dir"/*-expected.txt -echo "Done. To rebase the test expectations, run: yarn --cwd ~/chromium/src/third_party/blink/renderer/devtools test 'http/tests/devtools/audits2/*' --reset-results" +echo "Done. To rebase the test expectations, run: yarn --cwd ~/chromium/src/third_party/blink/renderer/devtools test 'http/tests/devtools/audits/*' --reset-results"