Meteor Testing with Velocity

meteor

#1

I’m trying to get the Velocity Meteor testing framework working on C9. https://ide.c9.io/bwobst/meteor-testing

Velocity works by running tests against a mirrored version of the app that runs in parallel with the real app.

For local environments, the app runs at localhost:3000 and the mirrored app runs on a randomly generated port (e.g. 40062).

On C9 the mirrored app’s logs show that the server boots up, but the tests don’t seem to run.

When I try to access the mirrored app directly, the request just times out.

I think this is because C9 only allows ports 8080, 8081, and 8082 to be used.

Hoping others have figured this out, otherwise I’d have to find a solution other than C9, which would not be cool.


#2

From searching the github codebase for velocity it looks like you can specify a port in the initialization options: https://github.com/meteor-velocity/velocity/search?q=port&type=Code&utf8=✓

You may also need to specify the rootUrl and host options. You can use the environment variable C9_HOSTNAME for these (to get that in Nodejs use the variable process.env.C9_HOSTNAME).

Try running meteor on port 8080 and velocity on port 8081 with rootUrl + host set and it should work and run the tests correctly.


#3

Good suggestion. In order to modify packages you have to add them to your project manually and then make the modifications.

For some reason, after adding the package manually it throws Error: A method named '/velocityTestFiles/insert' is already defined. That happens even without making any modifications. Just a git clone and run it.

If I add the package like normal via meteor add velocity:core, meteor starts up properly, but on a port that C9 doesn’t support.

If I try to edit the package within .meteor/local/build/programs/server/packages/ I get an access denied error.


#4

Hmm, the installed packages should be owned by your user by default, no? If not, can you try using sudo to edit the package?


#5

Turns out I had to keep the package name exactly the same when I installed it locally. I was also able to specify the ports with:

process.env.JASMINE_MIRROR_PORT = 8081; (client port. Source has a typo, should be JASMINE_CLIENT_MIRROR_PORT, that is getting fixed in next release.)
process.env.JASMINE_SERVER_MIRROR_PORT = 8082;

So now I have three tabs open.

