~matsubara/juju-gui/tarmac-test-2

« back to all changes in this revision

Viewing changes to test/utils.js

  • Committer: Nicola Larosa
  • Date: 2013-06-20 12:03:19 UTC
  • mfrom: (743.2.4 test-interdep-cleanup)
  • Revision ID: nicola.larosa@canonical.com-20130620120319-g0w8r6kyrgmwq6qp
Further improve test independence.

Remove many test interdependencies by giving local window.flags variables
to modules that need it.

Use loadFixture everywhere instead of duplicating code, including in the
jujuTests.utils object itself.

Mark the remaining test interdependencies and defects, to be fixed later.

Remove a meaningless test at the bottom of test_startup.js.bottom .

Add removal of generated test_startup.js file to Makefile "clean" entry.

R=gary.poster, bac
CC=
https://codereview.appspot.com/10383047

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  var jujuTests = Y.namespace('juju-tests');
24
24
 
25
25
  jujuTests.utils = {
 
26
 
26
27
    makeContainer: function(id) {
27
28
      var container = Y.Node.create('<div>');
28
29
      if (id) {
88
89
      };
89
90
    },
90
91
 
 
92
    /**
 
93
     * Util to load a fixture (typically as 'data/filename.json').
 
94
     *
 
95
     * @method loadFixture
 
96
     * @param {String} url to synchronously load.
 
97
     * @param {Boolean} parseJSON when true return will be processed
 
98
     *                  as a JSON blob before returning.
 
99
     * @return {Object} fixture data resulting from call.
 
100
     */
 
101
    loadFixture: function(url, parseJson) {
 
102
      var response = Y.io(url, {sync: true}).responseText;
 
103
      if (parseJson) {
 
104
        response = Y.JSON.parse(response);
 
105
      }
 
106
      return response;
 
107
    }
 
108
  };
 
109
 
 
110
  // Split jujuTests.utils definition, so that charms can be cached
 
111
  // right away, while at the same time reusing the loadFixture method.
 
112
  Y.mix(jujuTests.utils, {
 
113
 
91
114
    _cached_charms: (function() {
92
 
      var charms = {},
 
115
      var url, charms = {},
93
116
          names = [
94
117
            'wordpress', 'mysql', 'puppet', 'haproxy', 'mediawiki', 'hadoop',
95
118
            'memcached'];
96
119
      Y.Array.each(names, function(name) {
97
 
        charms[name] = Y.JSON.parse(
98
 
            Y.io('data/' + name + '-charmdata.json', {sync: true})
99
 
            .responseText);
 
120
        url = 'data/' + name + '-charmdata.json';
 
121
        charms[name] = jujuTests.utils.loadFixture(url, true);
100
122
      });
101
123
      return charms;
102
124
    })(),
122
144
          {charmStore: new jujuTests.utils.TestCharmStore()});
123
145
      fakebackend.login('admin', 'password');
124
146
      return fakebackend;
125
 
    },
126
 
 
127
 
    /**
128
 
     * Util to load a fixture (typically as 'data/filename.json').
129
 
     *
130
 
     * @method loadFixture
131
 
     * @param {String} url to synchronously load.
132
 
     * @param {Boolean} parseJSON when true return will be processed
133
 
     *                  as a JSON blob before returning.
134
 
     * @return {Object} fixture data resulting from call.
135
 
     */
136
 
    loadFixture: function(url, parseJson) {
137
 
      var response = Y.io(url, {sync: true}).responseText;
138
 
      if (parseJson) {
139
 
        response = Y.JSON.parse(response);
140
 
      }
141
 
      return response;
142
147
    }
143
 
  };
 
148
 
 
149
  });
144
150
 
145
151
}, '0.1.0', {
146
152
  requires: [