[ci] format

This commit is contained in:
matthewp 2022-11-16 17:24:18 +00:00 committed by fredkbot
parent a9f7ff9667
commit d017701ae6
2 changed files with 31 additions and 25 deletions

View file

@ -4,9 +4,9 @@ import type { RenderInstruction } from './types';
import { HTMLBytes, markHTMLString } from '../escape.js'; import { HTMLBytes, markHTMLString } from '../escape.js';
import { HydrationDirectiveProps } from '../hydration.js'; import { HydrationDirectiveProps } from '../hydration.js';
import { isPromise } from '../util.js';
import { renderChild } from './any.js'; import { renderChild } from './any.js';
import { HTMLParts } from './common.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 // In dev mode, check props and make sure they are valid for an Astro component
function validateComponentProps(props: any, displayName: string) { function validateComponentProps(props: any, displayName: string) {
@ -32,20 +32,20 @@ export class AstroComponent {
constructor(htmlParts: TemplateStringsArray, expressions: any[]) { constructor(htmlParts: TemplateStringsArray, expressions: any[]) {
this.htmlParts = htmlParts; this.htmlParts = htmlParts;
this.error = undefined; this.error = undefined;
this.expressions = expressions.map(expression => { this.expressions = expressions.map((expression) => {
// Wrap Promise expressions so we can catch errors // Wrap Promise expressions so we can catch errors
// There can only be 1 error that we rethrow from an Astro component, // 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. // so this keeps track of whether or not we have already done so.
if(isPromise(expression)) { if (isPromise(expression)) {
return Promise.resolve(expression).catch(err => { return Promise.resolve(expression).catch((err) => {
if(!this.error) { if (!this.error) {
this.error = err; this.error = err;
throw err; throw err;
} }
}); });
} }
return expression; return expression;
}) });
} }
get [Symbol.toStringTag]() { get [Symbol.toStringTag]() {

View file

@ -1,4 +1,3 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { runInContainer } from '../../../dist/core/dev/index.js'; import { runInContainer } from '../../../dist/core/dev/index.js';
@ -25,29 +24,36 @@ describe('dev container', () => {
<Bar client:load /> <Bar client:load />
</body> </body>
</html> </html>
` `,
}, },
root root
); );
await runInContainer({ await runInContainer(
fs, root, {
logging: { fs,
...defaultLogging, root,
// Error is expected in this test logging: {
level: 'silent' ...defaultLogging,
// Error is expected in this test
level: 'silent',
},
userConfig: {
integrations: [svelte()],
},
}, },
userConfig: { async (container) => {
integrations: [svelte()] 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!');
});
}); });
}); });