Skip to content

Commit

Permalink
test: write pre-rendered univeral html file to test outputs dir (#23651)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
trik authored Sep 28, 2021
1 parent 6e1f522 commit 191bc92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/universal-app/DEBUG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
30 changes: 15 additions & 15 deletions src/universal-app/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 191bc92

Please sign in to comment.