Skip to content

Commit b63333b

Browse files
trikamysorto
authored andcommitted
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` (cherry picked from commit 191bc92)
1 parent b026b4e commit b63333b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/universal-app/DEBUG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ the file will be stored in the `bazel-out` folder.
66

77
You can retrieve the path to the file by either running:
88

9-
* `bazel test //src/universal-app:server_test --test_output=all`
10-
* `echo $(bazel info bazel-bin)/src/universal-app/index-prerendered.html`
9+
* `bazel run //src/universal-app:server_test --test_output=all`
10+
* `echo $(bazel info bazel-testlogs)/src/universal-app/server_test/test.outputs/index-prerendered.html`

src/universal-app/prerender.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ import {KitchenSinkRootServerModuleNgFactory} from './kitchen-sink-root.ngfactor
1414
const indexHtmlPath = require.resolve('./index.html');
1515

1616
const result = renderModuleFactory(
17-
KitchenSinkRootServerModuleNgFactory,
18-
{document: readFileSync(indexHtmlPath, 'utf-8')});
17+
KitchenSinkRootServerModuleNgFactory, {document: readFileSync(indexHtmlPath, 'utf-8')});
18+
const outDir = process.env.TEST_UNDECLARED_OUTPUTS_DIR as string;
1919

2020
result
21-
.then(content => {
22-
const filename = join(__dirname, 'index-prerendered.html');
21+
.then(content => {
22+
const filename = join(outDir, 'index-prerendered.html');
2323

24-
console.log('Inspect pre-rendered page here:');
25-
console.log(`file://${filename}`);
26-
writeFileSync(filename, content, 'utf-8');
27-
console.log('Prerender done.');
28-
})
29-
// If rendering the module factory fails, print the error and exit the process
30-
// with a non-zero exit code.
31-
.catch(error => {
32-
console.error(error);
33-
process.exit(1);
34-
});
24+
console.log('Inspect pre-rendered page here:');
25+
console.log(`file://${filename}`);
26+
writeFileSync(filename, content, 'utf-8');
27+
console.log('Prerender done.');
28+
})
29+
// If rendering the module factory fails, print the error and exit the process
30+
// with a non-zero exit code.
31+
.catch(error => {
32+
console.error(error);
33+
process.exit(1);
34+
});

0 commit comments

Comments
 (0)