-
Notifications
You must be signed in to change notification settings - Fork 50
Add Testrunner #83
Comments
In line with this issue I also would like testing to be easy to integrate. I got cypress (e2e testing) working as it is easy to setup, however I would really like to have Jest (unit testing) working as well. I had it running with version 0.14, but I do not manage to get things (properly) working with version 0.15 see e.g. this. |
@musicformellons - I got some basic stuff working in quasar-cli as a mode, and I am waiting for the team to get back from vacation so that we can discuss its integration. I hope that by the end of April we can push it out. Here is how you can test it out:
As far as the stack-overflow question goes, I would recommend closing it and asking over at our discord channel: https://discord.gg/4j2Qq4Q |
@musicformellons btw you can run your unit tests in Cypress too https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/unit-testing__application-code/cypress/integration/unit_test_application_code_spec.js |
That's probably easiest currently. Probably not as speedy? I also feel a bit silly since I bought this book which seems (I am halfway) thorough and works with Jest and vue test library. |
@laurentpayot I am considering using just Cypress. When I import my client api I get errors which indicate that I need to have my cypress spec files compiled with babel, did you manage in setting this up? |
Hey @musicformellons & @laurentpayot - this issue is about adding a test mode to quasar-cli. Are you working on just getting it to work in your quasar app, or are you trying to help us get this into the codebase? |
Hi @nothingismagick , uh, I think a bit of both..., they do not seem contrary to each other...?! |
Ok -cool. So that means you are suggesting that we offer the user a variety of testing frameworks to write their code with? I am not sure that is a good idea in the sense of maintainability. |
I would really prefer to choose one framework and support it perfectly and in continuity. There are lots of options out there, and I also looked around a bit... but if you two can really convince me that one framework is better to use than another - or come up with some logic to switch them out - then I am totally happy to work with you on it this way. |
@musicformellons & @nothingismagick I created a Cypress folder in my root directory. It uses the same module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.coffee$/,
loaders: ['babel-loader', 'coffee-loader'],
exclude: /node_modules/
},
]
},
}, More details in the Cypress webpack plugin docs. |
@laurentpayot I tried to replicate your settings (leaving out the coffeescript), but it seems to error on the way quasar imports components in the routes.js (I am using v0.15 project setup). I get (gave just the error for one component, but it repeats for all pages/ components of my app):
My routes.js look something like this:
My questions:
I could make an issue at cypress (as I did on something similar recently), but they lack the experience with quasar, which seems to trigger -as far as I can see- the errors I encounter. So your experience with a working quasar-cypress setup is very welcome indeed! |
@laurentpayot BTW I just made an issue here. I was just wondering: which version of webpack preprocessor did you use? They mention current version: "This version is only compatible with webpack 4.x+" Since Quasar-cli uses webpack 3, maybe I need to use @cypress/webpack-preprocessor 1.x ? |
const webpack = require('@cypress/webpack-preprocessor')
const path = require('path')
module.exports = (on) => {
const options = {
// send in the options from your webpack.config.js, so it works the same
// as your app's code
webpackOptions: {
resolve: {
extensions: ['.js', '.coffee', '.json'],
modules: [
path.resolve(__dirname, '../../src'),
path.resolve(__dirname, '../../node_modules')
],
alias: {
src: path.resolve(__dirname, '../../src'),
components: path.resolve(__dirname, '../../src/components'),
support: path.resolve(__dirname, '../support')
}
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.coffee$/,
loaders: ['babel-loader', 'coffee-loader'],
exclude: /node_modules/
},
]
},
},
watchOptions: {},
}
on('file:preprocessor', webpack(options))
} Do not forget to close your Cypress issue if the aliases fix your problem… |
@laurentpayot Seems I am progressing but I still get errors from my .vue files. How does your setting ensure compilation of .vue files as you only configure .js files and .coffee files? You are on version 2 of webpack-preprocessor. |
I am starting to fear that I need to setup all the nicely hidden compiling stuff by the Quasar-cli to get this working. Including installing all the loaders etc. like quasar used to do before version 0.15, e.g.:
Aaargh, I hope that is not true? That would make cypress (or the new quasar-cli setup) setup less ideal than I was hoping for. |
Really Cypress is great for both end-to-end and unit tests. But maybe you're trying to test Vue components, and if that's the case I don't think it's possible with Cypress or any other e2e testing tool… |
PS: Note that I'm using webpack 3. |
@laurentpayot Thanks for explaining, as that indeed makes sense and maybe I am completely wrong in 'what I want/ try'. So I understand now how you can 'avoid' the problem I have right now. My case is as follows:
Probably I need to try to refactor the api module to a minimum which should be easier to transpile with just a .js loader. |
@laurentpayot - i really have to disagree with not needing unit tests. i think that they are really the only way to enforce spec compliance for projects that have big teams. it is a great way to make sure that you get what you expect. coverage is good to know about so you see parts of your code that are never reached. E2E is important to make sure that your atomic functions collaborate. @musicformellons - there are really a lot of ways to do unit tests, and the fork that this issue is about tries to find a compromise between staying conformant with the quasar-cli and enabling the developer to write their own tests and manage coverage. later we will be using this for our CI patterns, so it is important to get it right in a sustainable way. have either of you tried the fork of this repo that i wrote? this is how to use it:
|
@nothingismagick who said I was wasn't doing unit tests ? I do a lot of unit tests. Simply I'm not unit testing my vue components because:
Of course if I had a team of testers like in my former (big) company I wouldn't mind if they spend time on tests with low added value… And I do E2E tests too (that's what Cypress was made for) so maybe you misunderstood me. |
I must have misunderstood you, I was trying to clarify the broad approach that I think we need to maintain for integrating a testing suite into the quasar-cli - which is why we are discussing it here in an issue instead of on discord. |
@musicformellons I'm using Firebase so I had the same issue as you. To use Firebase node admin functionalities (test users creation on the fly, JWT generation etc.) I had to set a local express server up that I'm calling inside Cypress tests via POST fetch requests. Cypress is working on a back-end messaging plugin. Well at least they say they it would be great: cypress-io/cypress#684 |
@nothingismagick no worries 😉 |
@laurentpayot So you only import js files, no vue files. It looks like the only reason you need the webpack-preprocessor is since you use coffeescript as the default cypress install already supports ES6. Right? @nothingismagick I am interested in your unit-testing solution, but first need to fix this cypress config and I must say I find the Laurentpayot test philosopy tempting. |
@musicformellons and also to add the same aliases as Quasar webpack config, so importing lib files in Cypress for unit testing will work the same as in Quasar. |
@laurentpayot Cool, yeah! Thanks for helping out! |
@musicformellons - I closed this issue, but I wanted to know if I might be able to interest you in collaborating with me on the new @quasarframework/quasartest team. I am now building a monorepo called |
@nothingismagick Thanks for asking as this does have my interest. As I am seriously time-restricted at the moment I am afraid I can't help right now. When circumstances change I'll let you know! |
I started setting up a test-runner. The idea I am working with - that I hope is in-line with the Quasar method - is to allow the developer to
quasar add test
- which then creates a new test from a template. This new file is then found in the webpack loop of the dev-server, and mocha-runner executes the tests as part of webpack's dev-packaging job.Here you can see the status: https://github.com/nothingismagick/quasar-cli/tree/test-runner
I have installed the deps and created a passing test-unit (that I have verified by adding a script value to the package.json - now, if you type "npm test" you will see that the tests are immediately run in the command line.
There is still a little bit of work to do, but really not that much to get the basics up and running. It should be possible to do "static" mocha/chai testing very soon. Testing within scope is likely to be a great deal more challenging. It seems that the vue.js team solved it using
https://github.com/zinserjan/mocha-webpack - but that brings its own entire webpack service - which isn't really appropriate here.
Here is their solution:
https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-mocha
The text was updated successfully, but these errors were encountered: