Skip to content

Commit

Permalink
Initial test and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jakiestfu committed Aug 22, 2016
1 parent 0513b75 commit 2fe6f5d
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 66 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/*
31 changes: 31 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@

const babel = require('rollup-plugin-babel');
const connect = require('connect');
const eslint = require('gulp-eslint');
const gulp = require('gulp');
const header = require('gulp-header');
const http = require('http');
const minify = require('uglify-js').minify;
const mochaPhantomJS = require('gulp-mocha-phantomjs');
const rollup = require('rollup-stream');
const serveStatic = require('serve-static');
const source = require('vinyl-source-stream');
const uglify = require('rollup-plugin-uglify');

var parentServer
var childServer;

const pkg = require('./package.json');
const banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
Expand Down Expand Up @@ -41,5 +48,29 @@ gulp.task('lint', () =>
.pipe(eslint.failAfterError())
);

gulp.task('parent-test-server', done => {
parentServer = http.createServer(
connect()
.use(serveStatic('.'))
.use(serveStatic('test/fixtures'))
)
.listen(9000, done);
});
gulp.task('child-test-server', done => {
childServer = http.createServer(
connect()
.use(serveStatic('.'))
.use(serveStatic('test/fixtures'))
)
.listen(9001, done);
});

gulp.task('test', ['parent-test-server', 'child-test-server'], () => {
const stream = mochaPhantomJS();
stream.write({ path: 'http://localhost:9001/test/runner.html' });
stream.end();
return stream;
});

gulp.task('watch', () => gulp.watch('./lib/postmate.js', ['build']));
gulp.task('build-watch', ['build', 'watch']);
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ new Postmate.Handshake({

#### Properties

Name | Type | Description
Name | Type | Description | Default
:--- | :--- | :---
**`container`** | `DOM Node Element` | _An element to append the iFrame to_
**`container`** (optional) | `DOM Node Element` | _An element to append the iFrame to_ | `document.body`
**`url`** | `String` | _A URL to load in the iFrame. The origin of this URL will also be used for securing message transport_

***
Expand Down
2 changes: 1 addition & 1 deletion build/postmate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/postmate.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Postmate.Handshake = class Handshake {
this.id = 'parent';
this.parent = window;
this.frame = document.createElement('iframe');
container.appendChild(this.frame);
(container || document.body).appendChild(this.frame);
this.child = this.frame.contentWindow;

return this.sendHandshake(url);
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
"main": "lib/postmate.js",
"devDependencies": {
"babel-preset-es2015-rollup": "^1.1.1",
"chai": "^3.5.0",
"connect": "^3.4.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.12.0",
"express": "^4.14.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-header": "^1.8.7",
"gulp-mocha-phantomjs": "^0.11.0",
"mocha": "^3.0.2",
"mocha-phantomjs": "^4.1.0",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-uglify": "^1.0.1",
"rollup-stream": "^1.11.0",
"rsvp": "^3.2.1",
"serve-static": "^1.11.1",
"uglify-js": "^2.7.0",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "gulp test",
"serve-parent": "PORT=4000 node sandbox.js",
"serve-child": "PORT=4001 node sandbox.js",
"build": "gulp build",
"build-watch": "gulp build-watch",
"lint": "gulp lint",
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push origin --tags",
"ssl-gen-cert": "openssl req -x509 -newkey rsa:2048 -keyout ./ssl/key.pem -out ./ssl/cert.pem -days 365",
"ssl-move-pass": "openssl rsa -in ./ssl/key.pem -out ./ssl/new-key.pem && mv ./ssl/new-key.pem ./ssl/key.pem"
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push origin --tags"
},
"repository": {
"type": "git",
Expand Down
24 changes: 0 additions & 24 deletions sandbox.js

This file was deleted.

31 changes: 0 additions & 31 deletions sandbox/parent.html

This file was deleted.

4 changes: 2 additions & 2 deletions sandbox/child.html → test/fixtures/child.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<style>
body {
height: 1000px;
height: 1234px;
padding: 0;
margin: 0;
}
Expand All @@ -13,7 +13,7 @@
<script type="text/javascript" src="../build/postmate.min.js"></script>
<script type="text/javascript">
let height = function () { return document.height || document.body.offsetHeight; };
new Postmate({ height }).then(() => console.log('Child Page Ready'));
new Postmate({ height });
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
<meta charset="utf-8">
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/rsvp/dist/rsvp.min.js"></script>
<script>window.Promise = RSVP.Promise;</script>
<script>mocha.setup('bdd')</script>
<script src="../build/postmate.min.js"></script>
<script src="./test.js"></script>
<div id="frame"></div>
<script>
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
else { mocha.run(); }
</script>
</body>
</html>
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var expect = chai.expect;

describe('postmate', function() {

it('should pass', function() {
expect(1).to.equal(1);
});

it('should fetch the childs height', function (done) {
new Postmate.Handshake({
container: document.getElementById('frame'),
url: 'http://localhost:9000/child.html'
}).then(function (child) {
child.get('height').then(function (height) {
expect(height).to.equal(1234);
done();
})
.catch(err => done(err));
});
});
});

0 comments on commit 2fe6f5d

Please sign in to comment.