Permalink
Browse files

Merge pull request #331 from vojtajina/using-di

Refactor Testacular to use DI and enable plugins
  • Loading branch information...
2 parents 0cc6e13 + 4e233e5 commit 8e2011dc3fcd471f6bfa0b76a8951ea56c14bc3e @vojtajina vojtajina committed Mar 2, 2013
Showing with 544 additions and 40,541 deletions.
  1. +4 −0 .travis.yml
  2. +10 −35 Gruntfile.coffee
  3. +2 −1 Testacular.sublime-project
  4. +0 −88 adapter/angular-scenario.src.js
  5. +0 −7 adapter/angular-scenario.wrapper
  6. +0 −123 adapter/jasmine.src.js
  7. +0 −11 adapter/jasmine.wrapper
  8. +0 −26,120 adapter/lib/angular-scenario.js
  9. +0 −2,683 adapter/lib/jasmine.js
  10. +0 −4,868 adapter/lib/mocha.js
  11. +0 −1,977 adapter/lib/qunit.js
  12. +0 −1,981 adapter/lib/require.js
  13. +0 −98 adapter/mocha.src.js
  14. +0 −12 adapter/mocha.wrapper
  15. +0 −56 adapter/qunit.src.js
  16. +0 −10 adapter/qunit.wrapper
  17. +0 −37 adapter/require.src.js
  18. +0 −11 adapter/require.wrapper
  19. +0 −206 junit-schema.xsd
  20. +1 −1 lib/browser.js
  21. +22 −22 lib/cli.js
  22. +31 −12 lib/config.js
  23. +5 −2 lib/file-list.js
  24. +12 −5 lib/init.js
  25. +26 −27 lib/launcher.js
  26. +9 −2 lib/launchers/Base.js
  27. +0 −34 lib/launchers/Chrome.js
  28. +0 −27 lib/launchers/ChromeCanary.js
  29. +0 −53 lib/launchers/Firefox.js
  30. +0 −17 lib/launchers/IE.js
  31. +0 −76 lib/launchers/Opera.js
  32. +0 −33 lib/launchers/PhantomJS.js
  33. +0 −36 lib/launchers/Safari.js
  34. +17 −0 lib/launchers/Script.js
  35. +11 −17 lib/preprocessor.js
  36. +0 −19 lib/preprocessors/Coffee.js
  37. +0 −18 lib/preprocessors/Coverage.js
  38. +0 −24 lib/preprocessors/Html2js.js
  39. +0 −20 lib/preprocessors/Live.js
  40. +2 −2 lib/proxy.js
  41. +26 −29 lib/reporter.js
  42. +8 −0 lib/reporters/Base.js
  43. +1 −1 lib/reporters/BaseColor.js
  44. +0 −119 lib/reporters/Coverage.js
  45. +0 −66 lib/reporters/Growl.js
  46. +0 −101 lib/reporters/JUnit.js
  47. +1 −2 lib/reporters/Multi.js
  48. +2 −2 lib/reporters/Progress.js
  49. +0 −125 lib/reporters/Teamcity.js
  50. BIN lib/reporters/images/error.png
  51. BIN lib/reporters/images/failed.png
  52. BIN lib/reporters/images/success.png
  53. +55 −31 lib/server.js
  54. +2 −0 lib/watcher.js
  55. +9 −4 lib/web-server.js
  56. +23 −9 package.json
  57. +0 −13 static/safari.html
  58. +1 −0 static/testacular.src.js
  59. +6 −3 tasks/bump.js
  60. +1 −1 tasks/contributors.js
  61. +2 −3 tasks/lib/changelog.js
  62. +0 −3 tasks/lib/validate-commit-msg.js
  63. +2 −2 tasks/npm.js
  64. +2 −1 tasks/test.js
  65. +0 −127 test/client/angular-scenario.spec.js
  66. +0 −185 test/client/jasmine.spec.js
  67. +0 −128 test/client/mocha.spec.js
  68. +0 −16 test/client/mocks.js
  69. +0 −261 test/client/mocks/ObjectModel.js
  70. +0 −76 test/client/qunit.spec.js
  71. +0 −41 test/client/require.spec.js
  72. +10 −6 test/client/testacular.conf.js
  73. +12 −3 test/e2e/angular-scenario/testacular.conf.js
  74. +10 −4 test/e2e/basic/testacular.conf.js
  75. +10 −3 test/e2e/coffee/testacular.conf.js
  76. +9 −2 test/e2e/coverage/testacular.conf.js
  77. +9 −2 test/e2e/coverageQunit/testacular.conf.js
  78. +2 −1 test/e2e/coverageRequirejs/test.js
  79. +10 −5 test/e2e/coverageRequirejs/testacular.conf.js
  80. +8 −2 test/e2e/junit/testacular.conf.js
  81. +11 −3 test/e2e/mocha/testacular.conf.js
  82. +10 −4 test/e2e/qunit/testacular.conf.js
  83. +1 −1 test/e2e/requirejs/main.js
  84. +9 −6 test/e2e/requirejs/testacular.conf.js
  85. +12 −3 test/e2e/syntax-error/testacular.conf
  86. +7 −2 test/e2e/timeout/testacular.conf.ignore.js
  87. +0 −24 test/mocha-common.js
  88. +2 −6 test/tasks/lib/validate-commit-msg.spec.coffee
  89. +12 −0 test/tasks/mocha-globals.coffee
  90. +0 −1 test/unit/config.spec.coffee
  91. +66 −84 test/unit/launcher.spec.coffee
  92. +1 −49 test/unit/logger.spec.coffee
  93. +26 −0 test/unit/mocha-globals.coffee
  94. +13 −19 test/unit/preprocessor.spec.coffee
  95. +0 −34 test/unit/preprocessors/Html2js.spec.coffee
  96. +1 −1 test/unit/reporter.spec.coffee
  97. +0 −156 test/unit/reporters/Coverage.spec.coffee
