-
Notifications
You must be signed in to change notification settings - Fork 18
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
Cannot import from context="module" #87
Comments
OK I am using "https://github.com/ktsn/svelte-jest" and it works, with no issues |
Can you post your |
We're having the same issue, actually, and I wonder if it's some interaction with compiling the test file. If we switch from a typescript test file to a javascript test file, it works. jest.config.js
tsconfig.json
|
Same probleme here. Here are our configs: jest.config.js /** @type {import('@jest/types').Config.InitialOptions} */
const config = {
transform: {
'^.+\\.svelte$': [
'svelte-jester',
{
preprocess: true,
},
],
'^.+\\.[jt]s$': 'ts-jest',
'^.+\\.svg$': 'jest-transform-stub',
'^.+\\.webm$': 'jest-transform-stub',
},
testEnvironment: 'jsdom',
testMatch: ['**/src/**/*.test.[tj]s'],
testPathIgnorePatterns: ['/node_modules/'],
moduleFileExtensions: ['js', 'ts', 'svelte'],
moduleNameMapper: {
'assets(.*)$': '<rootDir>/src/assets/$1',
'components(.*)$': '<rootDir>/src/components/$1',
},
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
// Use cobertura as coverage reporter (used by gitlab) if coverage should be collected
coverageReporters: ['text', 'cobertura'],
collectCoverageFrom: [
'src/**/*.{ts,svelte}',
'!src/App.svelte',
'!src/main.ts',
'!src/vite-env.d.ts',
],
};
export default config; tsconfig.json {
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"resolveJsonModule": true,
"baseUrl": ".",
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": false,
"strictNullChecks": true
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
}
|
Can you move your export out of |
Would be possible for sure. But this is the actual use case. With this syntax it is possible to export anything other than the default from a svelte componenten file. Without the export, the whole thing would be useless. |
I meant, if it works, if you move the export into the other |
If I understand you correctly, that won't actually help us, since exports from the other script tag are local to the instance of the component, and module-level exports are shared between instances. We're already using the module-level exports in our codebase so it would be great to support this in jest, rather than coding a workaround just for the test. Again, this is only an issue if the test is a typescript file. |
I can have another shot at it in July. |
Hey just wanted to ping about this again. No spec files written in typescript can import module-level exports from Svelte components. |
Hello
I export component specific information from svelte components, but I can not import them in any svelte test using
svelte-jester
I am using typescript
I need to import
ARROW_STATE
from this component for testingError log
The text was updated successfully, but these errors were encountered: