Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove external CSS imports when running Jest #865

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/poor-grapes-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Remove external CSS imports when running Jest
11 changes: 11 additions & 0 deletions fixtures/styling/src/components/BlueBlock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import BlueBlock from './BlueBlock';
import lessStyles from './styles.less';
import * as styles from './BlueBlock.css';

test('LESS styles', () => {
expect(lessStyles.root).toEqual('styles__root');
expect(lessStyles.nested).toEqual('styles__nested');
});

test('Vanilla Extract styles', () => {
expect(styles.root).toEqual(expect.stringContaining('BlueBlock_root'));
expect(styles.border).toEqual(expect.stringContaining('BlueBlock_border'));
});

test('external CSS loaded without errors', () => {
expect(BlueBlock).toBeDefined();
});
11 changes: 11 additions & 0 deletions packages/sku/config/babel/babelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = ({
rootResolution = false,
}) => {
const isBrowser = target === 'browser';
const isJest = target === 'jest';
const isProductionBuild = process.env.NODE_ENV === 'production';

const plugins = [
Expand All @@ -32,6 +33,16 @@ module.exports = ({
]);
}

if (isJest) {
plugins.push([
require.resolve('babel-plugin-transform-remove-imports'),
{
test: /\.css$/,
remove: 'effects',
},
]);
}

if (isProductionBuild) {
plugins.push(
require.resolve('@babel/plugin-transform-react-inline-elements'),
Expand Down
1 change: 1 addition & 0 deletions packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"babel-plugin-macros": "^3.1.0",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-plugin-transform-remove-imports": "^1.7.0",
"babel-plugin-unassert": "^3.1.0",
"browserslist": "^4.16.1",
"browserslist-config-seek": "^2.1.0",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.