https://meteor-testing-bwobst.c9.io:8080 (main app - works)
*:8081 (client tests - error Can't listen on port 8081. Perhaps another Meteor is running?)
*:8082 (server integration tests - works).

I also get this error:

[sanjo:karma]: start request failed { [Error: connect ECONNREFUSED]
W20160202-19:21:04.315(0)? (STDERR) code: 'ECONNREFUSED',
W20160202-19:21:04.315(0)? (STDERR) errno: 'ECONNREFUSED',
W20160202-19:21:04.315(0)? (STDERR) syscall: 'connect' }

#6

I’m trying to use Meteor with Velocity on C9.
For Server Tests, all is working fine.
I just have to specify the port as cloud9 suggest.

meteor --port $IP:$PORT

Unfortunately, this is not the case for Client Test, even when specifying the mirror port and root url.
This is how I did it.

export MONGO_URL=mongodb://localhost:27017/meteor
export JASMINE_MIRROR_PORT=8081;
export JASMINE_SERVER_MIRROR_PORT=8082;
export ROOT_URL=https://callcenter-zied-ziedmahdi.c9users.io

meteor --settings settings.json --port $IP:$PORT

I changed the mongo url so that the port 8081 doesn’t get busy.
By the way, with this configuration even the Server tests are down.
So to inspect the problem, I enabled velocity debugging.

export VELOCITY_DEBUG=1

Here is the log on the main app:

[velocity] adding velocity core
[velocity] Register framework jasmine-client-integration with regex ^tests/jasmine/client/integration/.+\.(js|es6|jsx|coffee|cjsx|litcoffee|coffee\.md)$
[velocity] Velocity not started. Queueing func
[velocity] Register framework jasmine-client-unit with regex ^tests/jasmine/client/unit/.+\.(js|coffee|litcoffee|coffee\.md)$
[velocity] Velocity not started. Queueing func
loaded
Kadira: completed instrumenting the app
[velocity] Server startup
[velocity] app dir /home/ubuntu/workspace
[velocity] config = {
  "jasmine-client-integration": {
    "regex": "^tests/jasmine/client/integration/.+\\.(js|es6|jsx|coffee|cjsx|litcoffee|coffee\\.md)$",
    "name": "jasmine-client-integration",
    "_regexp": {}
  "jasmine-client-unit": {
    "regex": "^tests/jasmine/client/unit/.+\\.(js|coffee|litcoffee|coffee\\.md)$",
    "name": "jasmine-client-unit",
    "_regexp": {}
  },
  }
}
[velocity] resetting the world
[velocity] frameworks with disable auto reset: []
=> Started your app.

=> App running at: https://callcenter-zied-ziedmahdi.c9users.io
[velocity] Add paths to watcher [ '/home/ubuntu/workspace/tests' ]
[velocity] Search framework for path tests/jasmine/client/integration/zSpec.js
[velocity] Target framework for tests/jasmine/client/integration/zSpec.js is jasmine-client-integration
[velocity] Search framework for path tests/jasmine/server/integration/IVRSpec.js
[velocity] No framework registered for tests/jasmine/server/integration/IVRSpec.js
[velocity] File scan complete, now watching /tests
[velocity] Triggering queued startup functions
[sanjo:jasmine]: No tests for jasmine-client-unit found. Reporting completed.
[sanjo:jasmine]: Starting mirror for jasmine-client-integration
[velocity] 1 mirror(s) requested
[velocity] starting mirror { nodes: 1,
  framework: 'jasmine-client-integration',
  port: 8082,
  testsPath: 'jasmine/client/integration' }
[velocity] getting mirror child jasmine-client-integration jasmine-client-integration
[velocity] mirror child not found, creating new long running child process
[velocity] spawning the mirror child { command: 'meteor',
  args: 
   [ 'run',
     '--test-app',
     '--test-app-path',
     '/home/ubuntu/workspace/.meteor/local/mirrors/jasmine-client-integration',
     '--port',
     '8082',
     '--include-tests',
     'jasmine/client/integration',
     '--settings',
     '/tmp/tmp-12771AuPGCAxfTZK.tmp',
     '--release',
     'velocity:METEOR@1.2.1_2' ],
  options: 
   { cwd: '/home/ubuntu/workspace',
     env: 
      { PORT: 8082,
        MIRROR_PORT: 8082,
        HOST: 'https://callcenter-zied-ziedmahdi.c9users.io:8082/',
        ROOT_URL_PATH: '',
        ROOT_URL: 'https://callcenter-zied-ziedmahdi.c9users.io:8082/',
        FRAMEWORK: 'jasmine-client-integration',
        MONGO_URL: 'mongodb://localhost:27017/meteor-jasmine-client-integration',
        PARENT_URL: 'https://callcenter-zied-ziedmahdi.c9users.io',
        IS_MIRROR: true,
        HANDSHAKE: true,
        VELOCITY_MAIN_APP_PATH: '/home/ubuntu/workspace',
        METEOR_SETTINGS: '{"public":{"nodeEnv":"dev"},"appTitle":"CallCenter","senderEmail":"Admin <noreply@callcenter.com>","replyEmail":"Admin <noreply@callcenter.com>","smtpUrl":"smtp://9:744@mailtrap.io:25/","baseUrl":"https://callcenter-zied-ziedmahdi.c9users.io/","accountSid":"A3","authToken":"62","twilioNumber":"+0","expertApplicationSid":"APd0"}',
        NODE_OPTIONS: '',
        MANPATH: '/home/ubuntu/.nvm/versions/node/v4.3.2/share/man:/usr/local/rvm/rubies/ruby-2.3.0/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man:/usr/local/rvm/man',
        APACHE_PID_FILE: '/home/ubuntu/lib/apache2/run/apache2.pid',
        rvm_bin_path: '/usr/local/rvm/bin',
        C9_SHARED: '/mnt/shared',
        NVM_CD_FLAGS: '',
        GEM_HOME: '/usr/local/rvm/gems/ruby-2.3.0',
        C9_FULLNAME: 'ziedmahdi',
        APACHE_RUN_USER: 'ubuntu',
        SHELL: '/bin/bash',
        TERM: 'xterm-256color',
        IRBRC: '/usr/local/rvm/rubies/ruby-2.3.0/.irbrc',
        SSH_CLIENT: '::ffff:10.240.0.26 48502 22',
        NVM_PATH: '/home/ubuntu/.nvm/versions/node/v4.3.2/lib/node',
        ISOUTPUTPANE: '0',
        C9_PORT: '8080',
        OLDPWD: '/home/ubuntu/.meteor/packages/meteor-tool/1.1.10/mt-os.linux.x86_64',
        METEOR_IP: '0.0.0.0',
        MY_RUBY_HOME: '/usr/local/rvm/rubies/ruby-2.3.0',
        PHPRC: '/home/ubuntu/workspace',
        LC_ALL: 'C.UTF-8',
        NVM_DIR: '/home/ubuntu/.nvm',
        USER: 'ubuntu',
        LD_LIBRARY_PATH: '~/.c9/local/lib',
        _system_type: 'Linux',
        rvm_path: '/usr/local/rvm',
        C9_UID: '620715',
        JASMINE_SERVER_INTEGRATION: '0',
        TMUX: '/tmp/tmux-1000/cloud91.8,345,1',
        rvm_prefix: '/usr/local',
        C9_IP: '0.0.0.0',
        APACHE_LOG_DIR: '/home/ubuntu/lib/apache2/log',
        PATH: '/home/ubuntu/.nvm/versions/node/v4.3.2/bin:/usr/local/rvm/gems/ruby-2.3.0/bin:/usr/local/rvm/gems/ruby-2.3.0@global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/mnt/shared/bin:/home/ubuntu/workspace/node_moziedmahdi:~/workspace (expert) $ 

And this is the log of the client mirror

stream error Error during WebSocket handshake: Unexpected response code: 502
stream error Error during WebSocket handshake: Unexpected response code: 502
stream error Error during WebSocket handshake: Unexpected response code: 502

I have looked to many discussions. I didn’t find any solution.

Can anyone help me??