teaspoon-qunit 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/lib/teaspoon-qunit.rb +4 -0
  3. data/lib/teaspoon/qunit/assets/qunit/1.12.0.js +2212 -0
  4. data/lib/teaspoon/qunit/assets/qunit/1.13.0.js +2210 -0
  5. data/lib/teaspoon/qunit/assets/qunit/1.14.0.js +2288 -0
  6. data/lib/teaspoon/qunit/assets/qunit/1.15.0.js +2495 -0
  7. data/lib/teaspoon/qunit/assets/qunit/1.16.0.js +2819 -0
  8. data/lib/teaspoon/qunit/assets/qunit/1.17.1.js +2875 -0
  9. data/lib/teaspoon/qunit/assets/qunit/1.18.0.js +3828 -0
  10. data/lib/teaspoon/qunit/assets/qunit/MIT.LICENSE +21 -0
  11. data/lib/teaspoon/qunit/assets/teaspoon-qunit.js +1529 -0
  12. data/lib/teaspoon/qunit/assets/teaspoon/qunit.coffee +19 -0
  13. data/lib/teaspoon/qunit/assets/teaspoon/qunit/initialize.coffee +11 -0
  14. data/lib/teaspoon/qunit/assets/teaspoon/qunit/reporters/html.coffee +20 -0
  15. data/lib/teaspoon/qunit/assets/teaspoon/qunit/reporters/html/failure_view.coffee +10 -0
  16. data/lib/teaspoon/qunit/assets/teaspoon/qunit/reporters/html/spec_view.coffee +21 -0
  17. data/lib/teaspoon/qunit/assets/teaspoon/qunit/reporters/html/suite_view.coffee +8 -0
  18. data/lib/teaspoon/qunit/assets/teaspoon/qunit/responder.coffee +48 -0
  19. data/lib/teaspoon/qunit/assets/teaspoon/qunit/runner.coffee +12 -0
  20. data/lib/teaspoon/qunit/assets/teaspoon/qunit/spec.coffee +45 -0
  21. data/lib/teaspoon/qunit/assets/teaspoon/qunit/suite.coffee +16 -0
  22. data/lib/teaspoon/qunit/framework.rb +36 -0
  23. data/lib/teaspoon/qunit/templates/test_helper.coffee +29 -0
  24. data/lib/teaspoon/qunit/templates/test_helper.js +30 -0
  25. data/lib/teaspoon/qunit/version.rb +5 -0
  26. data/spec/console_spec.rb +75 -0
  27. data/spec/installation_spec.rb +35 -0
  28. data/spec/integration_spec.rb +73 -0
  29. data/spec/spec_helper.rb +11 -0
  30. data/test/javascripts/integration/_implementation.coffee +1 -0
  31. data/test/javascripts/integration/first_integration.coffee +14 -0
  32. data/test/javascripts/integration/second_integration.coffee +6 -0
  33. data/test/javascripts/integration/test_helper.coffee +9 -0
  34. data/test/javascripts/qunit/fixture_test.coffee +10 -0
  35. data/test/javascripts/qunit/reporters/console_test.coffee +3 -0
  36. data/test/javascripts/qunit/reporters/html/failure_view_test.coffee +3 -0
  37. data/test/javascripts/qunit/reporters/html/spec_view_test.coffee +3 -0
  38. data/test/javascripts/qunit/reporters/html/suite_view_test.coffee +3 -0
  39. data/test/javascripts/qunit/reporters/html_test.coffee +3 -0
  40. data/test/javascripts/qunit/responder_test.coffee +153 -0
  41. data/test/javascripts/qunit/runner_test.coffee +24 -0
  42. data/test/javascripts/qunit/spec_test.coffee +53 -0
  43. data/test/javascripts/qunit/suite_test.coffee +10 -0
  44. data/test/javascripts/test_helper.coffee +4 -0
  45. data/test/teaspoon_env.rb +12 -0
  46. metadata +124 -0
