angular/integration/platform-server/projects/ngmodule/prerender.ts
Alan Agius e8ad51aaed test: refactor platform-server integration tests to use application builder (#53205)
This commit updates the platform-server tests to use the new application builder, with this change we also have to remove the sizechecks since esbuild will do code motion and split the code into multiple chunks example `chunk-QUKLKPSE.js`.

PR Close #53205
2023-11-28 11:07:01 +01:00

44 lines
1.3 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
import {renderModule} from '@angular/platform-server';
import {AppServerModule} from './src/main.server';
import {fileURLToPath} from 'node:url';
import {dirname, join, resolve} from 'node:path';
import {readFileSync} from 'node:fs';
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
const browserDistFolder = resolve(serverDistFolder, '../browser');
const indexHtml = readFileSync(join(browserDistFolder, 'index.html'), 'utf-8');
async function runTest() {
// Test and validate the errors are printed in the console.
const originalConsoleError = console.error;
const errors: string[] = [];
console.error = (error, data) => errors.push(error.toString() + ' ' + data.toString());
try {
await renderModule(AppServerModule, {
document: indexHtml,
url: '/error',
});
} catch {}
console.error = originalConsoleError;
// Test case
if (!errors.some((e) => e.includes('Error in resolver'))) {
errors.forEach(console.error);
console.error(
'\nError: expected rendering errors ("Error in resolver") to be printed in the console.\n',
);
process.exit(1);
}
}
runTest();