-
-
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.
Showing
1 changed file
with
51 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
import { describe, expect, it } from 'bun:test' | ||
import { afterAll, describe, expect, it } from 'bun:test' | ||
import { plugin as unocss } from '../src/index' | ||
|
||
describe('bun-plugin-unocss', () => { | ||
it('should inject CSS into HTML', async () => { | ||
expect(true).toBe(true) | ||
it('should inject generated CSS into HTML', async () => { | ||
const html = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head><title>Test</title></head> | ||
<body> | ||
<div class="mt-24 text-red-500"></div> | ||
</body> | ||
</html> | ||
` | ||
|
||
await Bun.write('test.html', html) | ||
|
||
// Process with Bun plugin | ||
const result = await Bun.build({ | ||
entrypoints: ['test.html'], | ||
outdir: 'out', | ||
plugins: [unocss], | ||
root: import.meta.dir, // Add root directory specification | ||
}) | ||
|
||
// Get the output contents directly from build results | ||
const output = await result.outputs[0].text() | ||
|
||
// Verify CSS properties without spaces (UnoCSS minifies by default) | ||
expect(output).toInclude('margin-top:6rem') // mt-24 | ||
expect(output).toInclude('color:rgb(239 68 68') // text-red-500 | ||
}) | ||
|
||
it('should handle HTML without UnoCSS classes', async () => { | ||
const html = `<!DOCTYPE html><html><head></head><body></body></html>` | ||
await Bun.write('test-empty.html', html) | ||
|
||
const result = await Bun.build({ | ||
entrypoints: ['test-empty.html'], | ||
outdir: 'out', | ||
plugins: [unocss], | ||
root: import.meta.dir, | ||
}) | ||
|
||
const output = await result.outputs[0].text() | ||
// Check for presence of style tag with default layers | ||
expect(output).toInclude('<style></style>') | ||
expect(output).toInclude('/* layer: preflights */') | ||
expect(output).not.toInclude('margin-top:6rem') | ||
}) | ||
|
||
afterAll(async () => { | ||
await Bun.$`rm -rf out test.html test-empty.html`.quiet() | ||
}) | ||
}) |