Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit a806248

Browse files
author
Daniel Brain
committed
Testing fixes
1 parent a8610cc commit a806248

File tree

5 files changed

+82
-55
lines changed

5 files changed

+82
-55
lines changed

gulpfile.js

+48-48
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@ var MODULE_NAME = 'postRobot';
1212

1313
var WEBPACK_CONFIG = {
1414
module: {
15-
loaders: [
16-
{
17-
test: /\.js$/,
18-
exclude: /(node_modules|bower_components)/,
19-
loader: 'babel',
20-
query: {
21-
presets: ['es2015'],
22-
plugins: [
23-
'transform-object-rest-spread',
24-
'syntax-object-rest-spread',
25-
'transform-es3-property-literals',
26-
'transform-es3-member-expression-literals',
27-
['transform-es2015-for-of', {loose: true}]
28-
]
29-
}
30-
}
31-
]
32-
},
15+
loaders: [
16+
{
17+
test: /\.js$/,
18+
exclude: /(node_modules|bower_components)/,
19+
loader: 'babel',
20+
query: {
21+
presets: ['es2015'],
22+
plugins: [
23+
'transform-object-rest-spread',
24+
'syntax-object-rest-spread',
25+
'transform-es3-property-literals',
26+
'transform-es3-member-expression-literals',
27+
['transform-es2015-for-of', {loose: true}]
28+
]
29+
}
30+
}
31+
]
32+
},
3333
output: {
34-
filename: `${FILE_NAME}.js`,
35-
libraryTarget: 'umd',
36-
umdNamedDefine: true,
37-
library: MODULE_NAME
38-
},
34+
filename: `${FILE_NAME}.js`,
35+
libraryTarget: 'umd',
36+
umdNamedDefine: true,
37+
library: MODULE_NAME
38+
},
3939
bail: true
4040
};
4141

4242
var WEBPACK_CONFIG_MIN = Object.assign({}, WEBPACK_CONFIG, {
4343
output: {
44-
filename: `${FILE_NAME}.min.js`,
45-
libraryTarget: 'umd',
46-
umdNamedDefine: true,
47-
library: MODULE_NAME
48-
},
44+
filename: `${FILE_NAME}.min.js`,
45+
libraryTarget: 'umd',
46+
umdNamedDefine: true,
47+
library: MODULE_NAME
48+
},
4949
plugins: [
50-
new webpack.optimize.UglifyJsPlugin({
51-
test: /\.js$/,
52-
exclude: /(node_modules|bower_components)/,
53-
minimize: true
54-
})
55-
]
50+
new webpack.optimize.UglifyJsPlugin({
51+
test: /\.js$/,
52+
exclude: /(node_modules|bower_components)/,
53+
minimize: true
54+
})
55+
]
5656
});
5757

5858
gulp.task('webpack', ['lint'], function() {
@@ -76,24 +76,24 @@ gulp.task('lint', function() {
7676
gulp.task('karma', function (done) {
7777

7878
var server = new Server({
79-
configFile: __dirname + '/karma.conf.js',
80-
singleRun: true,
81-
client: {
82-
captureConsole: false
83-
}
84-
});
79+
configFile: __dirname + '/karma.conf.js',
80+
singleRun: true,
81+
client: {
82+
captureConsole: true
83+
}
84+
});
8585

8686
server.on('browser_error', function (browser, err) {
87-
console.log('Karma Run Failed: ' + err.message);
88-
throw err;
89-
});
87+
console.log('Karma Run Failed: ' + err.message);
88+
throw err;
89+
});
9090

9191
server.on('run_complete', function (browsers, results) {
92-
if (results.failed) {
93-
return done(new Error('Karma: Tests Failed'));
94-
}
95-
done();
96-
});
92+
if (results.failed) {
93+
return done(new Error('Karma: Tests Failed'));
94+
}
95+
done();
96+
});
9797

9898
server.start();
9999
});

karma.conf.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module.exports = function(config) {
2828
require('karma-phantomjs-launcher'),
2929
require('karma-chrome-launcher'),
3030
require('karma-sinon-chai'),
31-
require('karma-coverage')
31+
require('karma-coverage'),
32+
require('karma-spec-reporter')
3233
],
3334

3435

@@ -47,7 +48,7 @@ module.exports = function(config) {
4748
// possible values: 'dots', 'progress'
4849
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
4950
reporters: [
50-
'progress',
51+
'spec',
5152
'coverage'
5253
],
5354

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"karma-mocha": "^1.0.1",
5151
"karma-phantomjs-launcher": "^1.0.0",
5252
"karma-sinon-chai": "^1.2.0",
53+
"karma-spec-reporter": "0.0.26",
5354
"lolex": "^1.5.0",
5455
"mocha": "^2.4.5",
5556
"phantomjs-prebuilt": "^2.1.7",

src/drivers/listeners.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function addRequestListener(name, win, options, override) {
5050

5151
if (listener) {
5252
if (override) {
53-
removeRequestListener(listener.options);
53+
removeRequestListener(listener);
5454
} else {
5555
throw new Error(`Request listener already exists for ${name}`);
5656
}

test/test.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
window.console.karma = function() {
3+
var karma = window.karma || (window.top && window.top.karma) || (window.opener && window.opener.karma);
4+
karma.log('debug', arguments);
5+
console.log.apply(console, arguments);
6+
};
7+
28
function createIframe(name) {
39
var frame = document.createElement('iframe');
410
frame.src = '/base/test/' + name;
@@ -12,12 +18,12 @@ describe('post-robot', function() {
1218

1319
it('should set up a simple server and listen for a request', function(done) {
1420

15-
postRobot.on('foo', function() {
21+
postRobot.on('foobu', function() {
1622
done();
1723
});
1824

1925
postRobot.send(child, 'sendMessageToParent', {
20-
messageName: 'foo'
26+
messageName: 'foobu'
2127
});
2228
});
2329

@@ -44,13 +50,13 @@ describe('post-robot', function() {
4450

4551
messageName: 'foo',
4652
data: {
47-
foo: 'bar'
53+
foo: 'bar2'
4854
}
4955

5056
}).then(function() {
5157

5258
return postRobot.send(child, 'foo', function(err, data) {
53-
assert.equal(data.foo, 'bar');
59+
assert.equal(data.foo, 'bar2');
5460
done();
5561
});
5662

@@ -77,4 +83,23 @@ describe('post-robot', function() {
7783
});
7884
});
7985

86+
it('should pass a function across windows and be able to call it later', function(done) {
87+
88+
postRobot.send(child, 'setupListener', {
89+
90+
messageName: 'foo',
91+
data: {
92+
done: done
93+
}
94+
95+
}).then(function() {
96+
97+
return postRobot.send(child, 'foo').then(function(data) {
98+
99+
console.karma(data);
100+
data.done();
101+
});
102+
});
103+
});
104+
80105
});

0 commit comments

Comments
 (0)