最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I customize Jasmine's directory structure? - Stack Overflow

programmeradmin3浏览0评论

When using the Jasmine Rubygem, I find it extremely annoying that I have to conform to the generated directory structure which has a javascripts subfolder within the spec folder. I find it useless since I'm writing entirely in Javascript.

I find I can change this within the public folder by changing the generated jasmine.yml, however, this is not what I wanted since I still have to keep the javascripts folder with me.

Is there any way of customizing this folder structure?

When using the Jasmine Rubygem, I find it extremely annoying that I have to conform to the generated directory structure which has a javascripts subfolder within the spec folder. I find it useless since I'm writing entirely in Javascript.

I find I can change this within the public folder by changing the generated jasmine.yml, however, this is not what I wanted since I still have to keep the javascripts folder with me.

Is there any way of customizing this folder structure?

Share Improve this question asked Nov 25, 2011 at 21:30 Casey ChowCasey Chow 1,8144 gold badges19 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Here's how I did this with jasmine gem 1.0.2.1:

1) Customize the jasmine_config.rb file to override the simple_config_file method to point to the correct yml file path. This file is initially generated at spec/javascripts/support/jasmine_config.rb. As seen on the github source (https://github./pivotal/jasmine-gem/blob/v1.0.2.1/lib/jasmine/config.rb), the method is hardcoded to use:

def simple_config_file
  File.join(project_root, 'spec/javascripts/support/jasmine.yml')
end

I wanted to rename my 'spec' directory to 'test' so the top of my jasmine_config.rb file looks like this:

module Jasmine
  class Config
    def simple_config_file
      File.join(project_root, 'test/javascripts/support/jasmine.yml')
    end
  end
end

2) Force rake to load the config file. I did this by adding the line:

require 'test/javascripts/support/jasmine_config.rb'

immediately after requiring jasmine in my Rakefile.

3) Update jasmine.yml (also in the support folder) to indicate where your javascript test files live. My yml file now ends with this:

# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: test/javascripts

Of course, you need to adjust that path "test" to be what you want.

I think this approach should work with the latest version of the gem, but this approach will break in the future if they change the interface of that Config class.

As of 2021, here's how to change the folder name when using the jasmine-browser-runner with NodeJS.

Install jasmine and setup the project:

npm install --save-dev jasmine-browser-runner jasmine-core
npx jasmine-browser-runner init

Rename the spec folder to test and edit jasmine-browser.json:

"specDir": "test"

Run the tests with this mand:

npx jasmine-browser-runner runSpecs --config=test/support/jasmine-browser.json
发布评论

评论列表(0)

  1. 暂无评论