diff --git a/bin/serve.js b/bin/serve.js index f2112002..8932383c 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -106,7 +106,8 @@ function main (args) { options: plotlyJsOpts }, { name: 'plotly-dash-preview', - route: '/dash-preview' + route: '/dash-preview', + options: plotlyJsOpts }) } diff --git a/package-lock.json b/package-lock.json index f966d172..2ace34da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -429,6 +429,16 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, + "axios": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz", + "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", + "dev": true, + "requires": { + "follow-redirects": "^1.3.0", + "is-buffer": "^1.1.5" + } + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -2622,6 +2632,26 @@ "write": "^0.2.1" } }, + "follow-redirects": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz", + "integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==", + "dev": true, + "requires": { + "debug": "=3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } + } + }, "foreground-child": { "version": "1.5.6", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz", @@ -3077,6 +3107,12 @@ "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "dev": true }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "dev": true + }, "is-builtin-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", diff --git a/package.json b/package.json index 810cf429..31311c32 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "uuid": "^3.3.2" }, "devDependencies": { + "axios": "^0.18.0", "chttps": "^1.0.6", "cross-env": "^5.2.0", "devtron": "^1.4.0", diff --git a/test/integration/orca_serve_offline_test.js b/test/integration/orca_serve_offline_test.js new file mode 100644 index 00000000..d87f553c --- /dev/null +++ b/test/integration/orca_serve_offline_test.js @@ -0,0 +1,85 @@ +const tap = require('tap') +const Application = require('spectron').Application + +const { paths } = require('../common') +const path = require('path') + +const PORT = 9111 + +const numberOfComponents = 6 +const axios = require('axios') +const fs = require('fs') +const pathToPlotlyJS = path.join(paths.build, 'plotly-latest.min.js') + +const app = new Application({ + path: paths.bin, + args: ['serve', '--port', PORT, '--plotlyjs', pathToPlotlyJS] +}) + +tap.tearDown(() => { + if (app && app.isRunning()) { + app.stop() + } +}) + +tap.test('should launch', t => { + axios.request({ + url: 'https://cdn.plot.ly/plotly-latest.min.js', + method: 'get' + }) + .then((result) => { + fs.writeFileSync(pathToPlotlyJS, result.data) + }) + .then(() => { + return app.start() + }) + .then(() => { + app.client.getWindowCount().then(cnt => { + t.equal(cnt, numberOfComponents) + t.end() + }) + }) + .catch(err => { + t.fail(err) + t.end() + }) +}) + +function getScriptTagsSrc (index) { + // executeJavaScript in Spectron is broken https://github.com/electron/spectron/issues/163 + return app.client.windowByIndex(index).then(() => { + return app.client.execute(() => { + var htmlCollection = document.getElementsByTagName('script') + var arr = [].slice.call(htmlCollection) + return arr.map(script => { + return script.src + }) + }) + }) +} + +tap.test('should not link to resources on the network', t => { + var promises = [] + for (var i = 0; i < numberOfComponents; i++) { + promises.push(getScriptTagsSrc(0)) + } + Promise.all(promises).then(values => { + values.forEach(result => { + var urls = result.value + urls.forEach(url => { + t.notOk(url.match('http'), `A script tag refers to an HTTP(S) resource ${url}`) + }) + }) + t.end() + }) + .catch(err => { + t.fail(err) + t.end() + }) +}) + +tap.test('should teardown', t => { + app.stop() + .catch(t.fail) + .then(t.end) +})