generated from rspack-contrib/rsbuild-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feae6af
commit c27efa6
Showing
5 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,39 @@ | ||
import { dirname } from 'node:path'; | ||
import { readFileSync } from 'node:fs'; | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { expect, test } from '@playwright/test'; | ||
import { createRsbuild } from '@rsbuild/core'; | ||
import { pluginStyledComponents } from '../../src'; | ||
import { getRandomPort } from '../helper'; | ||
import { pluginStyledComponents } from '../../dist'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
test('should render page as expected', async ({ page }) => { | ||
test('should transform styled-components with pluginStyledComponents', async ({ | ||
page, | ||
}) => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [pluginStyledComponents()], | ||
server: { | ||
port: getRandomPort(), | ||
output: { | ||
minify: false, | ||
filenameHash: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const { server, urls } = await rsbuild.startDevServer(); | ||
|
||
await page.goto(urls[0]); | ||
expect(await page.evaluate('window.test')).toBe(1); | ||
await rsbuild.build(); | ||
|
||
await server.close(); | ||
}); | ||
const indexJs = readFileSync( | ||
join(rsbuild.context.distPath, 'static/js/index.js'), | ||
'utf-8', | ||
); | ||
|
||
test('should build succeed', async ({ page }) => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [pluginStyledComponents()], | ||
}, | ||
}); | ||
expect(indexJs).toContain('div.withConfig'); | ||
|
||
await rsbuild.build(); | ||
const { server, urls } = await rsbuild.preview(); | ||
|
||
await page.goto(urls[0]); | ||
expect(await page.evaluate('window.test')).toBe(1); | ||
expect(await page.evaluate('typeof window.test')).toBe('object'); | ||
|
||
await server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
window.test = 1; | ||
import styled from 'styled-components'; | ||
|
||
window.test = styled.div` | ||
color: red; | ||
`; |