From 5cf24a948dcf78baa01ac860d285d06a4d30e058 Mon Sep 17 00:00:00 2001 From: Matthew Arbesfeld Date: Fri, 29 Aug 2014 11:07:13 -0700 Subject: [PATCH] Create more hot code push tests and let --browserstack use many browsers. --- tools/selftest.js | 65 +++++++++++++----- .../packages/my-package/foo.css | 0 .../packages/my-package/package.js | 7 ++ .../apps/hot-code-push-test/.meteor/versions | 2 - .../hot-code-push-test/hot-code-push-test.js | 27 +++++++- .../packages/my-package/foo.js | 1 + .../packages/my-package/package.js | 8 +++ tools/tests/hot-code-push.js | 67 +++++++++++++++++-- 8 files changed, 148 insertions(+), 29 deletions(-) create mode 100644 tools/tests/apps/css-injection-test/packages/my-package/foo.css create mode 100644 tools/tests/apps/css-injection-test/packages/my-package/package.js create mode 100644 tools/tests/apps/hot-code-push-test/packages/my-package/foo.js create mode 100644 tools/tests/apps/hot-code-push-test/packages/my-package/package.js diff --git a/tools/selftest.js b/tools/selftest.js index c0f75d1abd..6411a0950f 100644 --- a/tools/selftest.js +++ b/tools/selftest.js @@ -388,16 +388,33 @@ var Sandbox = function (options) { self._makeWarehouse(options.warehouse); } - self.clients = [ new PhantomClient({ + self.clients = [new PhantomClient({ host: 'localhost', port: options.clients.port || 3000 })]; if (options.clients && options.clients.browserstack) { - self.clients.push(new BrowserStackClient({ - host: 'localhost', - port: options.clients.port || 3000 - })); + var browsers = [ + { browserName: 'firefox' }, + { browserName: 'chrome' }, + { browserName: 'internet explorer', + browserVersion: '11' }, + { browserName: 'internet explorer', + browserVersion: '8', + timeout: 60 }, + { browserName: 'safari' }, + { browserName: 'android' } + ]; + + _.each(browsers, function (browser) { + self.clients.push(new BrowserStackClient({ + host: 'localhost', + port: 3000, + browserName: browser.browserName, + browserVersion: browser.browserVersion, + timeout: browser.timeout + })); + }); } // Figure out the 'meteor' to run @@ -433,22 +450,20 @@ _.extend(Sandbox.prototype, { var self = this; var argsArray = _.compact(_.toArray(arguments).slice(1)); - if (self.clients.length) { - console.log("running test with " + self.clients.length + " client(s)."); - } else { - console.log("running a client test with no clients. Use --browserstack" + - " to run against clients." ); - } + console.log("running test with " + self.clients.length + " client(s)."); + _.each(self.clients, function (client) { console.log("testing with " + client.name + "..."); - f(new Run(self.execPath, { + var run = new Run(self.execPath, { sandbox: self, args: argsArray, cwd: self.cwd, env: self._makeEnv(), fakeMongo: self.fakeMongo, client: client - })); + }); + run.baseTimeout = client.timeout; + f(run); }); }, @@ -560,7 +575,10 @@ _.extend(Sandbox.prototype, { // Make a directory in the sandbox. 'filename' is as in write(). mkdir: function (dirname) { var self = this; - fs.mkdirSync(path.join(self.cwd, dirname)); + var dirPath = path.join(self.cwd, dirname); + if (! fs.existsSync(dirPath)) { + fs.mkdirSync(dirPath); + } }, // Rename something in the sandbox. 'oldName' and 'newName' are as in write(). @@ -784,7 +802,9 @@ var Client = function (options) { self.host = options.host; self.port = options.port; - self.url = "http://" + self.host + ":" + self.port; + self.url = "http://" + self.host + ":" + self.port + '/' + + (Math.random() * 0x100000000 + 1).toString(36); + self.timeout = options.timeout || 40; if (! self.connect || ! self.stop) { console.log("Missing methods in subclass of Client."); @@ -828,9 +848,16 @@ var BrowserStackClient = function (options) { var self = this; Client.apply(this, arguments); - self.name = "BrowserStack"; self.tunnelProcess = null; self.driver = null; + + self.browserName = options.browserName; + self.browserVersion = options.browserVersion; + + self.name = "BrowserStack - " + self.browserName; + if (self.browserVersion) { + self.name += " " + self.browserVersion; + } }; util.inherits(BrowserStackClient, Client); @@ -847,12 +874,16 @@ _.extend(BrowserStackClient.prototype, { "have installed your S3 credentials."); var capabilities = { - 'browserName' : 'firefox', + 'browserName' : self.browserName, 'browserstack.user' : 'meteor', 'browserstack.local' : 'true', 'browserstack.key' : browserStackKey }; + if (self.browserVersion) { + capabilities.browserVersion = self.browserVersion; + } + self._launchBrowserStackTunnel(function (error) { if (error) throw error; diff --git a/tools/tests/apps/css-injection-test/packages/my-package/foo.css b/tools/tests/apps/css-injection-test/packages/my-package/foo.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/tests/apps/css-injection-test/packages/my-package/package.js b/tools/tests/apps/css-injection-test/packages/my-package/package.js new file mode 100644 index 0000000000..22e5281e7f --- /dev/null +++ b/tools/tests/apps/css-injection-test/packages/my-package/package.js @@ -0,0 +1,7 @@ +Package.describe({ + summary: "test local package reloading" +}); + +Package.on_use(function (api) { + api.add_files('foo.css', 'client'); +}); \ No newline at end of file diff --git a/tools/tests/apps/hot-code-push-test/.meteor/versions b/tools/tests/apps/hot-code-push-test/.meteor/versions index a30872daba..7bec0ef3a4 100644 --- a/tools/tests/apps/hot-code-push-test/.meteor/versions +++ b/tools/tests/apps/hot-code-push-test/.meteor/versions @@ -1,5 +1,4 @@ application-configuration@1.0.0 -autopublish@1.0.0 autoupdate@1.0.0 binary-heap@1.0.0 callback-hook@1.0.0 @@ -13,7 +12,6 @@ geojson-utils@1.0.0 html-tools@1.0.0 htmljs@1.0.0 id-map@1.0.0 -insecure@1.0.0 jquery@1.0.0 json@1.0.0 livedata@1.0.0 diff --git a/tools/tests/apps/hot-code-push-test/hot-code-push-test.js b/tools/tests/apps/hot-code-push-test/hot-code-push-test.js index 792b563d6f..e10037704b 100644 --- a/tools/tests/apps/hot-code-push-test/hot-code-push-test.js +++ b/tools/tests/apps/hot-code-push-test/hot-code-push-test.js @@ -1,18 +1,39 @@ if (Meteor.isClient) { - Meteor.startup(function () { - Meteor.call("clientLoad", typeof jsVar === 'undefined' ? 'undefined' : jsVar); + var sessionVar = Session.get("sessionVar"); + + Meteor.defer(function () { + Meteor.call("clientLoad", + typeof jsVar === 'undefined' ? 'undefined' : jsVar, + typeof packageVar === 'undefined' ? 'undefined' : packageVar, + sessionVar); }); + + if (window.applicationCache) { + var call = function () { + Meteor.call("appcacheReady"); + }; + window.applicationCache.addEventListener('updateready', call, false); + window.applicationCache.addEventListener('noupdate', call, false); + window.applicationCache.addEventListener('obsolete', call, false); + } + + Session.setDefault("sessionVar", true); } if (Meteor.isServer) { var clientConnections = 0; Meteor.methods({ - clientLoad: function (jsVar) { + clientLoad: function (jsVar, packageVar, sessionVar) { // Make sure that the process still has the correct working directory. process.cwd(); console.log("client connected: " + clientConnections++); console.log("jsVar: " + jsVar); + console.log("packageVar: " + packageVar); + console.log("sessionVar: " + sessionVar); + }, + appcacheReady: function () { + console.log("appcache ready"); } }); } diff --git a/tools/tests/apps/hot-code-push-test/packages/my-package/foo.js b/tools/tests/apps/hot-code-push-test/packages/my-package/foo.js new file mode 100644 index 0000000000..5e7a7060e3 --- /dev/null +++ b/tools/tests/apps/hot-code-push-test/packages/my-package/foo.js @@ -0,0 +1 @@ +packageVar = 'foo'; \ No newline at end of file diff --git a/tools/tests/apps/hot-code-push-test/packages/my-package/package.js b/tools/tests/apps/hot-code-push-test/packages/my-package/package.js new file mode 100644 index 0000000000..121b5b8cda --- /dev/null +++ b/tools/tests/apps/hot-code-push-test/packages/my-package/package.js @@ -0,0 +1,8 @@ +Package.describe({ + summary: "test local package reloading" +}); + +Package.on_use(function (api) { + api.export('packageVar'); + api.add_files('foo.js', 'client'); +}); \ No newline at end of file diff --git a/tools/tests/hot-code-push.js b/tools/tests/hot-code-push.js index d239582efa..93d2ff5e59 100644 --- a/tools/tests/hot-code-push.js +++ b/tools/tests/hot-code-push.js @@ -14,7 +14,6 @@ selftest.define("css hot code push", function (options) { s.createApp("myapp", "css-injection-test"); s.cd("myapp"); s.testWithAllClients(function (run) { - run.baseTimeout = 20; run.match("myapp"); run.match("proxy"); run.match("MongoDB"); @@ -41,18 +40,45 @@ selftest.define("css hot code push", function (options) { s.write("test.css", "body { background-color: red; }"); run.match("Client modified -- refreshing"); run.match("numCssChanges: 1"); - run.match("background-color: rgb(255, 0, 0)"); + run.match(/background-color: (red|rgb\(255, 0, 0\))/); s.write("test.css", "body { background-color: blue; }"); run.match("Client modified -- refreshing"); run.match("numCssChanges: 2"); - run.match("background-color: rgb(0, 0, 255)"); + run.match(/background-color: (blue|rgb\(0, 0, 255\))/); // The server does NOT restart if a css file is removed. s.unlink("test.css"); run.match("Client modified -- refreshing"); run.match("numCssChanges: 3"); run.match(/background-color: (transparent|rgba\(0, 0, 0, 0\))/); + + s.write(".meteor/packages", "standard-app-packages \n my-package"); + run.match("added my-package"); + run.match("client connected"); + run.match("numCssChanges: 0"); + + s.write("packages/my-package/foo.css", "body { background-color: blue; }"); + run.match("numCssChanges: 1"); + run.match(/background-color: (blue|rgb\(0, 0, 255\))/); + + // Add appcache and ensure that the browser still reloads. + s.write(".meteor/packages", "standard-app-packages \n my-package \n appcache"); + run.match("added appcache"); + run.match("server restarted"); + run.match("numCssChanges: 0"); + run.match(/background-color: (blue|rgb\(0, 0, 255\))/); + + s.write("packages/my-package/foo.css", "body { background-color: red; }"); + run.match("Client modified -- refreshing"); + run.match("numCssChanges: 1"); + run.match(/background-color: (red|rgb\(255, 0, 0\))/); + + s.write(".meteor/packages", "standard-app-packages"); + run.match("removed my-package"); + run.match("numCssChanges: 0"); + run.match(/background-color: (transparent|rgba\(0, 0, 0, 0\))/); + run.stop(); }); }); @@ -90,7 +116,6 @@ selftest.define("javascript hot code push", function (options) { s.createApp("myapp", "hot-code-push-test"); s.cd("myapp"); s.testWithAllClients(function (run) { - run.baseTimeout = 20; run.match("myapp"); run.match("proxy"); run.match("MongoDB"); @@ -98,11 +123,12 @@ selftest.define("javascript hot code push", function (options) { run.match("localhost"); run.connectClient(); - run.waitSecs(20); + run.waitSecs(40); // There is initially no JavaScript file. run.match("client connected: 0"); run.match("jsVar: undefined"); + run.match("sessionVar: null"); // The server and client both restart if a shared js file is added // or removed. @@ -110,6 +136,7 @@ selftest.define("javascript hot code push", function (options) { run.match("server restarted"); run.match("client connected: 0"); run.match("jsVar: foo"); + run.match("sessionVar: true"); s.unlink("test.js"); run.match("server restarted"); @@ -119,6 +146,7 @@ selftest.define("javascript hot code push", function (options) { // Only the client should refresh if a client js file is added. Thus, // "client connected" variable will be incremented. s.mkdir("client"); + s.write("client/test.js", "jsVar = 'bar'"); run.match("client connected: 1"); run.match("jsVar: bar"); @@ -162,12 +190,37 @@ selftest.define("javascript hot code push", function (options) { run.match("client connected: 1"); run.match("jsVar: undefined"); + s.write(".meteor/packages", "standard-app-packages \n my-package"); + run.match("added my-package"); + run.match("server restarted"); + run.match("client connected: 0"); + run.match("jsVar: undefined"); + run.match("packageVar: foo"); + + s.write("packages/my-package/foo.js", "packageVar = 'bar'"); + run.match("client connected: 1"); + run.match("jsVar: undefined"); + run.match("packageVar: bar"); + + // Add appcache and ensure that the browser still reloads. + s.write(".meteor/packages", "standard-app-packages \n appcache"); + run.match("added appcache"); + run.match("server restarted"); + run.match("client connected: 0"); + run.match("jsVar: undefined"); + s.write("client/test.js", "jsVar = 'bar'"); - run.match("client connected: 2"); + run.match("client connected: 1"); run.match("jsVar: bar"); + // Remove appcache and ensure that the browser still reloads. + s.write(".meteor/packages", "standard-app-packages"); + run.match("removed appcache"); + run.match("server restarted"); + run.match("client connected: 0"); + s.write("client/test.js", "jsVar = 'baz'"); - run.match("client connected: 3"); + run.match("client connected: 1"); run.match("jsVar: baz"); s.unlink("client/test.js");