Simplify build scripts and implement preliminary tests

This commit is contained in:
hensm
2018-06-11 03:42:04 +01:00
parent 7cb626841f
commit f20f96cf10
19 changed files with 6021 additions and 11 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
node_modules/
dist/
app/node_modules/
ext/node_modules/
ext/dist/

View File

@@ -28,9 +28,9 @@ Only tested on Linux. mDNS library issue to be fixed. `mdns` only works on Windo
````
git clone https://github.com/hensm/caster.git
npm install ./ext --prefix ./ext
npm install ./app --prefix ./app
npm run build --prefix ./ext
npm install
npm run build
npm test
````
Installer scripts aren't written yet, so registering the native messaging manifest with Firefox and specifiying the path must be done manually:

5512
ext/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "webpack",
"build": "webpack && web-ext build --overwrite-dest --source-dir ../dist/unpacked --artifacts-dir ../dist && mv ../dist/*.zip ../dist/ext.xpi",
"watch": "webpack -d --watch"
},
"devDependencies": {
@@ -14,6 +14,7 @@
"copy-webpack-plugin": "^4.3.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"web-ext": "^2.7.0",
"webpack": "^3.10.0"
},
"dependencies": {

View File

@@ -1,14 +1,18 @@
"use strict";
import { AutoJoinPolicy
, DefaultActionPolicy } from "../enums";
export default class ApiConfig {
constructor (
sessionRequest
, sessionListener
, receiverListener
, opt_autoJoinPolicy
, opt_defaultActionPolicy) {
, opt_autoJoinPolicy = AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED
, opt_defaultActionPolicy = DefaultActionPolicy.CREATE_SESSION) {
this.autoJoinPolicy
this.autoJoinPolicy = opt_autoJoinPolicy;
this.defaultActionPolicy = opt_defaultActionPolicy;
this.receiverListener = receiverListener;
this.sessionListener = sessionListener;
this.sessionRequest = sessionRequest;

View File

@@ -4,6 +4,7 @@ export const AutoJoinPolicy = {
TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped"
, ORIGIN_SCOPED: "origin_scoped"
, PAGE_SCOPED: "page_scoped"
, CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped"
};
export const Capability = {

View File

@@ -6,7 +6,7 @@ const webpack_copy = require("copy-webpack-plugin");
const include_path = path.resolve(__dirname, "src");
const output_path = path.resolve(__dirname, "dist");
const output_path = path.resolve(__dirname, "../dist/unpacked");
module.exports = {
entry: {
@@ -22,9 +22,8 @@ module.exports = {
, path: `${output_path}`
}
, plugins: [
new webpack.optimize.UglifyJsPlugin()
//, new webpack.optimize.CommonsChunkPlugin("lib/init.bundle")
, new webpack.DefinePlugin({
new webpack.DefinePlugin({
"process.env.NODE_ENV": `"production"`
})

11
jasmine.json Normal file
View File

@@ -0,0 +1,11 @@
{
"spec_dir": "test/spec",
"spec_files": [
"*.spec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}

258
package-lock.json generated Normal file
View File

@@ -0,0 +1,258 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"core-js": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.3.0.tgz",
"integrity": "sha1-+rg/uwstjchfpjbEudNMdUIMbWU=",
"dev": true
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"dev": true
},
"es6-promise": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz",
"integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y=",
"dev": true
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=",
"dev": true
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true
},
"jasmine": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.1.0.tgz",
"integrity": "sha1-K9Wf1+xuwOistk4J9Fpo7SrRlSo=",
"dev": true,
"requires": {
"glob": "^7.0.6",
"jasmine-core": "~3.1.0"
}
},
"jasmine-core": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.1.0.tgz",
"integrity": "sha1-pHheE11d9lAk38kiSVPfWFvSdmw=",
"dev": true
},
"jszip": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.1.5.tgz",
"integrity": "sha512-5W8NUaFRFRqTOL7ZDDrx5qWHJyBXy6velVudIzQUSoqAAYqzSh2Z7/m0Rf1QbmQJccegD0r+YZxBjzqoBiEeJQ==",
"dev": true,
"requires": {
"core-js": "~2.3.0",
"es6-promise": "~3.0.2",
"lie": "~3.1.0",
"pako": "~1.0.2",
"readable-stream": "~2.0.6"
}
},
"lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
"integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=",
"dev": true,
"requires": {
"immediate": "~3.0.5"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
}
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
"dev": true
},
"pako": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz",
"integrity": "sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg==",
"dev": true
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=",
"dev": true
},
"readable-stream": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz",
"integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "~1.0.0",
"process-nextick-args": "~1.0.6",
"string_decoder": "~0.10.x",
"util-deprecate": "~1.0.1"
}
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
"dev": true,
"requires": {
"glob": "^7.0.5"
}
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"dev": true
},
"selenium-webdriver": {
"version": "4.0.0-alpha.1",
"resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.0.0-alpha.1.tgz",
"integrity": "sha512-z88rdjHAv3jmTZ7KSGUkTvo4rGzcDGMq0oXWHNIDK96Gs31JKVdu9+FMtT4KBrVoibg8dUicJDok6GnqqttO5Q==",
"dev": true,
"requires": {
"jszip": "^3.1.3",
"rimraf": "^2.5.4",
"tmp": "0.0.30",
"xml2js": "^0.4.17"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"tmp": {
"version": "0.0.30",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.30.tgz",
"integrity": "sha1-ckGdSovn1s51FI/YsyTlk6cRwu0=",
"dev": true,
"requires": {
"os-tmpdir": "~1.0.1"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xml2js": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
"dev": true,
"requires": {
"sax": ">=0.6.0",
"xmlbuilder": "~9.0.1"
}
},
"xmlbuilder": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=",
"dev": true
}
}
}

14
package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"scripts": {
"postinstall": "npm run postinstall:app && npm run postinstall:ext",
"postinstall:app": "npm install ./app --prefix ./app",
"postinstall:ext": "npm install ./ext --prefix ./ext",
"build": "npm run build --prefix ./ext",
"pretest": "npm run build",
"test": "jasmine --config=jasmine.json"
},
"devDependencies": {
"jasmine": "^3.1.0",
"selenium-webdriver": "^4.0.0-alpha.1"
}
}

47
test/driver.js Normal file
View File

@@ -0,0 +1,47 @@
"use strict";
const path = require("path");
const webdriver = require("selenium-webdriver");
const firefox = require("selenium-webdriver/firefox");
const chrome = require("selenium-webdriver/chrome");
const TEST_PAGE_URL = `file:///${__dirname}/test.html`;
const firefoxOptions = new firefox.Options()
.headless()
.addExtensions(path.resolve(__dirname, "../dist/ext.xpi"))
.setPreference("xpinstall.signatures.required", false);
const chromeOptions = new chrome.Options()
.excludeSwitches("disable-default-apps")
.addArguments(
"--load-media-router-component-extension");
async function create () {
const driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(firefoxOptions)
.setChromeOptions(chromeOptions)
.build();
await driver.get(TEST_PAGE_URL);
try {
// Allow access from other specs
this.driver = driver;
} catch (err) {}
return driver;
}
async function destroy () {
await this.driver.quit();
}
module.exports = {
create
, destroy
}

14
test/sharedDriver.js Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
const { create, destroy } = require("./driver");
let driver;
module.exports = async () => {
if (!driver) {
driver = await create();
}
return driver;
};

View File

View File

View File

View File

@@ -0,0 +1,120 @@
"use strict";
const sharedDriver = require("../sharedDriver");
describe("chrome.cast", () => {
let driver;
let chrome;
beforeAll(async () => {
driver = await sharedDriver();
chrome = await driver.executeScript(() => {
return chrome;
});
});
it("should have all api functions", async () => {
expect(chrome.cast.addReceiverActionListener).toBeDefined();
expect(chrome.cast.initialize).toBeDefined();
expect(chrome.cast.logMessage).toBeDefined();
expect(chrome.cast.precache).toBeDefined();
expect(chrome.cast.removeReceiverActionListener).toBeDefined();
expect(chrome.cast.requestSession).toBeDefined();
expect(chrome.cast.requestSessionById).toBeDefined();
expect(chrome.cast.setCustomReceivers).toBeDefined();
expect(chrome.cast.setPageContext).toBeDefined();
expect(chrome.cast.setReceiverDisplayStatus).toBeDefined();
expect(chrome.cast.unescape).toBeDefined();
});
it("should have all api classes", async () => {
expect(chrome.cast.ApiConfig).toBeDefined();
expect(chrome.cast.DialRequest).toBeDefined();
expect(chrome.cast.Error).toBeDefined();
expect(chrome.cast.Image).toBeDefined();
expect(chrome.cast.Receiver).toBeDefined();
expect(chrome.cast.ReceiverDisplayStatus).toBeDefined();
expect(chrome.cast.SenderApplication).toBeDefined();
expect(chrome.cast.Session).toBeDefined();
expect(chrome.cast.SessionRequest).toBeDefined();
expect(chrome.cast.Timeout).toBeDefined();
expect(chrome.cast.Volume).toBeDefined();
});
it("should have all api enums", async () => {
expect(chrome.cast.AutoJoinPolicy).toEqual(jasmine.objectContaining( {
CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped"
, TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped"
, ORIGIN_SCOPED: "origin_scoped"
, PAGE_SCOPED: "page_scoped"
}));
expect(chrome.cast.Capability).toEqual(jasmine.objectContaining({
VIDEO_OUT: "video_out"
, AUDIO_OUT: "audio_out"
, VIDEO_IN: "video_in"
, AUDIO_IN: "audio_in"
, MULTIZONE_GROUP: "multizone_group"
}));
expect(chrome.cast.DefaultActionPolicy).toEqual(jasmine.objectContaining({
CREATE_SESSION: "create_session"
, CAST_THIS_TAB: "cast_this_tab"
}));
expect(chrome.cast.DialAppState).toEqual(jasmine.objectContaining({
RUNNING: "running"
, STOPPED: "stopped"
, ERROR: "error"
}));
expect(chrome.cast.ErrorCode).toEqual(jasmine.objectContaining({
CANCEL: "cancel"
, TIMEOUT: "timeout"
, API_NOT_INITIALIZED: "api_not_initialized"
, INVALID_PARAMETER: "invalid_parameter"
, EXTENSION_NOT_COMPATIBLE: "extension_not_compatible"
, EXTENSION_MISSING: "extension_missing"
, RECEIVER_UNAVAILABLE: "receiver_unavailable"
, SESSION_ERROR: "session_error"
, CHANNEL_ERROR: "channel_error"
, LOAD_MEDIA_FAILED: "load_media_failed"
}));
expect(chrome.cast.ReceiverAction).toEqual(jasmine.objectContaining({
CAST: "cast"
, STOP: "stop"
}));
expect(chrome.cast.ReceiverAvailability).toEqual(jasmine.objectContaining({
AVAILABLE: "available"
, UNAVAILABLE: "unavailable"
}));
expect(chrome.cast.ReceiverType).toEqual(jasmine.objectContaining({
CAST: "cast"
, DIAL: "dial"
, HANGOUT: "hangout"
, CUSTOM: "custom"
}));
expect(chrome.cast.SenderPlatform).toEqual(jasmine.objectContaining({
CHROME: "chrome"
, IOS: "ios"
, ANDROID: "android"
}));
expect(chrome.cast.SessionStatus).toEqual(jasmine.objectContaining({
CONNECTED: "connected"
, DISCONNECTED: "disconnected"
, STOPPED: "stopped"
}));
expect(chrome.cast.VolumeControlType).toEqual(jasmine.objectContaining({
ATTENUATION: "attenuation"
, FIXED: "fixed"
, MASTER: "master"
}));
});
});

19
test/spec/chrome.spec.js Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
const { create, destroy } = require("../driver");
describe("chrome", () => {
beforeEach(create.bind(this));
afterEach(destroy.bind(this));
it("should exist", async () => {
const chrome = await this.driver.executeScript(() => {
return window.chrome;
});
expect(typeof chrome).toBeDefined();
expect(typeof chrome.cast).toBeDefined();
expect(typeof chrome.cast.media).toBeDefined();
});
});

9
test/test.html Normal file
View File

@@ -0,0 +1,9 @@
<html>
<head>
<meta charset="utf-8">
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js" defer></script>
</head>
<body>
<h1>TEST PAGE</h1>
</body>
</html>