Create more hot code push tests and let --browserstack use many browsers.

This commit is contained in:
Matthew Arbesfeld
2014-08-29 11:07:13 -07:00
committed by Avital Oliver
parent fa91505bb1
commit 5cf24a948d
8 changed files with 148 additions and 29 deletions

View File

@@ -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;

View File

@@ -0,0 +1,7 @@
Package.describe({
summary: "test local package reloading"
});
Package.on_use(function (api) {
api.add_files('foo.css', 'client');
});

View File

@@ -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

View File

@@ -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");
}
});
}

View File

@@ -0,0 +1 @@
packageVar = 'foo';

View File

@@ -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');
});

View File

@@ -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");