-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
How can we test our js components ? #256
Comments
Hey @Rebolon, Here is a small example I made a while ago that uses Karma/Jasmine: https://github.com/Lyrkan/encore-typescript-karma If you look at the |
Hey @Lyrkan! This is a great answer. I think we should add something to the docs to help people. Wdyt? |
Hi Ryan, I thought about it when I was toying around with karma but wasn't really happy with some of the tweaks needed to make it work. For instance, without that part the ManifestPlugin tries to create its files using an invalid path... still not sure why: // Set writeToFileEmit option of the ManifestPlugin to false
for (const plugin of webpackConfig.plugins) {
if ((plugin instanceof ManifestPlugin) && plugin.opts) {
plugin.opts.writeToFileEmit = false;
}
} Or the fact that you are supposed to remove the entry point since Karma handles it itself: // Remove entry property (handled by Karma)
delete webpackConfig.entry; |
Thanks for the answer @Lyrkan, i'll test it quickly. |
i've tried and get the following error:
Here is the PR which will improve the lisibility: |
@Rebolon It looks like it's caused by the CommonsChunkPlugin (which is used because you call I guess you could try removing it manually in your // webpack.config.js
const Encore = require('@symfony/webpack-encore')
const ManifestPlugin = require('@symfony/webpack-encore/lib/webpack/webpack-manifest-plugin')
+ const webpack = require('webpack');
// Initialize Encore before requiring the .config file
Encore.configureRuntimeEnvironment('dev-server')
// Retrieve webpack config
const webpackConfig = require('./webpack.config')
// Set writeToFileEmit option of the ManifestPlugin to false
for (const plugin of webpackConfig.plugins) {
if ((plugin instanceof ManifestPlugin) && plugin.opts) {
plugin.opts.writeToFileEmit = false
}
}
+ // Remove CommonsChunkPlugin
+ webpackConfig.plugins = webpackConfig.plugins.filter(plugin => !(plugin instanceof webpack.optimize.CommonsChunkPlugin));
// Remove entry property (handled by Karma)
delete webpackConfig.entry |
@Lyrkan I don’t know a lot about this, but it looks nasty - a lot of hacking to get it working. Is this unique to Karma, or is it something that will affect most test frameworks? Is there something we can add to Encore. This is the kind of stuff that it could (in theory) make easier :) |
thanks a lot @Lyrkan it works great now |
would be great if this could be reopened and be fixed in a non-that-much-hacking way =) |
Yea, let’s re-open - this could at least be a docs issue. In Webpack 4, the commons chunk plugin is removed. |
I see, I'll recheck then, when upgrading to Webpack4 |
Any advance on this topic ? |
Personally, I build my assets before running Cypress. |
Hello, with webpack4 no tests about vuejs are running... I posted a thread on stackoverflow to describe the problem: I created a specific webpack config for tests, so i only add what i needs (for instance only vueLoader and sassLoader). The problem is that karma stop reading test files when the file does an import of a signle file component. It's like if kara tryed to used the original file, whereas it should be preprocessed by webpack (or like if webpack didn't preprocessed the file). |
Hey @Rebolon, I think I found where your issue comes from... not sure yet why it happens though. Could you try removing the The issue seems to be related to the fact that we always use the There is another loader called // Replace the mini-css-extract-plugin's loader by the style-loader
const styleExtensions = ['/\\.css$/', '/\\.s[ac]ss$/', '/\\.less$/', '/\\.styl$/'];
for (const rule of webpackConfig.module.rules) {
if (rule.test && rule.oneOf && styleExtensions.includes(rule.test.toString())) {
rule.oneOf.forEach((oneOf) => {
oneOf.use[0] = 'style-loader';
})
}
} And here is a working example: https://github.com/Lyrkan/encore-typescript-vue |
Hi @Lyrkan , Thks a lot. I will post a new response when i'll test the workaround. |
It's ok for me with 'style-loader'. |
Let it open for now, I'm thinking about adding an I'm still unsure about why |
Okay so I really think that's a bug in What happens is that when you import a CSS file and the In this case, the current stable version of I found a PR that was supposed to fix this, it was merged but no Since then they worked on a |
…kan) This PR was merged into the master branch. Discussion ---------- Add Encore.disableCssExtraction() to the public API This PR adds an `Encore.disableCssExtraction()` method that allows to disable the `mini-css-extract-plugin` and use the `style-loader` instead. It can be used to solve various problems that, until now, required a really ugly workaround that relied on our internal implementation (for instance the following commit probably broke some builds that used previous versions of it: 6867443#diff-8beacd21a12ca072bafa4e8e3f1aae6b). Related issues: #3, #256, #348, #527 Commits ------- 347feed Add Encore.disableCssExtraction() to the public API
Hi,
I build vuejs or react components and i need to be able to run tests and i'm wondering how to do unit/e2e tests when we use
encore
. I don't find anythig about this in the documentation.Any idea ?
thanks a lot
The text was updated successfully, but these errors were encountered: