Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Nov 16, 2022
1 parent a9f7ff9 commit d017701
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
12 changes: 6 additions & 6 deletions packages/astro/src/runtime/server/render/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { RenderInstruction } from './types';

import { HTMLBytes, markHTMLString } from '../escape.js';
import { HydrationDirectiveProps } from '../hydration.js';
import { isPromise } from '../util.js';
import { renderChild } from './any.js';
import { HTMLParts } from './common.js';
import { isPromise } from '../util.js';

// In dev mode, check props and make sure they are valid for an Astro component
function validateComponentProps(props: any, displayName: string) {
Expand All @@ -32,20 +32,20 @@ export class AstroComponent {
constructor(htmlParts: TemplateStringsArray, expressions: any[]) {
this.htmlParts = htmlParts;
this.error = undefined;
this.expressions = expressions.map(expression => {
this.expressions = expressions.map((expression) => {
// Wrap Promise expressions so we can catch errors
// There can only be 1 error that we rethrow from an Astro component,
// so this keeps track of whether or not we have already done so.
if(isPromise(expression)) {
return Promise.resolve(expression).catch(err => {
if(!this.error) {
if (isPromise(expression)) {
return Promise.resolve(expression).catch((err) => {
if (!this.error) {
this.error = err;
throw err;
}
});
}
return expression;
})
});
}

get [Symbol.toStringTag]() {
Expand Down
44 changes: 25 additions & 19 deletions packages/astro/test/units/dev/hydration.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { expect } from 'chai';

import { runInContainer } from '../../../dist/core/dev/index.js';
Expand All @@ -25,29 +24,36 @@ describe('dev container', () => {
<Bar client:load />
</body>
</html>
`
`,
},
root
);

await runInContainer({
fs, root,
logging: {
...defaultLogging,
// Error is expected in this test
level: 'silent'
await runInContainer(
{
fs,
root,
logging: {
...defaultLogging,
// Error is expected in this test
level: 'silent',
},
userConfig: {
integrations: [svelte()],
},
},
userConfig: {
integrations: [svelte()]
async (container) => {
const { req, res, done } = createRequestAndResponse({
method: 'GET',
url: '/',
});
container.handle(req, res);
const html = await done;
expect(res.statusCode).to.equal(
200,
"We get a 200 because the error occurs in the template, but we didn't crash!"
);
}
}, async (container) => {
const { req, res, done } = createRequestAndResponse({
method: 'GET',
url: '/',
});
container.handle(req, res);
const html = await done;
expect(res.statusCode).to.equal(200, 'We get a 200 because the error occurs in the template, but we didn\'t crash!');
});
);
});
});

0 comments on commit d017701

Please sign in to comment.