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:
parent
5e568e4a14
commit
6a1a17dd28
8 changed files with 77 additions and 2 deletions
5
.changeset/odd-swans-collect.md
Normal file
5
.changeset/odd-swans-collect.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Allow HMR for internal e2e tests
|
33
packages/astro/e2e/css.test.js
Normal file
33
packages/astro/e2e/css.test.js
Normal 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)');
|
||||||
|
});
|
||||||
|
});
|
8
packages/astro/e2e/fixtures/css/package.json
Normal file
8
packages/astro/e2e/fixtures/css/package.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "@e2e/css",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
9
packages/astro/e2e/fixtures/css/src/pages/index.astro
Normal file
9
packages/astro/e2e/fixtures/css/src/pages/index.astro
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<h1>hello world</h1>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import "../styles/main.css";
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: var(--h1-color);
|
||||||
|
}
|
||||||
|
</style>
|
3
packages/astro/e2e/fixtures/css/src/styles/main.css
Normal file
3
packages/astro/e2e/fixtures/css/src/styles/main.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
:root {
|
||||||
|
--h1-color: red;
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
import { test as testBase, expect } from '@playwright/test';
|
import { test as testBase, expect } from '@playwright/test';
|
||||||
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';
|
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';
|
||||||
|
|
||||||
|
export const isWindows = process.platform === 'win32';
|
||||||
|
|
||||||
export function loadFixture(inlineConfig) {
|
export function loadFixture(inlineConfig) {
|
||||||
if (!inlineConfig || !inlineConfig.root)
|
if (!inlineConfig || !inlineConfig.root)
|
||||||
throw new Error("Must provide { root: './fixtures/...' }");
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -7,9 +7,10 @@ import { info } from '../core/logger/core.js';
|
||||||
import * as msg from '../core/messages.js';
|
import * as msg from '../core/messages.js';
|
||||||
import { isAstroScript } from './query.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) => {
|
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 {
|
export interface HandleHotUpdateOptions {
|
||||||
|
|
|
@ -585,6 +585,12 @@ importers:
|
||||||
'@astrojs/vue': link:../../../../integrations/vue
|
'@astrojs/vue': link:../../../../integrations/vue
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/e2e/fixtures/css:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/e2e/fixtures/error-cyclic:
|
packages/astro/e2e/fixtures/error-cyclic:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/preact': workspace:*
|
'@astrojs/preact': workspace:*
|
||||||
|
|
Loading…
Reference in a new issue