Comments (8)
+1
I also get the same error:
Running coverage on untested files...Failed to collect coverage from /path/to-app/src/components/SomeComponent/index.svelte
ERROR: Cannot find module 'file:///path/to-app/svelte.config.js'
Require stack:
- /path/to-app/node_modules/svelte-jester/dist/transformer.cjs
- /path/to-app/node_modules/@jest/reporters/node_modules/jest-util/build/requireOrImportModule.js
- /path/to-app/node_modules/@jest/reporters/node_modules/jest-util/build/index.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/shouldInstrument.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/ScriptTransformer.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/index.js
- /path/to-app/node_modules/@jest/reporters/build/generateEmptyCoverage.js
- /path/to-app/node_modules/@jest/reporters/build/CoverageWorker.js
- /path/to-app/node_modules/jest-worker/build/workers/processChild.js
STACK: Error: Cannot find module 'file:///path/to-app/svelte.config.js'
Require stack:
- /path/to-app/node_modules/svelte-jester/dist/transformer.cjs
- /path/to-app/node_modules/@jest/reporters/node_modules/jest-util/build/requireOrImportModule.js
- /path/to-app/node_modules/@jest/reporters/node_modules/jest-util/build/index.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/shouldInstrument.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/ScriptTransformer.js
- /path/to-app/node_modules/@jest/reporters/node_modules/@jest/transform/build/index.js
- /path/to-app/node_modules/@jest/reporters/build/generateEmptyCoverage.js
- /path/to-app/node_modules/@jest/reporters/build/CoverageWorker.js
- /path/to-app/node_modules/jest-worker/build/workers/processChild.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at /path/to-app/node_modules/svelte-jester/dist/transformer.cjs:77:141
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Failed to collect coverage from /path/to-app/src/components/_layout.svelte
ERROR: Cannot find module 'file:///path/to-app/svelte.config.js'
Require stack:
//...
Here is my jest config - v8
was unfortunately not an option for me as it outputs an incorrect test coverage for my Svelte components:
import type { Config } from '@jest/types';
const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
verbose: true,
testMatch: ['<rootDir>/src/**/*.test.(js|ts)'],
transform: {
'^.+\\.svelte$': [
'svelte-jester',
{
preprocess: true
}
],
'\\.svg$': '<rootDir>/transformSvg.js',
'^.+\\.(ts|js)$': 'ts-jest',
'.+\\.(css|styl|less|sass|scss)$': 'jest-css-modules-transform'
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleFileExtensions: ['js', 'ts', 'svelte'],
moduleDirectories: ['node_modules', '<rootDir>/src'],
coverageProvider: 'babel', // v8 is still experimental and outputs incorrect coverage stats for us
collectCoverageFrom: ['<rootDir>/src/**/*.(svelte|ts)', '!<rootDir>/src/**/*.stories.svelte'],
coveragePathIgnorePatterns: ['\\.svg$', '/node_modules/'],
};
export default config;
Once I add the untested file to a test case, the error for it disappears => @rvisharma thanks for your workaround!
from svelte-jester.
Can you try to change your coverageProvider
to v8
?
I think you have to set this as well: moduleFileExtensions: ["ts", "svelte", "js"],
Can you provide a sample repo, where the bug surfaces?
from svelte-jester.
This issue remains, replicated and documented here: https://github.com/raurir/svelte-code-linting#testing
from svelte-jester.
+1 having same issue
from svelte-jester.
I am also experiencing the same issue that @tobiasbueschel and @raurir mentioned, though I am not using Babel in my setup.
Here is my jest.config.cjs
:
module.exports = {
moduleFileExtensions: ['js', 'ts', 'svelte'],
transform: {
'^.+\\.svelte$': [
'svelte-jester',
{
preprocess: true
}
],
'^.+\\.ts$': 'ts-jest'
},
coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'],
collectCoverageFrom: ['src/**/*.{ts,svelte}', '!src/*.d.ts']
};
I get the same error message:
STACK: Error: Cannot find module 'file:///path/to/my/project/svelte.config.js'
Edit: I added coverageProvider: "v8"
to my jest.config.cjs
, and it appears to be working fine now. I am using v2.3.2
of svelte-jester
if it helps anyone else.
from svelte-jester.
note - this is a hack/workaround 🔨
@marekdedic - was stuck with same issue, couldn't find a proper solution for this, but was able to find a workaround for it based on this - jestjs/jest#1211 (comment)
the linked issue, creates a file at runtime and with all require statements, instead i added a dummy spec file coverage.spec.js
with below content, that basically traverses all *.svelte
files and requires all of them
const glob = require('glob');
const cwd = require('path').join(process.cwd(), 'app', 'modules');
const pattern = '*.svelte';
glob
.sync(pattern, { cwd, matchBase: true, nosort: true })
.forEach((file) => require(file));
from svelte-jester.
Hi,I have previously tried both of these, but not both of them at once, which works! Switching back to babel however makes the tests error out completely :/
You can see it in action on this branch of my repo: https://github.com/skaut/shared-drive-mover/tree/svelte-jester-coverage-test
from svelte-jester.
I've bumped the jest version from 27.5.1
to 29.4.3
and now also getting the error
STACK: Error: Cannot find module 'file:///path/to/my/project/svelte.config.js'
when trying to include --coverage argument.
I get the above error message when using babel
for coverageProvider
However when using v8
i get
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at /Users/<user>/w/xplore-ui/node_modules/@jest/reporters/build/CoverageReporter.js:507:37
from svelte-jester.
Related Issues (20)
- Add presets like vue-jest
- Svelte 4 support HOT 7
- Add mechanism to call beforeEach() and afterEach() manually inside an it block HOT 1
- Allow to use CJS with Svelte 4 without throwing an error HOT 3
- Call `compileModule` for `.svelte.js` files in Svelte 5 HOT 8
- Phantom file listed in coverage HOT 2
- Transformer.js must export a "process" function - jester v2.0.1 jest 27 HOT 33
- Support components mocks HOT 2
- yarn vs npm
- jestOptions?.transformerConfig Unexpected token '.' HOT 2
- TypeError [ERR_INVALID_ARG_TYPE] HOT 16
- Regression in 2.1.2: a transform must export a `process` or `processAsync` function. HOT 9
- Cannot find module './preprocess.js' HOT 13
- TypeError [ERR_INVALID_ARG_TYPE] - Sapper HOT 2
- Cannot import from context="module" HOT 10
- Image imports that use typescript alias returns undefined HOT 1
- ParseError: Colon is expected (svelte with scss style) HOT 1
- Completely fails when using preprocessing HOT 4
- <svelte:component/> breaks rendering with `TypeError: switch_value is not a constructor` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-jester.