@@ -0,0 +1,19 @@
1
+ #= require teaspoon/teaspoon
2
+ #= require_self
3
+ #= require_tree ./qunit
4
+
5
+ unless QUnit?
6
+ throw new Teaspoon.Error('QUnit not found -- use `suite.use_framework :qunit` and adjust or remove the `suite.javascripts` directive.')
7
+
8
+ @Teaspoon ?= {}
9
+ @Teaspoon.Qunit = {
10
+ version: ->
11
+ versions = @rawVersion().split('.')
12
+ {major: versions[0], minor: versions[1], patch: versions[2]}
13
+
14
+
15
+ rawVersion: ->
16
+ QUnit.version || _qunit_version
17
+ }
18
+ @Teaspoon.Qunit.Reporters ?= {}
19
+ @Teaspoon.Qunit.Reporters.HTML ?= {}
@@ -0,0 +1,11 @@
1
+ Teaspoon.setFramework(Teaspoon.Qunit)
2
+
3
+ # set the environment
4
+ QUnit.config.autostart = false
5
+ QUnit.config.altertitle = false
6
+ QUnit.config.filter = Teaspoon.Runner.prototype.getParams()["grep"]
7
+
8
+ originalReset = QUnit.reset
9
+ QUnit.reset = ->
10
+ originalReset()
11
+ Teaspoon.Fixture.cleanup()
@@ -0,0 +1,20 @@
1
+ #= require teaspoon/reporters/html
2
+
3
+ class Teaspoon.Qunit.Reporters.HTML extends Teaspoon.Reporters.HTML
4
+
5
+ reportRunnerResults: (runner) ->
6
+ version = Teaspoon.Qunit.version()
7
+ if version.major = 1 && version.minor < 16
8
+ # QUnit <= 1.15 doesn't provide the total until all tests are finished
9
+ # The .begin hook is broken
10
+ @total.exist = @total.run = runner.total
11
+ super
12
+
13
+
14
+ readConfig: ->
15
+ super
16
+ QUnit.config.notrycatch = @config["use-catch"]
17
+
18
+
19
+ envInfo: ->
20
+ "qunit #{Teaspoon.Qunit.rawVersion() || "[unknown version]"}"
@@ -0,0 +1,10 @@
1
+ #= require teaspoon/reporters/html/failure_view
2
+
3
+ class Teaspoon.Qunit.Reporters.HTML.FailureView extends Teaspoon.Reporters.HTML.FailureView
4
+
5
+ build: ->
6
+ super("spec")
7
+ html = """<h1 class="teaspoon-clearfix"><a href="#{@spec.link}">#{@htmlSafe(@spec.fullDescription)}</a></h1>"""
8
+ for error in @spec.errors()
9
+ html += """<div><strong>#{error.message}</strong><br/>#{@htmlSafe(error.stack || "Stack trace unavailable")}</div>"""
10
+ @el.innerHTML = html
@@ -0,0 +1,21 @@
1
+ #= require teaspoon/reporters/html/spec_view
2
+
3
+ class Teaspoon.Qunit.Reporters.HTML.SpecView extends Teaspoon.Reporters.HTML.SpecView
4
+
5
+ buildErrors: ->
6
+ div = @createEl("div")
7
+ html = ""
8
+ for error in @spec.errors()
9
+ html += """<strong>#{error.message}</strong><br/>#{@htmlSafe(error.stack || "Stack trace unavailable")}<br/>"""
10
+ div.innerHTML = html
11
+ @append(div)
12
+
13
+
14
+ buildParent: ->
15
+ parent = @spec.parent
16
+ return @reporter unless parent
17
+ if @views.suites[parent.description]
18
+ @views.suites[parent.description]
19
+ else
20
+ view = new Teaspoon.Qunit.Reporters.HTML.SuiteView(parent, @reporter)
21
+ @views.suites[parent.description] = view
@@ -0,0 +1,8 @@
1
+ #= require teaspoon/reporters/html/suite_view
2
+
3
+ class Teaspoon.Qunit.Reporters.HTML.SuiteView extends Teaspoon.Reporters.HTML.SuiteView
4
+
5
+ constructor: (@suite, @reporter) ->
6
+ @views = @reporter.views
7
+ @views.suites[@suite.description] = @
8
+ @build()
@@ -0,0 +1,48 @@
1
+ class Teaspoon.Qunit.Responder
2
+
3
+ constructor: (qunit, @reporter) ->
4
+ version = Teaspoon.Qunit.version()
5
+ if version.major = 1 && version.minor > 15
6
+ qunit.begin(@runnerStarted)
7
+ else
8
+ # QUnit's .begin hook was broken
9
+ @reporter.reportRunnerStarting(total: null)
10
+
11
+ qunit.done(@runnerDone)
12
+ qunit.moduleStart(@suiteStarted)
13
+ qunit.moduleDone(@suiteDone)
14
+ qunit.testDone(@specDone)
15
+ qunit.log(@assertionDone)
16
+
17
+ @assertions = []
18
+
19
+
20
+ runnerStarted: (runner) =>
21
+ @reporter.reportRunnerStarting(total: runner.totalTests)
22
+
23
+
24
+ runnerDone: (runner) =>
25
+ @reporter.reportRunnerResults(runner)
26
+
27
+
28
+ suiteStarted: (suite) =>
29
+ @reporter.reportSuiteStarting(new Teaspoon.Qunit.Suite(suite))
30
+
31
+
32
+ suiteDone: (suite) =>
33
+ @reporter.reportSuiteResults(new Teaspoon.Qunit.Suite(suite))
34
+
35
+
36
+ specDone: (spec) =>
37
+ spec.assertions = @assertions
38
+ @assertions = []
39
+
40
+ # QUnit doesn't have details about the spec until it's finished. So we
41
+ # wait until it's finished to report that it started.
42
+ spec = new Teaspoon.Qunit.Spec(spec)
43
+ @reporter.reportSpecStarting(spec)
44
+ @reporter.reportSpecResults(spec)
45
+
46
+
47
+ assertionDone: (assertion) =>
48
+ @assertions.push(assertion)
@@ -0,0 +1,12 @@
1
+ #= require teaspoon/runner
2
+
3
+ class Teaspoon.Qunit.Runner extends Teaspoon.Runner
4
+
5
+ constructor: ->
6
+ super
7
+ QUnit.start()
8
+
9
+
10
+ setup: ->
11
+ reporter = new (@getReporter())()
12
+ new Teaspoon.Qunit.Responder(QUnit, reporter)
@@ -0,0 +1,45 @@
1
+ class Teaspoon.Qunit.Spec
2
+
3
+ constructor: (@spec) ->
4
+ @fullDescription = "#{@spec.module} #{@spec.name}"
5
+ @description = "#{@spec.name} (#{@spec.failed}, #{@spec.passed}, #{@spec.total})"
6
+ @link = "?grep=#{encodeURIComponent("#{@spec.module}: #{@spec.name}")}"
7
+ @parent = if @spec.module then new Teaspoon.Qunit.Suite({description: @spec.module}) else null
8
+ @suiteName = @spec.module
9
+ @viewId = @spec.viewId
10
+ @pending = false
11
+
12
+
13
+ errors: ->
14
+ return [] unless @spec.failed
15
+ for item in @spec.assertions
16
+ continue if item.result
17
+ @provideFallbackMessage(item)
18
+ {message: item.message, stack: item.source}
19
+
20
+
21
+ getParents: ->
22
+ return [] unless @parent
23
+ [@parent]
24
+
25
+
26
+ result: ->
27
+ status = "failed"
28
+ status = "passed" if @spec.failed == 0
29
+ status: status
30
+ skipped: false
31
+
32
+
33
+ provideFallbackMessage: (item) ->
34
+ return if item.message
35
+
36
+ if item.actual && item.expected
37
+ item.message ||= "Expected #{JSON.stringify(item.actual)} to equal #{JSON.stringify(item.expected)}"
38
+ else
39
+ item.message = 'failed'
40
+
41
+
42
+ # Shim since core still initializes this class, but the argument
43
+ # is the real spec object passed in from the responder.
44
+ class Teaspoon.Spec
45
+ constructor: (spec) -> return spec
@@ -0,0 +1,16 @@
1
+ class Teaspoon.Qunit.Suite
2
+
3
+ constructor: (@suite) ->
4
+ # In QUnit 1.14, moduleStart uses @suite.name,
5
+ # moduleDone uses @suite.description
6
+ @fullDescription = @suite.description || @suite.name
7
+ @description = @suite.description || @suite.name
8
+ @link = "?grep=#{encodeURIComponent(@fullDescription)}"
9
+ @parent = null
10
+
11
+
12
+ # Shim since HTML.SuiteView still initializes the base class.
13
+ # TODO: inject instance into SuiteView
14
+ class Teaspoon.Suite
15
+ constructor: (suite) ->
16
+ return new Teaspoon.Qunit.Suite(suite)
@@ -0,0 +1,36 @@
1
+ require "teaspoon/framework/base"
2
+
3
+ module Teaspoon
4
+ module Qunit
5
+ class Framework < Teaspoon::Framework::Base
6
+ # specify the framework name
7
+ framework_name :qunit
8
+
9
+ # register standard versions
10
+ versions = ["1.12.0", "1.13.0", "1.14.0", "1.15.0", "1.16.0", "1.17.1", "1.18.0"]
11
+
12
+ versions.each do |version|
13
+ register_version version, "qunit/#{version}.js",
14
+ dependencies: ["teaspoon-qunit.js"],
15
+ dev_deps: ["teaspoon/qunit.js"]
16
+ end
17
+
18
+ # add asset paths
19
+ add_asset_path File.expand_path("../../../teaspoon/qunit/assets", __FILE__)
20
+
21
+ # add custom install templates
22
+ add_template_path File.expand_path("../../../teaspoon/qunit/templates", __FILE__)
23
+
24
+ # specify where to install, and add installation steps.
25
+ install_to "test" do
26
+ ext = options[:coffee] ? ".coffee" : ".js"
27
+ copy_file "test_helper#{ext}", "test/javascripts/test_helper#{ext}"
28
+ end
29
+
30
+ def self.modify_config(config)
31
+ config.matcher = "{test/javascripts,app/assets}/**/*_test.{js,js.coffee,coffee}"
32
+ config.helper = "test_helper"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ # Teaspoon includes some support files, but you can use anything from your own support path too.
2
+ # require support/sinon
3
+ # require support/your-support-file
4
+ #
5
+ # PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
6
+ # Use this polyfill to avoid the confusion.
7
+ #= require support/bind-poly
8
+ #
9
+ # You can require your own javascript files here. By default this will include everything in application, however you
10
+ # may get better load performance if you require the specific files that are being used in the test that tests them.
11
+ #= require application
12
+ #
13
+ # Deferring execution
14
+ # If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
15
+ # Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
16
+ #
17
+ # Teaspoon.defer = true
18
+ # setTimeout(Teaspoon.execute, 1000)
19
+ #
20
+ # Matching files
21
+ # By default Teaspoon will look for files that match _test.{js,js.coffee,.coffee}. Add a filename_test.js file in your
22
+ # test path and it'll be included in the default suite automatically. If you want to customize suites, check out the
23
+ # configuration in teaspoon_env.rb
24
+ #
25
+ # Manifest
26
+ # If you'd rather require your test files manually (to control order for instance) you can disable the suite matcher in
27
+ # the configuration and use this file as a manifest.
28
+ #
29
+ # For more information: http://github.com/modeset/teaspoon
@@ -0,0 +1,30 @@
1
+ // Teaspoon includes some support files, but you can use anything from your own support path too.
2
+ // require support/sinon
3
+ // require support/your-support-file
4
+ //
5
+ // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
6
+ // Use this polyfill to avoid the confusion.
7
+ //= require support/bind-poly
8
+ //
9
+ // You can require your own javascript files here. By default this will include everything in application, however you
10
+ // may get better load performance if you require the specific files that are being used in the test that tests them.
11
+ //= require application
12
+ //
13
+ // Deferring execution
14
+ // If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
15
+ // Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
16
+ //
17
+ // Teaspoon.defer = true
18
+ // setTimeout(Teaspoon.execute, 1000)
19
+ //
20
+ // Matching files
21
+ // By default Teaspoon will look for files that match _test.{js,js.coffee,.coffee}. Add a filename_test.js file in your
22
+ // test path and it'll be included in the default suite automatically. If you want to customize suites, check out the
23
+ // configuration in teaspoon_env.rb
24
+ //
25
+ // Manifest
26
+ // If you'd rather require your test files manually (to control order for instance) you can disable the suite matcher in
27
+ // the configuration and use this file as a manifest.
28
+ //
29
+ // For more information: http://github.com/modeset/teaspoon
30
+
@@ -0,0 +1,5 @@
1
+ module Teaspoon
2
+ module Qunit
3
+ VERSION = "1.18.0"
4
+ end
5
+ end
@@ -0,0 +1,75 @@
1
+ require_relative "./spec_helper"
2
+
3
+ feature "Running in the console", shell: true do
4
+ let(:expected_loading_output) do
5
+ <<-OUTPUT.strip_heredoc
6
+ Starting the Teaspoon server...
7
+ Teaspoon running default suite at http://127.0.0.1:31337/teaspoon/default
8
+ OUTPUT
9
+ end
10
+
11
+ let(:expected_testing_output) do
12
+ <<-OUTPUT.strip_heredoc
13
+ FFFit can log to the console
14
+ ..
15
+
16
+ Failures:
17
+
18
+ 1) global failure (1, 0, 1)
19
+ Failure/Error: TypeError: undefined is not a constructor (evaluating 'foo()')
20
+
21
+ 2) Integration tests allows failing specs (1, 0, 1)
22
+ Failure/Error: fails correctly
23
+
24
+ 3) Integration tests allows erroring specs (1, 0, 1)
25
+ Failure/Error: errors correctly
26
+
27
+ Finished in 0.31337 seconds
28
+ 5 examples, 3 failures
29
+
30
+ Failed examples:
31
+
32
+ teaspoon -s default --filter=" global failure"
33
+ teaspoon -s default --filter="Integration tests allows failing specs"
34
+ teaspoon -s default --filter="Integration tests allows erroring specs"
35
+ OUTPUT
36
+ end
37
+
38
+ let(:version) do
39
+ Teaspoon::Framework.fetch(:qunit).versions.last
40
+ end
41
+
42
+ before do
43
+ teaspoon_test_app("gem 'teaspoon-qunit', path: '#{Teaspoon::DEV_PATH}'")
44
+ install_teaspoon("--coffee --version=#{version}")
45
+ copy_integration_files("test", File.expand_path("../../test", __FILE__), "test")
46
+ end
47
+
48
+ it "runs successfully using the CLI" do
49
+ run_teaspoon("--no-color")
50
+
51
+ expect(teaspoon_output).to include(expected_loading_output)
52
+ expect(teaspoon_output).to include(expected_testing_output)
53
+ end
54
+
55
+ it "runs successfully using the rake task" do
56
+ rake_teaspoon("COLOR=false")
57
+
58
+ expect(teaspoon_output).to include(expected_loading_output)
59
+ expect(teaspoon_output).to include(expected_testing_output)
60
+ end
61
+
62
+ it "can display coverage information" do
63
+ pending("needs istanbul to be installed") unless Teaspoon::Instrumentation.executable
64
+ run_teaspoon("--coverage=default")
65
+
66
+ expect(teaspoon_output).to include(<<-COVERAGE.strip_heredoc)
67
+ =============================== Coverage summary ===============================
68
+ Statements : 75% ( 3/4 )
69
+ Branches : 100% ( 0/0 )
70
+ Functions : 50% ( 1/2 )
71
+ Lines : 75% ( 3/4 )
72
+ ================================================================================
73
+ COVERAGE
74
+ end
75
+ end
@@ -0,0 +1,35 @@
1
+ require_relative "./spec_helper"
2
+
3
+ feature "Installation", shell: true do
4
+ before do
5
+ teaspoon_test_app("gem 'teaspoon-qunit', path: '#{Teaspoon::DEV_PATH}'")
6
+ end
7
+
8
+ it "installs the expected files" do
9
+ install_teaspoon
10
+
11
+ expect(all_output).to include(<<-OUTPUT)
12
+ create test/teaspoon_env.rb
13
+ create test/javascripts/support
14
+ create test/javascripts/fixtures
15
+ create test/javascripts/test_helper.js
16
+ OUTPUT
17
+
18
+ check_file_content("test/teaspoon_env.rb", /suite\.use_framework :qunit, "\d+\.\d+\.\d+"/)
19
+ check_file_content("test/javascripts/test_helper.js", Regexp.new("require support/your-support-file"))
20
+ end
21
+
22
+ it "can install coffeescript and the teaspoon_env without comments" do
23
+ install_teaspoon("--coffee --no-comments")
24
+
25
+ expect(all_output).to include(<<-OUTPUT)
26
+ create test/teaspoon_env.rb
27
+ create test/javascripts/support
28
+ create test/javascripts/fixtures
29
+ create test/javascripts/test_helper.coffee
30
+ OUTPUT
31
+
32
+ check_file_content("test/teaspoon_env.rb", /suite\.use_framework :qunit, "\d+\.\d+\.\d+"/)
33
+ check_file_content("test/javascripts/test_helper.coffee", Regexp.new("require support/your-support-file"))
34
+ end
35
+ end