Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
philipp-spiess authored and adamwathan committed Oct 3, 2024
commit 2dc7d33baadf84409f709b758f13d8dfb6aed86b
34 changes: 34 additions & 0 deletions packages/tailwindcss/src/css-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,3 +901,37 @@ describe('in JS config files', () => {
`)
})
})

test('replaces CSS theme() function with values inside imported stylesheets', async () => {
expect(
await compileCss(
css`
@theme {
--color-red-500: #f00;
}
@import './bar.css';
`,
[],
{
async loadStylesheet() {
return {
base: '/bar.css',
content: css`
.red {
color: theme(colors.red.500);
}
`,
}
},
},
),
).toMatchInlineSnapshot(`
":root {
--color-red-500: red;
}

.red {
color: red;
}"
`)
})
28 changes: 28 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ describe('@apply', () => {
`)
})

it('should replace @apply with the correct result inside imported stylesheets', async () => {
expect(
await compileCss(
css`
@import './bar.css';
@tailwind utilities;
`,
[],
{
async loadStylesheet() {
return {
base: '/bar.css',
content: css`
.foo {
@apply underline;
}
`,
}
},
},
),
).toMatchInlineSnapshot(`
".foo {
text-decoration-line: underline;
}"
`)
})

it('should @apply in order the utilities would be sorted in if they were used in HTML', async () => {
expect(
await compileCss(css`
Expand Down
4 changes: 2 additions & 2 deletions packages/tailwindcss/src/test-utils/run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Features, transform } from 'lightningcss'
import { compile } from '..'

export async function compileCss(css: string, candidates: string[] = []) {
let { build } = await compile(css)
export async function compileCss(css: string, candidates: string[] = [], options = {}) {
let { build } = await compile(css, options)
return optimizeCss(build(candidates)).trim()
}

Expand Down