Skip to content

Commit

Permalink
🧑‍💻 [#724] Use aliases for tests
Browse files Browse the repository at this point in the history
When using relative imports, vite/vitest complain about ESM modules
being used through a CJS package, and setting type: module in
package.json breaks a lot of other things. Renaming the module to
.mts pushes the problem down the chain. It seems that using the
import alias seems to work to resolve the api-mocks package,
but there are plenty of other problems...
  • Loading branch information
sergei-maertens committed Nov 17, 2024
1 parent f20718c commit f68f3e1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"importOrder": ["^((api-mocks|components|data|formio|hooks|map|story-utils|types)/(.*)|(api|api-mocks|cache|Context|errors|headers|i18n|sdk|sentry|types|utils))$", "^[./]"],
"importOrder": ["^@/.*", "^((api-mocks|components|data|formio|hooks|map|story-utils|types)/(.*)|(api|api-mocks|cache|Context|errors|headers|i18n|sdk|sentry|types|utils))$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
5 changes: 4 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"compilerOptions": {
"baseUrl": "src"
"baseUrl": "src",
"paths": {
"@/*": ["./*"]
},
},
"include": ["src"]
}
2 changes: 1 addition & 1 deletion src/vitest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

import mswServer from 'api-mocks/msw-server';
import mswServer from '@/api-mocks/msw-server';

beforeAll(() => mswServer.listen());
afterEach(() => mswServer.resetHandlers());
Expand Down
3 changes: 3 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ export default defineConfig({
environment: 'jsdom',
globals: true, // for compatibility with jest
setupFiles: ['./src/vitest.setup.js'],
alias: {
'@/': new URL('./src/', import.meta.url).pathname,
},
},
});

0 comments on commit f68f3e1

Please sign in to comment.