Commit 7d013f77 authored by Eric Eastwood's avatar Eric Eastwood 🌴

Remove defunct in-browser tests

parent 5e7fc3db
......@@ -2,10 +2,6 @@
**/node_modules_linux/*
public/repo/**
output/**
test/in-browser/old-n-busted/**
test/in-browser/fixtures/coverage/**
public/js/utils/base64.js
config/mongo-docker/*
test/in-browser/fixtures/build/*
test/in-browser/fixtures/runner.js
modules/*/output/**
......@@ -80,10 +80,7 @@ docker_node_modules
*.cpuprofile
*-v8.log
.vagrant/
test/in-browser/fixtures/build/*
test/in-browser/browserstack-run.pid
drop-dev-database.sh
test/in-browser/fixtures/coverage/*
node_modules_old
config.dev.user-overrides.json
node_modules_linux
......
......@@ -4,6 +4,10 @@
- Update `@gitterhq/translations@1.9.0` dependency for Georgian(`ka`) translations
- Thanks to [@davitperaze](https://gitlab.com/davitperaze) for the contribution, https://gitlab.com/gitlab-org/gitter/gitter-translations/merge_requests/68
Developer facing:
- Remove defunct in-browser tests, https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1326
# 19.35.0 - 2019-1-31
......
......@@ -196,23 +196,6 @@ You can look at the [issues labeled with ~"test"](https://gitlab.com/gitlab-org/
All unit tests etc can be run with `npm test`
#### Browser testing
Running browser unit tests during development requires this command:
```
npm run browser-watch-test
```
Then open your favourite browser and view `http://localhost:9191/fixtures`. This page will live reload with you test changes when required.
To perform an automated test run use the following command:
```
npm run browser-test
```
This will run all tests in [devtool](https://www.npmjs.com/package/devtool).
# Contributing
......
......@@ -289,13 +289,7 @@
"task-validate": "gulp validate",
"task-watch": "gulp watch",
"build-android-assets": "gulp --gulpfile gulpfile-embedded.js --android",
"build-ios-assets": "gulp --gulpfile gulpfile-embedded.js --ios",
"browser-build-tests": "webpack --config ./test/in-browser/webpack.config.js",
"browser-run-test": "cd ./test/in-browser/fixtures && devtool -cq runner.js",
"browser-test": "npm run browser-build-tests && npm run browser-run-test",
"browser-watch-build-tests": "webpack -w --config ./test/in-browser/webpack.config.js",
"browser-watch-run-tests": "http-server ./test/in-browser -p 9191 & live-reload ./test/in-browser/fixtures --port 9192",
"browser-watch-test": "npm run browser-watch-build-tests & npm run browser-watch-run-tests"
"build-ios-assets": "gulp --gulpfile gulpfile-embedded.js --ios"
},
"git": {
"scripts": {
......
<!doctype html>
<html>
<head>
<title>In-Browser Tests</title>
<link rel="stylesheet" href="/repo/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script defer='defer' async='true' data-main='in-browser/test-runner.js' src='/repo/requirejs/requirejs.js' type='text/javascript'></script>
</body>
</html>
{
"env": {
"commonjs": true,
"browser": true,
"mocha": true
},
"plugins": [
"mocha"
],
"rules": {
"mocha/no-exclusive-tests": "error",
"strict": [
"warn",
"safe"
],
"max-nested-callbacks": [
"error",
10
],
"node/no-unpublished-require": "off",
"node/no-missing-require": "off"
}
}
'use strict';
require('template/helpers/all');
var requireAll = function(requireContext) {
return requireContext.keys().map(requireContext);
};
requireAll(require.context('../specs', true, /^\.\/.*-test\.js$/));
'use strict';
module.exports = function cdn() {
return '';
};
'use strict';
var sinon = require('sinon');
var Promise = require('bluebird');
module.exports = {
user: {
delete: sinon.spy(),
put: function() {
//TODO find a better way of mocking this
return {
then: function() {
return { catch: function() {} };
},
catch: function() {}
};
}
},
priv: {
get: function() {
return Promise.resolve({});
},
channelGenerator: function(relativeUrl) {
return relativeUrl;
}
},
delete: sinon.stub().returns(Promise.resolve()),
get: sinon.stub().returns(Promise.resolve())
};
var Backbone = require('backbone');
module.exports = Backbone.Events;
'use strict';
module.exports = {
avatarCdns: ['http://localhost:5000/api/private/avatars']
};
'use strict';
module.exports = function(fn) {
fn();
};
'use strict';
var Backbone = require('backbone');
module.exports = Backbone.Collection.extend({
model: Backbone.Model.extend({
url: function() {
return ' ';
}
}),
initialize: function() {
//fake a snapshot event
setTimeout(
function() {
this.add([
{ id: 1, name: 'gitterHQ', githubType: 'ORG', favourite: 1, url: '/gitterHQ' },
{ id: 2, name: 'troupe', githubType: 'ORG', url: '/troupe' },
{
id: 3,
name: 'gitterHQ/test1',
githubType: 'ORG_CHANNEL',
favourite: 2,
url: '/gitterHQ/test1'
},
{ id: 4, name: 'gitterHQ/test2', githubType: 'ORG_CHANNEL', url: '/gitterHQ/test2' },
{
id: 5,
name: 'troupe/test1',
githubType: 'ORG_CHANNEL',
favourite: 3,
url: '/troupe/test1'
},
{ id: 6, name: 'troupe/test2', githubType: 'ORG_CHANNEL', url: '/troupe/test2' },
{ id: 7, name: 'someusername', githubType: 'ONETOONE', url: '/someusername' },
{
id: 8,
name: 'someotherusername',
githubType: 'ONETOONE',
favourite: 4,
url: '/someotherusername'
},
{ id: 9, name: 'username', githubType: 'ONETOONE', url: '/username' }
]);
this.trigger('snapshot');
}.bind(this),
0
);
}
});
'use strict';
var Marionette = require('backbone.marionette');
module.exports = Marionette.ItemView.extend({});
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gitter Webapp browser tests</title>
<!-- Mocha styles -->
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
<!-- Mocha JS-->
<script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
<script src="https://cdn.rawgit.com/mochajs/mocha/v2.5.3/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.15.4/sinon.min.js"></script>
<script>mocha.setup('bdd')</script>
<!-- Tests -->
<script src="http://localhost:9192"></script>
<script src='/fixtures/build/test.js'></script>
</head>
<body>
<div id="mocha"></div>
<script>
// This should allow errors to fall through to the devTools console
// But doesn't seem to be working :/
mocha.allowUncaught();
mocha.checkLeaks();
mocha.globals(['BrowserStack', 'troupeContext']);
window.onerror = function(err) {
console.log('-----------------------');
console.log(err);
console.log('-----------------------');
};
window.onload = function(){
console.log('STARTED');
mocha.run(function(){
console.log('FINISHED');
mocha.bail();
});
}
</script>
</body>
</html>
var Mocha = require('mocha');
var path = require('path');
var mocha = new Mocha({ useColors: true });
mocha.addFile(path.resolve(__dirname, './build/test.js'));
window.onerror = function(message) {
console.log('-----------------------');
console.log(message);
console.log('-----------------------');
};
// Run the tests.
var runner = mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures); // exit with non-zero status if there were failures
});
});
runner.on('end', function() {
process.exit();
});
runner.on('fail', function(test, err) {
process.exit(1);
});
This diff is collapsed.
/*jshint unused:true, browser:true*/
define([
'jquery',
'underscore',
'expect',
'collections/chat',
'views/chat/chatCollectionView'
], function($, _, expect, chatModel, ChatCollectionView) {
/*
* Default browser scroll behaviour:
* When an element is added to the bottom of a container the browser does not scroll the container, it keeps the current content in view and the new message is below the fold.
* When an element is added to the top of a container the browser does not scroll the container, and it does NOT keep the current content in view, the original content will be lower (it's displaced), and the new content may be visible.
*
* Desired chat collection scroll behaviour:
* When a message is added to either the top or bottom, and the viewer is at the bottom of the screen, the scroll should "stay" at the NEW bottom of the screen.
* When a subsequent message is added to the bottom, no scrolling is needed (unless the viewer is already at the bottom of the page).
* When a chunk of older messages are loaded at the top, the current items in view must stay in view.
* When the window is not in focus, subsequent (unread) messages at the bottom must not cause the top most unread item to be scrolled above the fold.
*/
// to ensure that our test environment is working properly
xdescribe('Mimmick default browser scroll behaviour', function() {
it('should keep the current scroll position as the height of the container grows', function(done) {
done();
});
});
xdescribe('Chat scroll behaviour for new messages added at the bottom', function() {
it('should scroll to the new bottom if the viewer was already at the bottom', function() {
var env = new TestEnvironment();
for (var a = 0; a < 30; a++) {
env.newMessage();
}
expect(env.scrollOf.scrollTop()).greaterThan(
Math.max(0, env.container.height() - env.scrollOf.height()) - 1
);
});
it('should not scroll past the top unread message when a new message comes in at the bottom', function() {
var env = new TestEnvironment();
// take up some space, with read messages
for (var a = 0; a < 30; a++) env.newMessage();
// store this position as the top unread item
env.topUnreadPosition = env.scrollOf.scrollTop();
// add enough "unread" messages to fill the screen
for (var b = 0; b < 20; b++) env.newMessage();
// ensure the scroll position has not gone past the top unread position previously saved
expect(env.scrollOf.scrollTop()).to.be.lessThan(env.topUnreadPosition);
});
});
xdescribe('ChatCollection', function() {
/*
it("should send a reset / sync event after the initial models come in through live collection listening", function(done) {
var env = new TestEnvironment();
env.collection.listen();
env.collection.on('reset sync', function() {
done();
});
});
*/
});
xdescribe('ChatCollectionView', function() {
it('should wait for a collection sync / reset before enabling the scroll delegate', function(done) {
var env = new TestEnvironment();
expect(env.view.hasRendered).not.to.be(true);
env.collection.on('reset sync', function() {
expect(env.view.hasRendered).equal(true);
done();
});
env.collection.trigger('sync');
});
});
function TestEnvironment() {
// mock the scrollOf jquery element
$('#content-frame').remove();
$('#chat-frame').remove();
$('<div id="content-frame"></div>').appendTo('body');
$('<div id="chat-frame"></div>').appendTo('#content-frame');
this.scrollOf = $('#content-frame');
this.scrollOf.height(800);
this.scrollOf.css({ overflow: 'scroll' });
/*{
scroll: 0,
scrollTop: function(top) {
if (top === 0 || top)
this.scroll = top;
return this.scroll;
},
h: 800,
height: function() {
//if (y === 0 || y)
// this.h = y;
return this.h;
}
};*/
// mock the container jquery element
this.container = $('#chat-frame');
/*
{
h: 0,
height: function(y) {
if (y === 0 || y) {
this.h = y;
//scrollOf.h = y;
}
return this.h;
}
};
*/
// setup the collection view
this.collection = new chatModel.ChatCollection();
this.view = new ChatCollectionView({ collection: this.collection });
this.topUnreadPosition = null;
this.newMessage = function() {
this.container.height(this.container.height() + 60);
};
}
});
/*jshint unused:true, browser:true*/
define(['jquery', 'underscore', 'expect', 'faye'], function($, _, expect, Faye) {
var ClientAuth = function() {};
ClientAuth.prototype.outgoing = function(message, callback) {
message.ext = message.ext || {};
message.ext.token = 'TEST-TOKEN-1';
callback(message);
};
var userId = null;
function getUserId(callback) {
if (userId) return callback(userId);
$.ajax({
url: '/user/',
headers: {
Authorization: 'Bearer TEST-TOKEN-1'
},
success: function(data) {
userId = data[0].id;
return callback(null, userId);
},
error: function(j, s, e) {
return callback(e);
}
});
}
function emptyFunc() {}
describe('Faye', function() {
describe('.connect()', function() {
it(
'should be able to connect and disconnect many times',
null,
/* Disable this test for now */ function(done) {
getUserId(function(err, userId) {
if (err) return done(err);
var COUNT = 10;
var total = 0;
function errorCallback(e) {
return done(e);
}
function subscriptionCallback() {
subscription.cancel();
if (++total == COUNT) {
done();
}
}
for (var i = 0; i < COUNT; i++) {
var client = new Faye.Client('/faye');
client.addExtension(new ClientAuth());
var subscription = client.subscribe('/user/' + userId, emptyFunc);
subscription.errback(errorCallback);
subscription.callback(subscriptionCallback);
}
});
}
);
});
});
});
/*jshint unused:true, browser:true*/
define(['utils/is-mobile', 'assert'], function(isMobile, assert) {
describe('is-mobile', function() {
it('detects iPhone is mobile', function() {
var userAgent =
'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B141 Safari/8536.25';
assert(isMobile(userAgent));
});
it('detects iPad is mobile', function() {
var userAgent =
'Mozilla/5.0 (iPad; CPU OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B141 Safari/8536.25';
assert(isMobile(userAgent));
});
it('detects anthing android is mobile', function() {
var userAgent =
'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile myTouch 3G Slide Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
assert(isMobile(userAgent));
});
it('detects desktop chrome is not mobile', function() {
var userAgent =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36';
assert(!isMobile(userAgent));
});
it('detects native ios client is mobile', function() {
var userAgent =
'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D167 GitterBeta/1.2.2 (4478960544)';
assert(isMobile(userAgent));
});
it('detects native osx client is not mobile', function() {
var userAgent =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.77.4 (KHTML, like Gecko) Gitter/1.153';
assert(!isMobile(userAgent));
});
it('assumes garbage user-agent is not mobile', function() {
var userAgent = 'nonsense';
assert(!isMobile(userAgent));
});
});
});
/*jshint unused:true, browser:true*/
define(['jquery', 'underscore', 'expect', 'components/realtime'], function($, _, expect, realtime) {
describe('realtime', function() {
describe('.connect()', function() {
xit('should be able to connect and disconnect many times', function(done) {
var sub = realtime.subscribe('moo', function() {});
sub.callback(function() {
done();
});
});
});
});
});
/*jshint unused:true, browser:true*/
define(['jquery', 'utils/rollers'], function($, Rollers) {
// to ensure that our test environment is working properly
describe('Rollers', function() {
before(function() {
$(document.body).append("<div id='rollers' style='height:300px; overflow-y: scroll'></div>");
});
after(function() {
$('rollers').remove();
});
it('should handle the situation of more than a single page of content arrives at once', function(done) {
var rollers = new Rollers(document.querySelector('#rollers'));
var scrollPane = $('#rollers');
var element;
for (var i = 0; i < 40; i++) {
scrollPane.append('<p>Hello' + i + '</p>');
if (i == 10) {
element = $('#rollers p').last()[0];
rollers.trackUntil(element);
}
}
setTimeout(function() {
var scrollTop = $('#rollers').scrollTop();
var expectedTop = element.offsetTop - scrollPane[0].offsetTop;
assert(scrollTop >= expectedTop - 5);
assert(scrollTop <= expectedTop + 5);
done();
}, 100);
});
});
});
/*jshint unused:true, browser:true*/
define(['backbone', 'collections/users'], function(backbone, collectionLib) {
function assert(condition, message) {
if (!condition) {
throw message || 'Assertion failed';
}
}
function assertEquals(a, b) {
if (a !== b) {
throw a + ' does not equal ' + b;
}
}
function assertArrayEquals(a, b) {
assertEquals(a.toString(), b.toString());
}
function assertCollection(collection, expected) {
var actual = collection.pluck('displayName');
assertArrayEquals(actual, expected);
}
describe('roster collection', function() {
it('should trim the users', function() {
var users = [
new backbone.Model({ displayName: 'A' }),
new backbone.Model({ displayName: 'B' }),
new backbone.Model({ displayName: 'C' })
];
var collection = new backbone.Collection();
var roster = new collectionLib.RosterCollection(null, { users: collection, limit: 2 });
collection.add(users);
assertCollection(roster, ['A', 'B']);
});
it('should sort by role', function() {
var users = [
new backbone.Model({ displayName: 'A' }),
new backbone.Model({ displayName: 'B', role: 'contributor' }),
new backbone.Model({ displayName: 'C', role: 'admin' })
];
var collection = new backbone.Collection();
var roster = new collectionLib.RosterCollection(null, { users: collection, limit: 5 });
collection.add(users);
assertCollection(roster, ['C', 'B', 'A']);
});
it('should sort by role and trim', function() {
var users = [
new backbone.Model({ displayName: 'A' }),
new backbone.Model({ displayName: 'B', role: 'contributor' }),
new backbone.Model({ displayName: 'C', role: 'admin' })
];
var collection = new backbone.Collection();
var roster = new collectionLib.RosterCollection(null, { users: collection, limit: 2 });
collection.add(users);
assertCollection(roster, ['C', 'B']);
});
it("should work with mike's weird case", function() {
var users = [
{
id: '529f4686278f637b8bb75c54',
username: 'mbtesting',
displayName: 'mbtesting',
url: '/mbtesting',
avatarUrlSmall:
'https://gravatar.com/avatar/ea9b0c6d63199a7912fd02d15dc37159?d=https%3A%2F%2Fidenticons.github.com%2F23c13ee84cc5e3a1ee1815224df023e6.png&r=x',
avatarUrlMedium:
'https://gravatar.com/avatar/ea9b0c6d63199a7912fd02d15dc37159?d=https%3A%2F%2Fidenticons.github.com%2F23c13ee84cc5e3a1ee1815224df023e6.png&r=x',