[go: nahoru, domu]

Skip to content

Commit

Permalink
Update tests to work with new structure
Browse files Browse the repository at this point in the history
This updates the tests to work with the new structure, and removes the
old `utils/run_from_console.js` files in favor of just using Karma
directly.  The Karma debug page now displays the normal mocha HTML, so
we can use that instead of the HTML generation functionality of the old
test runner.

Note that PhantomJS does not work at the moment (PhantomJS 1.5 should
make it possible to test on PhantomJS again).
  • Loading branch information
DirectXMan12 committed Mar 21, 2017
1 parent 6d6f0db commit dfae320
Show file tree
Hide file tree
Showing 17 changed files with 6,656 additions and 780 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ node_js:
- '6.1'
env:
matrix:
- TEST_BROWSER_NAME=PhantomJS
- TEST_BROWSER_NAME=chrome TEST_BROWSER_OS='Windows 10,Linux,OS X 10.11'
- TEST_BROWSER_NAME=firefox TEST_BROWSER_OS='Windows 10,Linux,OS X 10.11'
- TEST_BROWSER_NAME='internet explorer' TEST_BROWSER_OS='Windows 10'
Expand Down
18 changes: 3 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,8 @@ Contributing Guidelines
Running the unit tests
----------------------

There are two ways to run the unit tests. For both ways, you should first run
`npm install` (not as root).

The first way to run the tests is to run `npm test`. This will run all the
tests in the headless PhantomJS browser (which uses WebKit).

The second way to run the tests is using the `tests/run_from_console.js` file.
This way is a bit more flexible, and can provide more information about what
went wrong. To run all the tests, simply run `tests/run_from_console.js`.
To run a specific test file, you can use the `-t path/to/test/file.js` option.
If you wish to simply generate the HTML for the test, use the `-g` option, and
the path to the temporary HTML file will be written to standard out. To open
this file in your default browser automatically, pass the `-o` option as well.
More information can be found by passing the `--help` or `-h` option.

We use Karma to run our tests. You can launch karma manually, or simply
run `npm test`. The Karma debug page will display the tests in normal
mocha form, if you need it.

Thanks, and happy coding!
99 changes: 26 additions & 73 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,6 @@
// Karma configuration

