Skip to content

Commit

Permalink
test: write pre-rendered univeral html file to test outputs dir
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 committed Sep 28, 2021
1 parent 6e1f522 commit 4b762cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 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`
5 changes: 3 additions & 2 deletions src/universal-app/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'zone.js';

import {renderModuleFactory} from '@angular/platform-server';
import {readFileSync, writeFileSync} from 'fs';
import {join} from 'path';
import {dirname, join} from 'path';

import {KitchenSinkRootServerModuleNgFactory} from './kitchen-sink-root.ngfactory';

Expand All @@ -16,10 +16,11 @@ const indexHtmlPath = require.resolve('./index.html');
const result = renderModuleFactory(
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');
const filename = join(outDir, 'index-prerendered.html');

console.log('Inspect pre-rendered page here:');
console.log(`file://${filename}`);
Expand Down

0 comments on commit 4b762cd

Please sign in to comment.