Skip to content

Commit 42b1ff2

Browse files
authoredJun 27, 2024··
fix(hydrate): change type resolve order (#5863)
* fix(hydrate): change type resolve order * prettier * use custom stencil config for building end-to-end tests * prettier
1 parent 4ff9011 commit 42b1ff2

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed
 

‎src/hydrate/runner/render.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export function streamToString(html: string | any, option?: SerializeDocumentOpt
2424
return renderToString(html, option, true);
2525
}
2626

27+
export function renderToString(html: string | any, options?: SerializeDocumentOptions): Promise<HydrateResults>;
2728
export function renderToString(
2829
html: string | any,
2930
options: SerializeDocumentOptions | undefined,
3031
asStream: true,
3132
): Readable;
32-
export function renderToString(html: string | any, options?: SerializeDocumentOptions): Promise<HydrateResults>;
3333
export function renderToString(
3434
html: string | any,
3535
options?: SerializeDocumentOptions,
@@ -56,12 +56,12 @@ export function renderToString(
5656
return hydrateDocument(html, opts, asStream);
5757
}
5858

59+
export function hydrateDocument(doc: any | string, options?: HydrateDocumentOptions): Promise<HydrateResults>;
5960
export function hydrateDocument(
6061
doc: any | string,
6162
options: HydrateDocumentOptions | undefined,
6263
asStream?: boolean,
6364
): Readable;
64-
export function hydrateDocument(doc: any | string, options?: HydrateDocumentOptions): Promise<HydrateResults>;
6565
export function hydrateDocument(
6666
doc: any | string,
6767
options?: HydrateDocumentOptions,

‎test/end-to-end/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "dist/types/components.d.ts",
77
"collection": " dist/collection/collection-manifest.json",
88
"scripts": {
9-
"build": "node ../../bin/stencil build --docs",
9+
"build": "node ../../bin/stencil build --config ./stencil.build.config.ts --docs",
1010
"start": "node ../../bin/stencil build --debug --watch --dev --serve",
1111
"test": "node ../../bin/stencil test --ci --e2e --spec --screenshot --debug",
1212
"test.dist": "npm run build && node test-end-to-end-dist.js && node test-end-to-end-hydrate.js",

‎test/end-to-end/src/declarative-shadow-dom/test.e2e.ts

+14
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,27 @@ async function readableToString(readable: Readable) {
2929
type HydrateModule = typeof import('../../hydrate');
3030
let renderToString: HydrateModule['renderToString'];
3131
let streamToString: HydrateModule['streamToString'];
32+
let hydrateDocument: HydrateModule['hydrateDocument'];
3233

3334
describe('renderToString', () => {
3435
beforeAll(async () => {
3536
// @ts-ignore may not be existing when project hasn't been built
3637
const mod = await import('../../hydrate');
3738
renderToString = mod.renderToString;
3839
streamToString = mod.streamToString;
40+
hydrateDocument = mod.hydrateDocument;
41+
});
42+
43+
it('resolves to a Promise<HydrateResults> by default', async () => {
44+
const renderedString = renderToString('<div>Hello World</div>');
45+
expect(typeof renderedString.then).toBe('function');
46+
// this is a type assertion to verify that the promise resolves to a HydrateResults object
47+
renderedString.then((result) => result.html);
48+
49+
const renderedDocument = hydrateDocument('<div>Hello World</div>');
50+
expect(typeof renderedDocument.then).toBe('function');
51+
// this is a type assertion to verify that the promise resolves to a HydrateResults object
52+
renderedDocument.then((result) => result.html);
3953
});
4054

4155
it('can render a simple dom node', async () => {
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { config as baseConfig } from './stencil.config';
2+
3+
/**
4+
* We are using a slightly different tsconfig to build the end-to-end tests
5+
* as we are doing type assertions on the hydrate module which is not available
6+
* when the project hasn't been built.
7+
*/
8+
baseConfig.tsconfig = './tsconfig.build.json';
9+
export const config = baseConfig;

‎test/end-to-end/tsconfig.build.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
/**
4+
* Exclude the test where we do type assertions using the hydrate module
5+
* which doesn't exist at build time.
6+
*/
7+
"exclude": ["src/declarative-shadow-dom/test.e2e.ts"]
8+
}

0 commit comments

Comments
 (0)
Please sign in to comment.