module.exports = function(config) {
/*var customLaunchers = {
sl_chrome_win7: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 7'
},
sl_firefox30_linux: {
base: 'SauceLabs',
browserName: 'firefox',
version: '30',
platform: 'Linux'
},
sl_firefox26_linux: {
base: 'SauceLabs',
browserName: 'firefox',
version: 26,
platform: 'Linux'
},
sl_windows7_ie10: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
version: '10'
},
sl_windows81_ie11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
sl_osxmavericks_safari7: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.9',
version: '7'
},
sl_osxmtnlion_safari6: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.8',
version: '6'
}
};*/

var customLaunchers = {};
var browsers = [];
var useSauce = false;
Expand Down Expand Up @@ -93,7 +43,8 @@ module.exports = function(config) {
browsers = Object.keys(customLaunchers);
} else {
useSauce = false;
browsers = ['PhantomJS'];
//browsers = ['PhantomJS'];
browsers = [];
}

var my_conf = {
Expand All @@ -103,39 +54,30 @@ module.exports = function(config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'sinon', 'chai', 'sinon-chai'],

frameworks: ['requirejs', 'mocha', 'chai'],

// list of files / patterns to load in the browser (loaded in order)
files: [
'tests/fake.*.js',
'tests/assertions.js',
'core/util.js', // load first to avoid issues, since methods are called immediately
//'../core/*.js',
'core/base64.js',
'core/input/keysym.js',
'core/input/keysymdef.js',
'core/input/xtscancodes.js',
'core/input/util.js',
'core/input/devices.js',
'core/websock.js',
'core/rfb.js',
'core/des.js',
'core/display.js',
'core/inflator.js',
'tests/test.*.js'
{ pattern: 'vendor/sinon.js', included: false },
{ pattern: 'node_modules/sinon-chai/lib/sinon-chai.js', included: false },
{ pattern: 'core/**/*.js', included: false },
{ pattern: 'vendor/pako/**/*.js', included: false },
{ pattern: 'tests/test.*.js', included: false },
{ pattern: 'tests/fake.*.js', included: false },
{ pattern: 'tests/assertions.js', included: false },
'tests/karma-test-main.js',
],

client: {
mocha: {
// replace Karma debug page with mocha display
'reporter': 'html',
'ui': 'bdd'
}
},

// list of files to exclude
exclude: [
'../tests/playback.js',
'../app/ui.js'
],

customLaunchers: customLaunchers,
Expand All @@ -147,14 +89,24 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {

'core/**/*.js': ['babel'],
'tests/test.*.js': ['babel'],
'tests/fake.*.js': ['babel'],
'tests/assertions.js': ['babel'],
'vendor/pako/**/*.js': ['babel'],
},

babelPreprocessor: {
options: {
plugins: ['transform-es2015-modules-amd', 'syntax-dynamic-import'],
sourceMap: 'inline',
},
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'saucelabs'],
reporters: ['mocha'],


// web server port
Expand Down Expand Up @@ -186,6 +138,7 @@ module.exports = function(config) {
};

if (useSauce) {
my_conf.reporters.push('saucelabs');
my_conf.captureTimeout = 0; // use SL timeout
my_conf.sauceLabs = {
testName: 'noVNC Tests (all)',
Expand Down
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"homepage": "https://github.com/kanaka/noVNC",
"devDependencies": {
"ansi": "^0.3.1",
"babel-core": "^6.22.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
Expand All @@ -38,27 +37,21 @@
"babelify": "^7.3.0",
"browser-es-module-loader": "^0.4.1",
"browserify": "^13.1.0",
"casperjs": "^1.1.3",
"chai": "^3.5.0",
"commander": "^2.9.0",
"fs-extra": "^1.0.0",
"jsdom": "*",
"karma": "^1.3.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-chai": "^0.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sauce-launcher": "^1.0.0",
"karma-sinon": "^1.0.5",
"karma-sinon-chai-latest": "^0.1.0",
"karma-requirejs": "^1.1.0",
"requirejs": "^2.3.2",
"mocha": "^3.1.2",
"node-getopt": "*",
"open": "^0.0.5",
"phantomjs-prebuilt": "^2.1.13",
"po2json": "*",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"spooky": "^0.2.5",
"temp": "^0.8.3"
"sinon-chai": "^2.8.0"
}
}
146 changes: 71 additions & 75 deletions tests/fake.websocket.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,87 @@
var FakeWebSocket;

(function () {
// PhantomJS can't create Event objects directly, so we need to use this
function make_event(name, props) {
var evt = document.createEvent('Event');
evt.initEvent(name, true, true);
if (props) {
for (var prop in props) {
evt[prop] = props[prop];
}
// PhantomJS can't create Event objects directly, so we need to use this
function make_event(name, props) {
var evt = document.createEvent('Event');
evt.initEvent(name, true, true);
if (props) {
for (var prop in props) {
evt[prop] = props[prop];
}
return evt;
}
return evt;
}

FakeWebSocket = function (uri, protocols) {
this.url = uri;
this.binaryType = "arraybuffer";
this.extensions = "";

if (!protocols || typeof protocols === 'string') {
this.protocol = protocols;
} else {
this.protocol = protocols[0];
}
export default function FakeWebSocket (uri, protocols) {
this.url = uri;
this.binaryType = "arraybuffer";
this.extensions = "";

this._send_queue = new Uint8Array(20000);
if (!protocols || typeof protocols === 'string') {
this.protocol = protocols;
} else {
this.protocol = protocols[0];
}

this.readyState = FakeWebSocket.CONNECTING;
this.bufferedAmount = 0;
this._send_queue = new Uint8Array(20000);

this.__is_fake = true;
};
this.readyState = FakeWebSocket.CONNECTING;
this.bufferedAmount = 0;

FakeWebSocket.prototype = {
close: function (code, reason) {
this.readyState = FakeWebSocket.CLOSED;
if (this.onclose) {
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
}
},
this.__is_fake = true;
};

send: function (data) {
if (this.protocol == 'base64') {
data = Base64.decode(data);
} else {
data = new Uint8Array(data);
}
this._send_queue.set(data, this.bufferedAmount);
this.bufferedAmount += data.length;
},
FakeWebSocket.prototype = {
close: function (code, reason) {
this.readyState = FakeWebSocket.CLOSED;
if (this.onclose) {
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
}
},

_get_sent_data: function () {
var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
this.bufferedAmount = 0;
return res;
},
send: function (data) {
if (this.protocol == 'base64') {
data = Base64.decode(data);
} else {
data = new Uint8Array(data);
}
this._send_queue.set(data, this.bufferedAmount);
this.bufferedAmount += data.length;
},

_open: function (data) {
this.readyState = FakeWebSocket.OPEN;
if (this.onopen) {
this.onopen(make_event('open'));
}
},
_get_sent_data: function () {
var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
this.bufferedAmount = 0;
return res;
},

_receive_data: function (data) {
this.onmessage(make_event("message", { 'data': data }));
_open: function (data) {
this.readyState = FakeWebSocket.OPEN;
if (this.onopen) {
this.onopen(make_event('open'));
}
};
},

FakeWebSocket.OPEN = WebSocket.OPEN;
FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
FakeWebSocket.CLOSING = WebSocket.CLOSING;
FakeWebSocket.CLOSED = WebSocket.CLOSED;
_receive_data: function (data) {
this.onmessage(make_event("message", { 'data': data }));
}
};

FakeWebSocket.__is_fake = true;
FakeWebSocket.OPEN = WebSocket.OPEN;
FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
FakeWebSocket.CLOSING = WebSocket.CLOSING;
FakeWebSocket.CLOSED = WebSocket.CLOSED;

FakeWebSocket.replace = function () {
if (!WebSocket.__is_fake) {
var real_version = WebSocket;
WebSocket = FakeWebSocket;
FakeWebSocket.__real_version = real_version;
}
};
FakeWebSocket.__is_fake = true;

FakeWebSocket.restore = function () {
if (WebSocket.__is_fake) {
WebSocket = WebSocket.__real_version;
}
};
})();
FakeWebSocket.replace = function () {
if (!WebSocket.__is_fake) {
var real_version = WebSocket;
WebSocket = FakeWebSocket;
FakeWebSocket.__real_version = real_version;
}
};

FakeWebSocket.restore = function () {
if (WebSocket.__is_fake) {
WebSocket = WebSocket.__real_version;
}
};
Loading

0 comments on commit dfae320

Please sign in to comment.