Skip to content

Commit

Permalink
test(e2e): add test case for CSS layers (#3669)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 10, 2024
1 parent a4263a7 commit 8573c97
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
66 changes: 66 additions & 0 deletions e2e/cases/css/css-layers/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { build, dev, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should bundle CSS layers as expected in build', async () => {
const rsbuild = await build({
cwd: __dirname,
});
const files = await rsbuild.unwrapOutputJSON();

const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];

expect(content).toEqual(
'@layer a{.a{color:red}}@layer b{.b{color:green}}@layer c{@layer{.c-sub{color:#00f}.c-sub2{color:green}}.c{color:#00f}}',
);
});

rspackOnlyTest(
'should bundle CSS layers as expected in dev',
async ({ page }) => {
const rsbuild = await dev({
cwd: __dirname,
page,
rsbuildConfig: {
dev: {
writeToDisk: true,
},
},
});
const files = await rsbuild.unwrapOutputJSON();

const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];

expect(content.trim()).toEqual(`@layer a {
.a {
color: red;
}
}
@layer b {
.b {
color: green;
}
}
@layer c {
@layer {.c-sub {
color: #00f;
}
.c-sub2 {
color: green;
}
}
}
@layer c {
.c {
color: #00f;
}
}`);

await rsbuild.close();
},
);
3 changes: 3 additions & 0 deletions e2e/cases/css/css-layers/src/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
color: red;
}
3 changes: 3 additions & 0 deletions e2e/cases/css/css-layers/src/b.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.b {
color: green;
}
7 changes: 7 additions & 0 deletions e2e/cases/css/css-layers/src/c-sub.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.c-sub {
color: blue;
}

.c-sub2 {
color: green;
}
5 changes: 5 additions & 0 deletions e2e/cases/css/css-layers/src/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import './c-sub.css' layer;

.c {
color: blue;
}
1 change: 1 addition & 0 deletions e2e/cases/css/css-layers/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './style.css';
3 changes: 3 additions & 0 deletions e2e/cases/css/css-layers/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import './a.css' layer(a);
@import './b.css' layer(b);
@import './c.css' layer(c);

0 comments on commit 8573c97

Please sign in to comment.