mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
a87ce4412c
commit
2aa43549e0
8 changed files with 24 additions and 24 deletions
|
@ -142,6 +142,6 @@ test.describe('Vue components', () => {
|
|||
const label = counter.locator('h1');
|
||||
|
||||
await expect(label, 'slotted text updated').toHaveText('Hello, updated client:visible!');
|
||||
await expect(counter, 'component styles persisted').toHaveCSS('display', 'grid')
|
||||
await expect(counter, 'component styles persisted').toHaveCSS('display', 'grid');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type * as vite from 'vite';
|
||||
|
||||
import path from 'path';
|
||||
import { RuntimeMode } from '../../../@types/astro.js';
|
||||
import { unwrapId, viteID } from '../../util.js';
|
||||
import { STYLE_EXTENSIONS } from '../util.js';
|
||||
import { RuntimeMode } from '../../../@types/astro.js';
|
||||
|
||||
/**
|
||||
* List of file extensions signalling we can (and should) SSR ahead-of-time
|
||||
|
@ -16,7 +16,7 @@ export async function getStylesForURL(
|
|||
filePath: URL,
|
||||
viteServer: vite.ViteDevServer,
|
||||
mode: RuntimeMode
|
||||
): Promise<{urls: Set<string>, stylesMap: Map<string, string>}> {
|
||||
): Promise<{ urls: Set<string>; stylesMap: Map<string, string> }> {
|
||||
const importedCssUrls = new Set<string>();
|
||||
const importedStylesMap = new Map<string, string>();
|
||||
|
||||
|
@ -68,8 +68,8 @@ export async function getStylesForURL(
|
|||
const ext = path.extname(importedModule.url).toLowerCase();
|
||||
if (STYLE_EXTENSIONS.has(ext)) {
|
||||
if (
|
||||
mode === 'development' // only inline in development
|
||||
&& typeof importedModule.ssrModule?.default === 'string' // ignore JS module styles
|
||||
mode === 'development' && // only inline in development
|
||||
typeof importedModule.ssrModule?.default === 'string' // ignore JS module styles
|
||||
) {
|
||||
importedStylesMap.set(importedModule.url, importedModule.ssrModule.default);
|
||||
} else {
|
||||
|
@ -85,6 +85,6 @@ export async function getStylesForURL(
|
|||
await crawlCSS(viteID(filePath), true);
|
||||
return {
|
||||
urls: importedCssUrls,
|
||||
stylesMap: importedStylesMap
|
||||
stylesMap: importedStylesMap,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export type RenderResponse =
|
|||
| { type: 'html'; html: string; response: ResponseInit }
|
||||
| { type: 'response'; response: Response };
|
||||
|
||||
const svelteStylesRE = /svelte\?svelte&type=style/;
|
||||
const svelteStylesRE = /svelte\?svelte&type=style/;
|
||||
|
||||
async function loadRenderer(
|
||||
viteServer: ViteDevServer,
|
||||
|
@ -155,14 +155,14 @@ export async function render(
|
|||
});
|
||||
|
||||
let styles = new Set<SSRElement>();
|
||||
[...(stylesMap)].forEach(([url, content]) => {
|
||||
[...stylesMap].forEach(([url, content]) => {
|
||||
// The URL is only used by HMR for Svelte components
|
||||
// See src/runtime/client/hmr.ts for more details
|
||||
styles.add({
|
||||
props: {
|
||||
'data-astro-injected': svelteStylesRE.test(url) ? url : true
|
||||
'data-astro-injected': svelteStylesRE.test(url) ? url : true,
|
||||
},
|
||||
children: content
|
||||
children: content,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -46,7 +46,9 @@ if (import.meta.hot) {
|
|||
// This will only be called after the svelte component has hydrated in the browser.
|
||||
// At this point Vite is tracking component style updates, we need to remove
|
||||
// styles injected by Astro for the component in favor of Vite's internal HMR.
|
||||
const injectedStyle = document.querySelector(`style[data-astro-injected="${file.acceptedPath}"]`);
|
||||
const injectedStyle = document.querySelector(
|
||||
`style[data-astro-injected="${file.acceptedPath}"]`
|
||||
);
|
||||
if (injectedStyle) {
|
||||
injectedStyle.parentElement?.removeChild(injectedStyle);
|
||||
}
|
||||
|
|
|
@ -298,8 +298,8 @@ describe('CSS', function () {
|
|||
});
|
||||
|
||||
it('resolves ESM style imports', async () => {
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
|
||||
expect(allInjectedStyles, 'styles/imported-url.css').to.contain('.imported{');
|
||||
expect(allInjectedStyles, 'styles/imported-url.sass').to.contain('.imported-sass{');
|
||||
expect(allInjectedStyles, 'styles/imported-url.scss').to.contain('.imported-scss{');
|
||||
|
@ -307,7 +307,7 @@ describe('CSS', function () {
|
|||
|
||||
it('resolves Astro styles', async () => {
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text();
|
||||
|
||||
|
||||
expect(allInjectedStyles).to.contain('.linked-css.astro-');
|
||||
expect(allInjectedStyles).to.contain('.linked-sass.astro-');
|
||||
expect(allInjectedStyles).to.contain('.linked-scss.astro-');
|
||||
|
@ -318,14 +318,14 @@ describe('CSS', function () {
|
|||
const styles = [
|
||||
'ReactModules.module.css',
|
||||
'ReactModules.module.scss',
|
||||
'ReactModules.module.sass'
|
||||
'ReactModules.module.sass',
|
||||
];
|
||||
for (const style of styles) {
|
||||
const href = $(`link[href$="${style}"]`).attr('href');
|
||||
expect((await fixture.fetch(href)).status, style).to.equal(200);
|
||||
}
|
||||
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
|
||||
expect(allInjectedStyles).to.contain('.react-title{');
|
||||
expect(allInjectedStyles).to.contain('.react-sass-title{');
|
||||
|
@ -341,15 +341,13 @@ describe('CSS', function () {
|
|||
});
|
||||
|
||||
it('resolves CSS from Vue', async () => {
|
||||
const styles = [
|
||||
'VueModules.vue?vue&type=style&index=0&lang.module.scss'
|
||||
];
|
||||
const styles = ['VueModules.vue?vue&type=style&index=0&lang.module.scss'];
|
||||
for (const style of styles) {
|
||||
const href = $(`link[href$="${style}"]`).attr('href');
|
||||
expect((await fixture.fetch(href)).status, style).to.equal(200);
|
||||
}
|
||||
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
|
||||
expect(allInjectedStyles).to.contain('.vue-css{');
|
||||
expect(allInjectedStyles).to.contain('.vue-sass{');
|
||||
|
|
|
@ -52,7 +52,7 @@ describe('Imported markdown CSS', function () {
|
|||
expect(importedAstroComponent?.name).to.equal('h2');
|
||||
const cssClass = $(importedAstroComponent).attr('class')?.split(/\s+/)?.[0];
|
||||
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
expect(allInjectedStyles).to.match(new RegExp(`h2.${cssClass}{color:#00f}`));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('Partial HTML', async () => {
|
|||
expect(html).to.match(/^<!DOCTYPE html/);
|
||||
|
||||
// test 2: link tag present
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
expect(allInjectedStyles).to.match(/h1{color:red;}/);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -108,11 +108,11 @@ describe('Component Libraries', () => {
|
|||
const $ = cheerioLoad(html);
|
||||
|
||||
// Most styles are inlined in a <style> block in the dev server
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g,"");
|
||||
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
|
||||
if (expected.test(allInjectedStyles)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Also check for <link> stylesheets
|
||||
const links = $('link[rel=stylesheet]');
|
||||
for (const link of links) {
|
||||
|
|
Loading…
Reference in a new issue