Giter Club home page Giter Club logo

Comments (8)

tobiasbueschel avatar tobiasbueschel commented on September 23, 2024 2

+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.

sebastianrothe avatar sebastianrothe commented on September 23, 2024 1

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.

raurir avatar raurir commented on September 23, 2024 1

This issue remains, replicated and documented here: https://github.com/raurir/svelte-code-linting#testing

from svelte-jester.

cabreraalex avatar cabreraalex commented on September 23, 2024 1

+1 having same issue

from svelte-jester.

cooperwalbrun avatar cooperwalbrun commented on September 23, 2024 1

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.

rvisharma avatar rvisharma commented on September 23, 2024

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.

marekdedic avatar marekdedic commented on September 23, 2024

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.

ritchieanesco avatar ritchieanesco commented on September 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.