xolvio / qualityfaster

An example project showing how to create robust and maintainable acceptance tests
262 stars 58 forks source link

Include information on how to include server specs #27

Closed willclarktech closed 7 months ago

willclarktech commented 8 years ago

karma.conf.js excludes src/imports/**/server/**/*-spec.@(js|jsx) and commenting out that line leads to an error:

Uncaught Error: There is already a collection named 'accountHolders' at
[...]/src/.meteor/local/build/programs/web.browser/packages/mongo.js:312

I couldn't find any information in the docs on how to include the server-side tests. What's the best way?

samhatoum commented 8 years ago

They are not being run as part of Karma as it is a client-side only testing framework.

There was an older project that allowed server-side testing to happen: https://github.com/mhevery/jasmine-node

Jasmine now has a node cli runner built-in so it's probably possible to wire it up so it runs as part of Karma. I haven't had time to look into this.

Currently wallaby.js is the only way to run the server tests. There's a ticket open to allow wallaby to run as a cli command, but it's not promised: https://github.com/wallabyjs/public/issues/72

willclarktech commented 8 years ago

Ah of course, got so focused on isomorphism I forgot Karma is just client-side. What would be the benefit of running the server-side tests as part of Karma rather than separately though?

samhatoum commented 8 years ago

Common file watching when in dev mode so the tests rerun on file changes, and having the configuration to run all the tests in one place I guess

You can also setup something like Grunt/Gulp to do the file-watching and to run jasmine.

We're waiting on the final Meteor 1.3 release before seeing how the API works and how we might want to run the server-side tests.

willclarktech commented 8 years ago

That makes sense. Thanks a lot for this repo by the way, really useful stuff.

rjsmith commented 8 years ago

Hi @samhatoum, @Sanjo

I'm also very interested in trying to figure out what options I have to retain my 260+ Meteor v1.2.1 Velocity / Jasmine server integration tests in my project when I upgrade to Meteor v1.3, which is the only thing stopping me from making that move now. The ideas in this best practices repo all make a lot of sense to me, so I am looking forward to seeing an upgrade path to v1.3.

ghost commented 8 years ago

The following instructions may contain small mistakes. Please point out the mistakes, so I can correct them. I currently have very limited time for this stuff.

How to execute tests with sanjo:jasmine and Meteor test runner

1) Install: meteor add sanjo:jasmine 2) Execute: meteor test --full-app --driver-package sanjo:jasmine and then visite your app in the browser. No CI support yet.

How to execute server tests with Jasmine CLI tool (without Wallaby)

1) Copy the following files into your project

2) Add the following devDependencies to package.json. Preferably outside of the meteor app. Inside the meteor app is untested:

    "babel-core": "^6.3.17",
    "babel-plugin-transform-decorators-legacy": "^1.2.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.4.0",
    "babel-plugin-transform-runtime": "^6.3.13",
    "babel-plugin-transform-strict-mode": "^6.3.13",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13",
    "babel-register": "^6.7.2",
    "jasmine": "https://github.com/xolvio/jasmine-npm/archive/29065151846755d6bbad369f506143ebf69b168f.tar.gz",
    "underscore": "^1.8.3"

3) If your app does not use ES2015 modules (untested): remove the following lines of code. This will load all app files before tests execution. It's the same mechanism as meteor test --full-app

4) Adjust the Jasmine options to your needs here: https://github.com/xolvio/automated-testing-best-practices/blob/master/.scripts/jasmine_server_unit/jasmine_server_unit.js#L349-L362. The Jasmine options are documented here: http://jasmine.github.io/2.4/node.html

5) Run the tests with .scripts/jasmine_server_unit/jasmine_server_unit.sh. The same command can be used for CI.

How to execute server tests with with Wallaby

1) Copy the following files into your project

2) Add the following devDependencies to package.json. Preferably outside of the meteor app. Inside the meteor app is untested:

    "babel-core": "^6.3.17",
    "babel-plugin-transform-decorators-legacy": "^1.2.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.4.0",
    "babel-plugin-transform-runtime": "^6.3.13",
    "babel-plugin-transform-strict-mode": "^6.3.13",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13",
    "babel-register": "^6.7.2",
    "jasmine": "https://github.com/xolvio/jasmine-npm/archive/29065151846755d6bbad369f506143ebf69b168f.tar.gz",
    "underscore": "^1.8.3"

3) Adjust the Wallaby options to your needs

4) Install Node.js 0.10.40 with nvm nvm install 0.10.40 the version should match the version that is used by meteor in needs to be changed here: https://github.com/xolvio/automated-testing-best-practices/blob/master/wallaby_server.js#L276

5) Configure the Wallaby runner with the wallaby_server.js config in your IDE and run it.