Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-sull authored and github-actions[bot] committed Jun 6, 2022
1 parent a87ce44 commit 2aa4354
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/astro/e2e/vue-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
10 changes: 5 additions & 5 deletions packages/astro/src/core/render/dev/css.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>();

Expand Down Expand Up @@ -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 {
Expand All @@ -85,6 +85,6 @@ export async function getStylesForURL(
await crawlCSS(viteID(filePath), true);
return {
urls: importedCssUrls,
stylesMap: importedStylesMap
stylesMap: importedStylesMap,
};
}
8 changes: 4 additions & 4 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/runtime/client/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 7 additions & 9 deletions packages/astro/test/0-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ 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{');
});

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-');
Expand All @@ -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{');
Expand All @@ -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{');
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-markdown-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`));
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-partial-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;}/);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/component-library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2aa4354

Please sign in to comment.