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

Custom boot for Node #29

Closed
mattheworiordan opened this issue Feb 18, 2015 · 11 comments
Closed

Custom boot for Node #29

mattheworiordan opened this issue Feb 18, 2015 · 11 comments

Comments

@mattheworiordan
Copy link

The custom boot.js file introduced in 2.0 is a great addition, however I am trying to figure out how to use jasmine with Node with a custom boot.js file, and so far the only way I seem to be able to get this to work is to invoke the Jasmine Runner directly from a Grunt script as opposed to using the jasmine command line script.

I have worked around this issue easily when running the entire test suite using helpers, however when I run a single spec such as jasmine spec/whatever.spec.js the helpers are not loaded.

I have also tried adding a boot_files option to my jasmine.json file without luck.

Is there a recommended way with node to inject your own custom boot?

On a slightly separate note, I see in https://github.com/jasmine/jasmine-npm/blob/master/lib/jasmine.js#L45-L46 that you automatically add the default console reporter. If I want to use a different reporter, it seems unfortunately there is no way to do that because the API only exposes an addReporter method. Any thoughts on how to address that?

@mattheworiordan
Copy link
Author

Whilst getting custom boot to work may be a bit more challenging, do you think the fact that the helpers are not loaded when a specific test is specified is a bug? If so, perhaps I should create a PR to resolve that bug in the mean time?

@amavisca
Copy link
Member

It probably makes sense for the CLI to use the jasmine.json configuration as defaults that the CLI then overrides. You could file an issue/PR for the helper files not being loaded.

When you add a reporter, the default reporter is no longer added.

There is no boot_files option for jasmine.json. Right now you can not use a custom boot from the command line. All this module does for booting is use the boot exposed by the jasmine-core module. You can optionally pass in a jasmineCore to this module, so you could just pass in your own instance of jasmineCore and then define your own boot method on the core. https://github.com/jasmine/jasmine-npm/blob/master/lib/jasmine.js#L14

@slackersoft
Copy link
Member

@mattheworiordan What are you trying to do in a boot file? Are you able to solve your problems with a helper file instead? Right now there's a bug in tracker for fixing helper file loading when specifying files to run on the command line.

If this gets fixed so helpers are always loaded correctly, does this fix your issue?

@whitehat101
Copy link

I'm in a similar situation. I'm trying to load BabelJS through the boot.js. I have a "working" setup with gulp, but I'm hoping to run a single spec with the jasmine CLI without pre-compiling my source/spec.

@mattheworiordan
Copy link
Author

Sorry for the slow reply on this. In the end I actually abandoned Jasmine as I just couldn't get it to behave the way I needed, not specifically this issue though.

In terms of why I could not use helpers, yes, I expect when that bug is fixed that would have solved my problem indeed. Thanks.

@slackersoft
Copy link
Member

@whitehat101 The helper files should be loaded properly even when specifying files to execute now on master. If you get a chance, can you take a look and see if adding a helper that does the extra stuff you want in a boot solves your problem? If not, we'd like to know what would need to be added to make a helper file sufficient.

Thanks for using jasmine!

@slackersoft
Copy link
Member

The fix for loading helper files properly should be released with 2.3 now. From what I can tell that should solve this issue, so I'm going to close it.

@jedwards1211
Copy link

I'm trying to use something like the custom_boot.js to make a webpack loader for Jasmine tests, so that it can inject the Jasmine methods into test modules. This is also necessary because I'm using Meteor, which also injects variables, and they wouldn't be present if I let Jasmine run the tests itself. The way both Meteor and Jasmine prefer to load and run js files themselves really gets in the way of interoperability, it makes the developer jump through hoops. Meteor's Velocity test framework has figured out how to run things with Jasmine, but Velocity has some severe limitations (e.g. you can't do anything like Karma as far as I know).

@slackersoft
Copy link
Member

@jedwards1211 if you're looking to run the tests in a browser, you want to just go straight to jasmine-core, which is just the base jasmine files. You might also see if something like gulp-jasmine-browser will work for you, it should be capable of doing a webpack server as well.

@jedwards1211
Copy link

I'm running both server and client-side tests. Here is my somewhat hacky workaround:

  • Use a custom Webpack loader for test modules. It wraps them in function(jasmine) and at the top of the function, uses eval to put everything in jasmine.getEnv() on the local scope.
  • Inside the Velocity Jasmine test scripts, I call those functions, passing the fake jasmine whose getEnv() returns the Jasmine globals on the local scope of the Velocity Jasmine test scripts.

@thabti
Copy link

thabti commented Nov 28, 2015

@whitehat101

I thought I would add to this, I managed to include a boot.js file by doing the follow:

{
  "spec_dir": "app/server/",
  "spec_files": [
    "../../.utilities/boot.js", //this
    "**/*.test.js"
  ],
  "helpers": [
    "helpers/**/*.js"
  ]
}

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

6 participants