Skip to content

Commit

Permalink
test: write pre-rendered univeral html file to bazel bin dir
Browse files Browse the repository at this point in the history
Server side rendered kitchen sync app was written inside the test sandbox execution directory, which is deleted after test execution when the is executed without `--sandbox_debug` option thus we couldn't retrieve the `index-prendered.html` file using the command `echo $(bazel info bazel-bin)/src/universal-app/index-prerendered.html`
  • Loading branch information
trik committed Sep 28, 2021
1 parent 6e1f522 commit 77d51a7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 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,12 @@ const indexHtmlPath = require.resolve('./index.html');
const result = renderModuleFactory(
KitchenSinkRootServerModuleNgFactory,
{document: readFileSync(indexHtmlPath, 'utf-8')});
const runfilesDir = process.env.RUNFILES_DIR as string;
const bazelOutDir = dirname(runfilesDir.replace(/sandbox\/[a-z0-9]+-sandbox\/[0-9]+\//, ''));

result
.then(content => {
const filename = join(__dirname, 'index-prerendered.html');
const filename = join(bazelOutDir, 'index-prerendered.html');

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

0 comments on commit 77d51a7

Please sign in to comment.