diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..ab1cfb4e --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +test/* diff --git a/Gulpfile.js b/Gulpfile.js index ddccbcb0..7b1f80e4 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -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 %>', @@ -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']); diff --git a/README.md b/README.md index 5cc84571..c4044ee5 100644 --- a/README.md +++ b/README.md @@ -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_ *** diff --git a/build/postmate.min.js b/build/postmate.min.js index 0cdbaad2..3397eab1 100644 --- a/build/postmate.min.js +++ b/build/postmate.min.js @@ -4,4 +4,4 @@ * @link https://github.com/dollarshaveclub/postmate * @license MIT */ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.Postmate=n()}(this,function(){"use strict";function e(){var e;(e=console).log.apply(e,arguments)}function n(e){var n=document.createElement("a");return n.href=e,n.origin}function t(e,n){return e.origin===n&&("object"===r(e.data)&&("postmate"in e.data&&e.data.type===d))}function a(e,n,t){var a="function"==typeof e[n]?e[n](t):e[n];return Promise.resolve(a)}function i(n){var i=n.id,r=n.context,o=n.parent,s=n.parentOrigin,u=n.frame,c=n.child,h=n.childOrigin;return e('Registering consumer: "'+i+'"'),"parent"===i?(e("Parent awaiting messages..."),{frame:u,get:function(e,n){return new Promise(function(t){var a=(new Date).getTime(),i=function e(n){n.data.uid===a&&(o.removeEventListener("message",e,!1),t(n.data.value))};o.addEventListener("message",i,!1),c.postMessage({data:n,postmate:"request",type:d,key:e,uid:a},h)})}}):void("child"===i&&(e("Child awaiting messages..."),c.addEventListener("message",function(n){if(t(n,s)){e("Child received message",n.data);var i=n.data,o=i.data,u=i.key,c=i.uid;a(r,u,o).then(function(e){return n.source.postMessage({key:u,postmate:"reply",type:d,uid:c,value:e},n.origin)})}})))}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},o=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},s=function(){function e(e,n){for(var t=0;t express.static(path.join(__dirname, folder)); - -// Routes -app.use('/sandbox', staticPath('sandbox')); -app.use('/build', staticPath('build')); - -// http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/ -if (useSSL) { - https.createServer({ - key: fs.readFileSync(path.join(__dirname, 'ssl', 'key.pem')), - cert: fs.readFileSync(path.join(__dirname, 'ssl', 'cert.pem')), - }, app).listen(port, () => console.log(`Sandbox served at https://localhost:${port}`)); -} else { - app.listen(port, () => console.log(`Sandbox served at http://localhost:${port}`)); -} diff --git a/sandbox/parent.html b/sandbox/parent.html deleted file mode 100644 index 5550e09d..00000000 --- a/sandbox/parent.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - -
- - - - - diff --git a/sandbox/child.html b/test/fixtures/child.html similarity index 78% rename from sandbox/child.html rename to test/fixtures/child.html index bc531862..e893ad82 100644 --- a/sandbox/child.html +++ b/test/fixtures/child.html @@ -3,7 +3,7 @@