Skip to content
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

Test files with same name over-writing each other #395

Closed
leegee opened this issue Feb 4, 2019 · 6 comments
Closed

Test files with same name over-writing each other #395

leegee opened this issue Feb 4, 2019 · 6 comments

Comments

@leegee
Copy link

leegee commented Feb 4, 2019

  • Operating System: OSX
  • Node Version: 11.4.0
  • NPM Version: 6.5.0
  • webpack Version: 4.16.5
  • karma-webpack Version: 5.0.0-alpha.1

Expected Behavior

All tests to be compiled and run

Actual Behaviour

If tests have the same name, only one is run.

Code

    webpack: {
      devtool: 'cheap-module-source-map', // inline-source-map
      module: {
        rules: webpackConfig.module.rules.concat([
          {
            test: /\.js$/,
            loader: 'istanbul-instrumenter-loader',
            enforce: 'post',
            include: path.resolve('./'),
            exclude: /node_modules|\.(test|spec)\.js$/,
            options: {
              esModules: true
            }
          },
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: require.resolve('@open-wc/webpack/loaders/import-meta-url-loader.js')
          }
        ])
      }

Webpack shows only one test.spec.js — as it was a key to a hash, so should I add something like [hash:8] in output.filename?

Version: webpack 4.16.5
Time: 5115ms
Built at: 02/04/2019 3:49:01 PM
                     Asset       Size               Chunks             Chunk Names
                commons.js   2.87 MiB              commons  [emitted]  commons
    error-snackbar.spec.js  232 bytes  error-snackbar.spec  [emitted]  error-snackbar.spec
                runtime.js   6.08 KiB              runtime  [emitted]  runtime
              test.spec.js  190 bytes            test.spec  [emitted]  test.spec
            commons.js.map   3.01 MiB              commons  [emitted]  commons
error-snackbar.spec.js.map   88 bytes  error-snackbar.spec  [emitted]  error-snackbar.spec
            runtime.js.map   5.97 KiB              runtime  [emitted]  runtime
          test.spec.js.map   78 bytes            test.spec  [emitted]  test.spec
Entrypoint test.spec = runtime.js runtime.js.map commons.js commons.js.map test.spec.js test.spec.js.map
Entrypoint error-snackbar.spec = runtime.js runtime.js.map commons.js commons.js.map error-snackbar.spec.js error-snackbar.spec.js.map

How Do We Reproduce?

Have two test files, obv matching the files entry, with the same name, in different directories. After running, rename one of the files to see it process.

I've not changed 'entries'!

@daKmoR
Copy link
Collaborator

daKmoR commented Feb 4, 2019

uh that seems like a tough/weird one... could you prepare a minimal repo where this occurs so I can easily debug it?

@leegee
Copy link
Author

leegee commented Feb 4, 2019

I'll give it a go, because I can't get my head around it. Just a standard set-up with:

 components/one/test.spec.js
 components/two/test.spec.js

@ryanclark
Copy link
Collaborator

I guess you'd need to add the file hash to the output config, or alternatively use require.context (https://github.com/webpack-contrib/karma-webpack#alternative-usage) and only have the one entry file

@leegee
Copy link
Author

leegee commented Feb 14, 2019

Finally got around to creating a test repo, and cannot reproduce this issue. Thanks for your help/software!

// const webpack = require("webpack");
const webpackConfigJs = require('./webpack.config');

module.exports = (config) => {
    config.set({

        frameworks: ['mocha'],

        plugins: [
            require("karma-webpack"),
            require("karma-mocha"),
            require("karma-spec-reporter")
        ],

        files: [
            { pattern: 'src/*.js', watched: false },
            { pattern: 'src/**/*.js', watched: false },
        ],

        preprocessors: {
            'src/*.js': ['webpack'],
            'src/**/*.js': ['webpack'],
        },

        webpack: webpackConfigJs
    })
}

@leegee leegee closed this as completed Feb 14, 2019
@daKmoR
Copy link
Collaborator

daKmoR commented Mar 2, 2019

I could reproduce it here #400 and then I made a fix here #401

maybe it's still interesting 🤗

@leegee
Copy link
Author

leegee commented Mar 12, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants