0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Add CSS @import test (#4454)

* Add css hmr test

* Allow HMR in e2e tests

* Add changeset

* Actually fix test

* Fix lint

* Skip windows for now
This commit is contained in:
Bjorn Lu 2022-09-23 03:06:49 +08:00 committed by GitHub
parent 5e568e4a14
commit 6a1a17dd28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Allow HMR for internal e2e tests

View file

@ -0,0 +1,33 @@
import { expect } from '@playwright/test';
import { getColor, isWindows, testFactory } from './test-utils.js';
const test = testFactory({
root: './fixtures/css/',
});
let devServer;
test.beforeAll(async ({ astro }) => {
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
test.describe('CSS HMR', () => {
test.skip(isWindows, 'TODO: fix css hmr in windows');
test('edit CSS from @import', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const h = page.locator('h1');
expect(await getColor(h)).toBe('rgb(255, 0, 0)');
await astro.editFile('./src/styles/main.css', (original) =>
original.replace('--h1-color: red;', '--h1-color: green;')
);
expect(await getColor(h)).toBe('rgb(0, 128, 0)');
});
});

View file

@ -0,0 +1,8 @@
{
"name": "@e2e/css",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,9 @@
<h1>hello world</h1>
<style>
@import "../styles/main.css";
h1 {
color: var(--h1-color);
}
</style>

View file

@ -0,0 +1,3 @@
:root {
--h1-color: red;
}

View file

@ -1,6 +1,8 @@
import { test as testBase, expect } from '@playwright/test';
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';
export const isWindows = process.platform === 'win32';
export function loadFixture(inlineConfig) {
if (!inlineConfig || !inlineConfig.root)
throw new Error("Must provide { root: './fixtures/...' }");
@ -40,3 +42,11 @@ export async function getErrorOverlayMessage(page) {
return await overlay.$$eval('.message-body', (m) => m[0].textContent);
}
/**
* @param {import('@playwright/test').Locator} el
* @returns {Promise<string>}
*/
export async function getColor(el) {
return await el.evaluate((e) => getComputedStyle(e).color);
}

View file

@ -7,9 +7,10 @@ import { info } from '../core/logger/core.js';
import * as msg from '../core/messages.js';
import { isAstroScript } from './query.js';
const PKG_PREFIX = new URL('../../', import.meta.url);
const PKG_PREFIX = fileURLToPath(new URL('../../', import.meta.url));
const E2E_PREFIX = fileURLToPath(new URL('../../e2e', import.meta.url));
const isPkgFile = (id: string | null) => {
return id?.startsWith(fileURLToPath(PKG_PREFIX)) || id?.startsWith(PKG_PREFIX.pathname);
return id && id.startsWith(PKG_PREFIX) && !id.startsWith(E2E_PREFIX);
};
export interface HandleHotUpdateOptions {

View file

@ -585,6 +585,12 @@ importers:
'@astrojs/vue': link:../../../../integrations/vue
astro: link:../../..
packages/astro/e2e/fixtures/css:
specifiers:
astro: workspace:*
dependencies:
astro: link:../../..
packages/astro/e2e/fixtures/error-cyclic:
specifiers:
'@astrojs/preact': workspace:*