Skip to content
Merged
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 dedicated integration tests to ensure border compatibility is inj…
…ected in the correct spot
  • Loading branch information
RobinMalfait committed Oct 24, 2024
commit 3a91299b996bb713702613a6bf4cfc7a2aa735c7
174 changes: 174 additions & 0 deletions integrations/upgrade/js-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,178 @@ describe('border compatibility', () => {
`)
},
)

test(
'migrate border compatibility in the file that uses the `@import "tailwindcss"` import',
{
fs: {
'package.json': json`
{
"dependencies": {
"@tailwindcss/upgrade": "workspace:^"
}
}
`,
'tailwind.config.ts': ts`
import { type Config } from 'tailwindcss'

export default {
theme: {},
} satisfies Config
`,
'src/input.css': css`@import './tailwind.css';`,
'src/tailwind.css': css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`,
},
},
async ({ exec, fs }) => {
await exec('npx @tailwindcss/upgrade')

expect(await fs.dumpFiles('src/**/*.css')).toMatchInlineSnapshot(`
"
--- src/input.css ---
@import './tailwind.css';

--- src/tailwind.css ---
@import 'tailwindcss';

/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injected the border compatibility CSS because @import "tailwindcss" exists

The default border color has changed to \`currentColor\` in Tailwind CSS v4,
so we've added these compatibility styles to make sure everything still
looks the same as it did with Tailwind CSS v3.

If we ever want to remove these styles, we need to add an explicit border
color utility to any element that depends on these defaults.
*/
@layer base {
*,
::after,
::before,
::backdrop,
::file-selector-button {
border-color: var(--color-gray-200, currentColor);
}
}

/*
Form elements have a 1px border by default in Tailwind CSS v4, so we've
added these compatibility styles to make sure everything still looks the
same as it did with Tailwind CSS v3.

If we ever want to remove these styles, we need to add \`border-0\` to
any form elements that shouldn't have a border.
*/
@layer base {
input:where(:not([type='button'], [type='reset'], [type='submit'])),
select,
textarea {
border-width: 0;
}
}
"
`)
},
)

test(
'migrate border compatibility in the file that uses the `@import "tailwindcss/preflight"` import',
{
fs: {
'package.json': json`
{
"dependencies": {
"@tailwindcss/upgrade": "workspace:^"
}
}
`,
'tailwind.config.ts': ts`
import { type Config } from 'tailwindcss'

export default {
theme: {},
} satisfies Config
`,
'src/input.css': css`
@import './base.css';
@import './my-base.css';
@import './utilities.css';
`,
'src/base.css': css`@tailwind base;`,
'src/utilities.css': css`
@tailwind components;
@tailwind utilities;
`,
'src/my-base.css': css`
@layer base {
html {
color: black;
}
}
`,
},
},
async ({ exec, fs }) => {
await exec('npx @tailwindcss/upgrade')

expect(await fs.dumpFiles('src/**/*.css')).toMatchInlineSnapshot(`
"
--- src/base.css ---
@import 'tailwindcss/theme' layer(theme);
@import 'tailwindcss/preflight' layer(base);

/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injected the border compatibility CSS because @import "tailwindcss/preflight" exists

The default border color has changed to \`currentColor\` in Tailwind CSS v4,
so we've added these compatibility styles to make sure everything still
looks the same as it did with Tailwind CSS v3.

If we ever want to remove these styles, we need to add an explicit border
color utility to any element that depends on these defaults.
*/
@layer base {
*,
::after,
::before,
::backdrop,
::file-selector-button {
border-color: var(--color-gray-200, currentColor);
}
}

/*
Form elements have a 1px border by default in Tailwind CSS v4, so we've
added these compatibility styles to make sure everything still looks the
same as it did with Tailwind CSS v3.

If we ever want to remove these styles, we need to add \`border-0\` to
any form elements that shouldn't have a border.
*/
@layer base {
input:where(:not([type='button'], [type='reset'], [type='submit'])),
select,
textarea {
border-width: 0;
}
}

--- src/input.css ---
@import './base.css';
@import './my-base.css';
@import './utilities.css';

--- src/my-base.css ---
@layer base {
html {
color: black;
}
}

--- src/utilities.css ---
@import 'tailwindcss/utilities' layer(utilities);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No border compatibility CSS was injected because we only have tailwindcss/utilities but not the tailwindcss or tailwindcss/preflight imports

"
`)
},
)
})