Skip to content

Commit

Permalink
Remove external CSS imports when running Jest (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 authored Jul 25, 2023
1 parent 2f69bb0 commit 282dc9e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
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.

0 comments on commit 282dc9e

Please sign in to comment.