Skip to content

Commit ea3acb9

Browse files
committed
adding tests
1 parent 63c1866 commit ea3acb9

7 files changed

Lines changed: 39 additions & 6 deletions

File tree

.changeset/violet-lions-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sku': patch
3+
---
4+
5+
vite: make vanilla-extract dep scan resolve path aliases for `css.ts` imports

fixtures/path-aliases/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
"name": "@sku-fixtures/custom-output-target",
33
"private": true,
44
"type": "module",
5+
"scripts": {
6+
"build:vite": "sku build --config sku.config.vite.ts",
7+
"start:vite": "sku start --config sku.config.vite.ts"
8+
},
59
"dependencies": {
610
"react": "catalog:",
711
"react-dom": "catalog:"
812
},
9-
"scripts": {
10-
"start:vite": "sku start --config sku.config.vite.ts",
11-
"build:vite": "sku build --config sku.config.vite.ts"
12-
},
1313
"devDependencies": {
1414
"@sku-private/test-utils": "workspace:*",
1515
"@types/react": "catalog:",
1616
"@types/react-dom": "catalog:",
17+
"@vanilla-extract/css": "catalog:",
1718
"sku": "workspace:*"
1819
}
1920
}

fixtures/path-aliases/sku.config.vite.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export default {
88
pathAliases: {
99
'@components/*': './src/components/*',
1010
'@utils/*': './src/utils/*',
11+
'#styles/*': './src/styles/*',
1112
},
12-
dangerouslySetViteConfig: makeStableViteHashes,
13+
dangerouslySetViteConfig: () => ({
14+
...makeStableViteHashes(),
15+
optimizeDeps: {
16+
// css resolution issues only occur during the first optimization.
17+
// Forcing a re-optimization to be able to test the error consistently.
18+
force: true,
19+
},
20+
}),
1321
} satisfies SkuConfig;

fixtures/path-aliases/src/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { Button } from '@components/Button';
22
import { add } from 'src/utils/add';
33

4+
// This does not get picked up by the vanilla-extract css filter since it doesn't have a ts/js extension (e.g., "foo.css.ts")
5+
import * as stylesCss from '#styles/root.css';
6+
7+
// This _does_ get picked up by the vanilla-extract css filter so we need to make sure that it resolves correctly.
8+
// The internal resolve (`this.resolve`) is used in that plugin to make sure it resolves aliases.
9+
import * as stylesCssTs from '#styles/root.css.ts';
10+
411
export default () => (
512
<div>
6-
<p>6 + 9 = {add(6, 9)}</p>
13+
<p className={stylesCss.paragraph}>6 + 9 = {add(6, 9)}</p>
14+
<p className={stylesCssTs.paragraph}>this text is red</p>
715
<Button />
816
</div>
917
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { style } from '@vanilla-extract/css';
2+
3+
export const paragraph = style({
4+
color: 'red',
5+
});

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/browser/path-aliases.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('pathAliases', () => {
3131
'src/*': ['./src/*'],
3232
'@components/*': ['./src/components/*'],
3333
'@utils/*': ['./src/utils/*'],
34+
'#styles/*': ['./src/styles/*'],
3435
});
3536
});
3637

@@ -83,6 +84,8 @@ describe('pathAliases', () => {
8384
start.queryByError('The plugin "vite-tsconfig-paths" is detected.'),
8485
).not.toBeInTheConsole();
8586

87+
expect(start.queryByError('PLUGIN_ERROR')).not.toBeInTheConsole();
88+
8689
expect(
8790
start.queryByError(
8891
"Cannot find module '@components/Button'",

0 commit comments

Comments
 (0)