From 191bc9281ebaa6f434c13102c4b7c78b64275d82 Mon Sep 17 00:00:00 2001 From: Marco Marche Date: Tue, 28 Sep 2021 23:56:33 +0200 Subject: [PATCH] test: write pre-rendered univeral html file to test outputs dir (#23651) Write server side pre-rendered kitchen sync app to bazel TEST_UNDECLARED_OUTPUTS_DIR. Update the DEBUG guide information to retrieve the generated `index-prerendered.html` --- src/universal-app/DEBUG.md | 4 ++-- src/universal-app/prerender.ts | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/universal-app/DEBUG.md b/src/universal-app/DEBUG.md index 24fff3e3a8c1..cf1190863bd3 100644 --- a/src/universal-app/DEBUG.md +++ b/src/universal-app/DEBUG.md @@ -6,5 +6,5 @@ the file will be stored in the `bazel-out` folder. You can retrieve the path to the file by either running: -* `bazel test //src/universal-app:server_test --test_output=all` -* `echo $(bazel info bazel-bin)/src/universal-app/index-prerendered.html` +* `bazel run //src/universal-app:server_test --test_output=all` +* `echo $(bazel info bazel-testlogs)/src/universal-app/server_test/test.outputs/index-prerendered.html` diff --git a/src/universal-app/prerender.ts b/src/universal-app/prerender.ts index 315681ff7dc5..9441bb421246 100644 --- a/src/universal-app/prerender.ts +++ b/src/universal-app/prerender.ts @@ -14,21 +14,21 @@ import {KitchenSinkRootServerModuleNgFactory} from './kitchen-sink-root.ngfactor const indexHtmlPath = require.resolve('./index.html'); const result = renderModuleFactory( - KitchenSinkRootServerModuleNgFactory, - {document: readFileSync(indexHtmlPath, 'utf-8')}); + KitchenSinkRootServerModuleNgFactory, {document: readFileSync(indexHtmlPath, 'utf-8')}); +const outDir = process.env.TEST_UNDECLARED_OUTPUTS_DIR as string; result - .then(content => { - const filename = join(__dirname, 'index-prerendered.html'); + .then(content => { + const filename = join(outDir, 'index-prerendered.html'); - console.log('Inspect pre-rendered page here:'); - console.log(`file://${filename}`); - writeFileSync(filename, content, 'utf-8'); - console.log('Prerender done.'); - }) - // If rendering the module factory fails, print the error and exit the process - // with a non-zero exit code. - .catch(error => { - console.error(error); - process.exit(1); - }); + console.log('Inspect pre-rendered page here:'); + console.log(`file://${filename}`); + writeFileSync(filename, content, 'utf-8'); + console.log('Prerender done.'); + }) + // If rendering the module factory fails, print the error and exit the process + // with a non-zero exit code. + .catch(error => { + console.error(error); + process.exit(1); + });