Blame view

framework/thirdparty/jasmine/src/Suite.js 2.08 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  /**
   * Internal representation of a Jasmine suite.
   *
   * @constructor
   * @param {jasmine.Env} env
   * @param {String} description
   * @param {Function} specDefinitions
   * @param {jasmine.Suite} parentSuite
   */
  jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
    var self = this;
    self.id = env.nextSuiteId ? env.nextSuiteId() : null;
    self.description = description;
    self.queue = new jasmine.Queue(env);
    self.parentSuite = parentSuite;
    self.env = env;
    self.before_ = [];
    self.after_ = [];
    self.children_ = [];
    self.suites_ = [];
    self.specs_ = [];
  };
  
  jasmine.Suite.prototype.getFullName = function() {
    var fullName = this.description;
    for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
      fullName = parentSuite.description + ' ' + fullName;
    }
    return fullName;
  };
  
  jasmine.Suite.prototype.finish = function(onComplete) {
    this.env.reporter.reportSuiteResults(this);
    this.finished = true;
    if (typeof(onComplete) == 'function') {
      onComplete();
    }
  };
  
  jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
    beforeEachFunction.typeName = 'beforeEach';
    this.before_.unshift(beforeEachFunction);
  };
  
  jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
    afterEachFunction.typeName = 'afterEach';
    this.after_.unshift(afterEachFunction);
  };
  
  jasmine.Suite.prototype.results = function() {
    return this.queue.results();
  };
  
  jasmine.Suite.prototype.add = function(suiteOrSpec) {
    this.children_.push(suiteOrSpec);
    if (suiteOrSpec instanceof jasmine.Suite) {
      this.suites_.push(suiteOrSpec);
      this.env.currentRunner().addSuite(suiteOrSpec);
    } else {
      this.specs_.push(suiteOrSpec);
    }
    this.queue.add(suiteOrSpec);
  };
  
  jasmine.Suite.prototype.specs = function() {
    return this.specs_;
  };
  
  jasmine.Suite.prototype.suites = function() {
    return this.suites_;
  };
  
  jasmine.Suite.prototype.children = function() {
    return this.children_;
  };
  
  jasmine.Suite.prototype.execute = function(onComplete) {
    var self = this;
    this.queue.start(function () {
      self.finish(onComplete);
    });
  };