View
@@ -2,6 +2,10 @@ language: node_js
node_js:
- 0.8
+before_install:
+ - mkdir node_modules
+ - ln -s .. node_modules/testacular
+
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
View
@@ -16,24 +16,14 @@ module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
pkgFile: 'package.json'
-
+
files:
server: ['lib/**/*.js']
client: ['static/testacular.src.js']
- jasmine: ['adapter/jasmine.src.js']
- mocha: ['adapter/mocha.src.js']
- ngScenario: ['adapter/angular-scenario.src.js']
- require: ['adapter/require.src.js']
- qunit: ['adapter/qunit.src.js']
grunt: ['grunt.js', 'tasks/**/*.js']
build:
client: '<%= files.client %>'
- jasmine: '<%= files.jasmine %>'
- mocha: '<%= files.mocha %>'
- ngScenario: '<%= files.ngScenario %>'
- require: '<%= files.require %>'
- qunit: '<%= files.qunit %>'
test:
unit: 'simplemocha:unit'
@@ -48,12 +38,12 @@ module.exports = (grunt) ->
reporter: 'dot'
unit:
src: [
- 'test/mocha-common.js'
+ 'test/unit/mocha-globals.coffee'
'test/unit/**/*.coffee'
]
tasks:
src: [
- 'test/mocha-common.js'
+ 'test/tasks/mocha-globals.coffee'
'test/tasks/**/*.coffee'
]
@@ -72,29 +62,11 @@ module.exports = (grunt) ->
files:
src: '<%= files.client %>'
options: JSHINT_BROWSER
- jasmine:
- files:
- src: '<%= files.jasmine %>'
- options: JSHINT_BROWSER
- mocha:
- files:
- src: '<%= files.mocha %>'
- options: JSHINT_BROWSER
- qunit:
- files:
- src: '<%= files.qunit %>'
- options: JSHINT_BROWSER
- ngScenario:
- files:
- src: '<%= files.ngScenario %>'
- options: JSHINT_BROWSER
- require:
- files:
- src: '<%= files.require %>'
- options: JSHINT_BROWSER
-
+
options:
quotmark: 'single'
+ bitwise: true
+ indent: 2
camelcase: true
strict: true
trailing: true
@@ -103,10 +75,13 @@ module.exports = (grunt) ->
immed: true
latedef: true
newcap: true
+ noempty: true
+ unused: true
noarg: true
sub: true
undef: true
- boss: true
+ maxdepth: 4
+ maxlen: 100
globals: {}
grunt.loadTasks 'tasks'
@@ -35,7 +35,8 @@
"open_related_patterns": [
["*/lib/*.js", "*/test/unit/*.spec.coffee"],
["*/adapter/*.src.js", "*/test/client/*.spec.js"],
- ["*/static/*.src.js", "*/test/client/*.spec.js"]
+ ["*/static/*.src.js", "*/test/client/*.spec.js"],
+ ["*/tasks/*.js", "*/test/tasks/*.spec.coffee"]
],
"build_switcher_systems": ["Unit tests", "Task tests", "Client tests"]
}
@@ -1,88 +0,0 @@
-var registerResultListeners = function(model, tc) {
- var totalTests = 0, testsCompleted = 0;
-
- var createFailedSpecLog = function(spec) {
- var failedStep = findFailedStep(spec.steps);
- var specError = spec.line ? spec.line + ': ' + spec.error.toString() : spec.error.toString();
-
- return failedStep ? [failedStep.name, specError] : [specError];
- };
-
- var findFailedStep = function(steps) {
- var stepCount = steps.length;
- for(var i = 0; i < stepCount; i++) {
- var step = steps[i];
-
- if (step.status === 'failure') {
- return step;
- }
- }
-
- return null;
- };
-
- model.on('RunnerBegin', function() {
- totalTests = angular.scenario.Describe.specId;
- tc.info({total: totalTests});
- });
-
- model.on('SpecEnd', function(spec) {
- // TODO(vojta): create Result type
- var result = {
- id: spec.id,
- description: spec.name,
- suite: [spec.fullDefinitionName],
- success: spec.status === 'success',
- skipped: false,
- time: spec.duration,
- log: []
- };
-
- if (spec.error) {
- result.log = createFailedSpecLog(spec);
- }
-
- testsCompleted++;
- tc.result(result);
- });
-
- model.on('RunnerEnd', function() {
- var skippedTests = totalTests - testsCompleted;
-
- // Inform Testacular about number of skipped tests
- // TODO(vojta): report proper suite/description (need to fix the scenario runner first)
- for (var i = 0; i < skippedTests; i++) {
- tc.result({
- id: 'Skipped' + (i + 1),
- description: 'Skipped' + (i + 1),
- suite: [],
- skipped: true,
- time: 0,
- log: []
- });
- }
-
- tc.complete({
- coverage: window.__coverage__
- });
- });
-};
-
-/**
- *
- * @param {Object} tc Testacular!!
- * @param {Function} scenarioSetupAndRun angular.scenario.setUpAndRun
- * @return {Function}
- */
-var createNgScenarioStartFn = function(tc, scenarioSetupAndRun) {
- /**
- * Generates Testacular Output
- */
- angular.scenario.output('testacular', function(context, runner, model) {
- registerResultListeners(model, tc);
- });
-
- return function(config) {
- scenarioSetupAndRun({scenario_output: 'testacular,html'});
- };
-};
@@ -1,7 +0,0 @@
-(function(window) {
-
-%CONTENT%
-
-window.__testacular__.start = createNgScenarioStartFn(window.__testacular__, angular.scenario.setUpAndRun);
-
-})(window);
View
@@ -1,123 +0,0 @@
-var formatFailedStep = function(step) {
-
- var stack = step.trace.stack;
- var message = step.message;
- if (stack) {
- // remove the trailing dot
- var firstLine = stack.substring(0, stack.indexOf('\n') - 1);
- if (message && message.indexOf(firstLine) === -1) {
- stack = message + '\n' + stack;
- }
-
- // remove jasmine stack entries
- return stack.replace(/\n.+jasmine\.js\?\d*\:.+(?=(\n|$))/g, '');
- }
-
- return message;
-};
-
-var indexOf = function(collection, item) {
- if (collection.indexOf) {
- return collection.indexOf(item);
- }
-
- for (var i = 0, ii = collection.length; i < ii; i++) {
- if (collection[i] === item) {
- return i;
- }
- }
-
- return -1;
-};
-
-
-/**
- * Very simple reporter for jasmine
- */
-var TestacularReporter = function(tc) {
-
- this.reportRunnerStarting = function(runner) {
- tc.info({total: runner.specs().length});
- };
-
- this.reportRunnerResults = function(runner) {
- tc.complete({
- coverage: window.__coverage__
- });
- };
-
- this.reportSuiteResults = function(suite) {
- // memory clean up
- suite.after_ = null;
- suite.before_ = null;
- suite.queue = null;
- };
-
- this.reportSpecStarting = function(spec) {
- spec.results_.time = new Date().getTime();
- };
-
- this.reportSpecResults = function(spec) {
- var result = {
- id: spec.id,
- description: spec.description,
- suite: [],
- success: spec.results_.failedCount === 0,
- skipped: spec.results_.skipped,
- time: spec.results_.skipped ? 0 : new Date().getTime() - spec.results_.time,
- log: []
- };
-
- var suitePointer = spec.suite;
- while (suitePointer) {
- result.suite.unshift(suitePointer.description);
- suitePointer = suitePointer.parentSuite;
- }
-
- if (!result.success) {
- var steps = spec.results_.items_;
- for (var i = 0; i < steps.length; i++) {
- if (!steps[i].passed_) {
- result.log.push(formatFailedStep(steps[i]));
- }
- }
- }
-
- tc.result(result);
-
- // memory clean up
- spec.results_ = null;
- spec.spies_ = null;
- spec.queue = null;
- };
-
- this.log = function() {};
-};
-
-
-var createStartFn = function(tc, jasmineEnvPassedIn) {
- return function(config) {
- // we pass jasmineEnv during testing
- // in production we ask for it lazily, so that adapter can be loaded even before jasmine
- var jasmineEnv = jasmineEnvPassedIn || window.jasmine.getEnv();
-
- jasmineEnv.addReporter(new TestacularReporter(tc));
- jasmineEnv.execute();
- };
-};
-
-
-var createDumpFn = function(tc, serialize) {
- return function() {
-
- var args = Array.prototype.slice.call(arguments, 0);
-
- if (serialize) {
- for (var i = 0; i < args.length; i++) {
- args[i] = serialize(args[i]);
- }
- }
-
- tc.info({dump: args});
- };
-};
View
@@ -1,11 +0,0 @@
-(function(window) {
-
-%CONTENT%
-
-
-window.__testacular__.start = createStartFn(window.__testacular__);
-window.dump = createDumpFn(window.__testacular__, function(value) {
- return window.angular && window.angular.mock && window.angular.mock.dump(value) || value;
-});
-
-})(window);
Oops, something went wrong.

0 comments on commit 8e2011d

Please sign in to comment.