-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try mocha/chai test runners #1418
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
079aaf1
Try mocha/chai test runners
drwpow 999f0f4
Disable failing smoke test for now
drwpow 5ea5153
Enable mocha in parallel mode
drwpow be5716f
Remove warning
drwpow a66486e
Update docs
drwpow be05785
Fix Windows bug
drwpow 3c20e7b
Fix internal imports
drwpow 2d80feb
Fix styles
drwpow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import type { AstroComponentMetadata } from '../@types/astro'; | |
import { valueToEstree } from 'estree-util-value-to-estree'; | ||
import * as astring from 'astring'; | ||
import shorthash from 'shorthash'; | ||
import { renderToString, renderAstroComponent } from '../runtime/astro.js'; | ||
|
||
const { generate, GENERATOR } = astring; | ||
|
||
|
@@ -77,11 +76,11 @@ export interface AstroComponentFactory { | |
isAstroComponentFactory?: boolean; | ||
} | ||
|
||
export const createComponent = (cb: AstroComponentFactory) => { | ||
export function createComponent(cb: AstroComponentFactory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor code style nit: I think functions are generally better because they all get hoisted and don’t depend on order of definition like |
||
// Add a flag to this callback to mark it as an Astro component | ||
(cb as any).isAstroComponentFactory = true; | ||
return cb; | ||
}; | ||
} | ||
|
||
function extractHydrationDirectives(inputProps: Record<string | number, any>): { hydrationDirective: [string, any] | null; props: Record<string | number, any> } { | ||
let props: Record<string | number, any> = {}; | ||
|
@@ -135,14 +134,14 @@ setup("${astroId}", {${metadata.hydrateArgs ? `value: ${JSON.stringify(metadata. | |
return hydrationScript; | ||
} | ||
|
||
export const renderSlot = async (result: any, slotted: string, fallback?: any) => { | ||
export async function renderSlot(result: any, slotted: string, fallback?: any) { | ||
if (slotted) { | ||
return _render(slotted); | ||
} | ||
return fallback; | ||
}; | ||
} | ||
|
||
export const renderComponent = async (result: any, displayName: string, Component: unknown, _props: Record<string | number, any>, slots?: any) => { | ||
export async function renderComponent(result: any, displayName: string, Component: unknown, _props: Record<string | number, any>, slots?: any) { | ||
Component = await Component; | ||
// children = await renderGenerator(children); | ||
const { renderers } = result._metadata; | ||
|
@@ -196,35 +195,73 @@ export const renderComponent = async (result: any, displayName: string, Componen | |
result.scripts.add(await generateHydrateScript({ renderer, astroId, props }, metadata as Required<AstroComponentMetadata>)); | ||
|
||
return `<astro-root uid="${astroId}">${html}</astro-root>`; | ||
}; | ||
} | ||
|
||
export const addAttribute = (value: any, key: string) => { | ||
export function addAttribute(value: any, key: string) { | ||
if (value == null || value === false) { | ||
return ''; | ||
} | ||
return ` ${key}="${value}"`; | ||
}; | ||
} | ||
|
||
export const spreadAttributes = (values: Record<any, any>) => { | ||
export function spreadAttributes(values: Record<any, any>) { | ||
let output = ''; | ||
for (const [key, value] of Object.entries(values)) { | ||
output += addAttribute(value, key); | ||
} | ||
return output; | ||
}; | ||
} | ||
|
||
export const defineStyleVars = (astroId: string, vars: Record<any, any>) => { | ||
export function defineStyleVars(astroId: string, vars: Record<any, any>) { | ||
let output = '\n'; | ||
for (const [key, value] of Object.entries(vars)) { | ||
output += ` --${key}: ${value};\n`; | ||
} | ||
return `.${astroId} {${output}}`; | ||
}; | ||
} | ||
|
||
export const defineScriptVars = (vars: Record<any, any>) => { | ||
export function defineScriptVars(vars: Record<any, any>) { | ||
let output = ''; | ||
for (const [key, value] of Object.entries(vars)) { | ||
output += `let ${key} = ${JSON.stringify(value)};\n`; | ||
} | ||
return output; | ||
}; | ||
} | ||
|
||
export async function renderToString(result: any, componentFactory: AstroComponentFactory, props: any, children: any) { | ||
const Component = await componentFactory(result, props, children); | ||
let template = await renderAstroComponent(Component); | ||
return template; | ||
} | ||
|
||
export async function renderPage(result: any, Component: AstroComponentFactory, props: any, children: any) { | ||
const template = await renderToString(result, Component, props, children); | ||
const styles = Array.from(result.styles).map((style: any) => renderElement('style', style)); | ||
const scripts = Array.from(result.scripts); | ||
return template.replace('</head>', styles.join('\n') + scripts.join('\n') + '</head>'); | ||
} | ||
|
||
export async function renderAstroComponent(component: InstanceType<typeof AstroComponent>) { | ||
let template = ''; | ||
|
||
for await (const value of component) { | ||
if (value || value === 0) { | ||
template += value; | ||
} | ||
} | ||
|
||
return template; | ||
} | ||
|
||
function renderElement(name: string, { props: _props, children = '' }: { props: Record<any, any>; children?: string }) { | ||
const { hoist: _, 'data-astro-id': astroId, 'define:vars': defineVars, ...props } = _props; | ||
if (defineVars) { | ||
if (name === 'style') { | ||
children = defineStyleVars(astroId, defineVars) + '\n' + children; | ||
} | ||
if (name === 'script') { | ||
children = defineScriptVars(defineVars) + '\n' + children; | ||
} | ||
} | ||
return `<${name}${spreadAttributes(props)}>${children}</${name}>`; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporarily disabled docs build test until we get a little farther