Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Results of npm run format
Browse files Browse the repository at this point in the history
  • Loading branch information
motin committed Mar 24, 2018
1 parent a8b11d8 commit aaf6290
Show file tree
Hide file tree
Showing 16 changed files with 575 additions and 494 deletions.
18 changes: 6 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@

module.exports = {
env: {
"node": true
node: true,
},
extends: [
"eslint:recommended",
"plugin:mozilla/recommended",
],
extends: ["eslint:recommended", "plugin:mozilla/recommended"],

plugins: [
"mozilla",
"json"
],
plugins: ["mozilla", "json"],

rules: {
"babel/new-cap": "off",
"comma-dangle": ["error", "always-multiline"],
"eqeqeq": "error",
"indent": ["warn", 2, {SwitchCase: 1}],
eqeqeq: "error",
indent: ["warn", 2, { SwitchCase: 1 }],
"mozilla/no-aArgs": "warn",
"mozilla/balanced-listeners": 0,
"no-console": "warn",
"no-debugger": "warn",
"no-shadow": ["error"],
"no-unused-vars": "error",
"prefer-const": "warn",
"semi": ["error", "always"],
semi: ["error", "always"],
"require-jsdoc": "warn",
"valid-jsdoc": "warn",
"max-len": ["error", 80],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"scripts": {
"build-test-addon-xpi": "./bin/make_xpi.sh",
"dist": "webpack",
"docformat": "doctoc --title '**Contents**' docs/*.md && prettier '**/*.md' --write",
"eslint": "eslint src --ext jsm --ext js --ext json",
"eslint-fix": "npm run eslint -- --fix",
"format": "prettier '**/*.{css,js,jsm,json,md}' --trailing-comma=all --ignore-path=.eslintignore --write",
"postformat": "npm run eslint-fix && fixpack",
"predist": "npm run eslint",
"prepack": "fixpack && npm run dist",
"pretest": "npm run dist && npm run build-test-addon-xpi",
"test": "export FIREFOX_BINARY=firefox && XPI_NAME=test-addon/test-addon.xpi mocha test",
"docformat": "doctoc --title '**Contents**' docs/*.md && prettier '**/*.md' --write"
"test": "export FIREFOX_BINARY=firefox && XPI_NAME=test-addon/test-addon.xpi mocha test"
}
}
41 changes: 23 additions & 18 deletions shield-study-helper-addon/addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,66 @@
/* global __SCRIPT_URI_SPEC__, Feature, studyUtils, config */
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "(startup|shutdown|install|uninstall)" }]*/

async function getTelemetryPings (options) {
async function getTelemetryPings(options) {
// type is String or Array
const {type, n, timestamp, headersOnly} = options;
const { type, n, timestamp, headersOnly } = options;
Components.utils.import("resource://gre/modules/TelemetryArchive.jsm");
// {type, id, timestampCreated}
let pings = await TelemetryArchive.promiseArchivedPingList();
if (type) {
if (!(type instanceof Array)) {
type = [type]; // Array-ify if it's a string
type = [type]; // Array-ify if it's a string
}
}
if (type) pings = pings.filter(p => type.includes(p.type));
if (timestamp) pings = pings.filter(p => p.timestampCreated > timestamp);

pings.sort((a, b) => b.timestampCreated - a.timestampCreated);
if (n) pings = pings.slice(0, n);
const pingData = headersOnly ? pings : pings.map(ping => TelemetryArchive.promiseArchivedPingById(ping.id));
return Promise.all(pingData)
const pingData = headersOnly
? pings
: pings.map(ping => TelemetryArchive.promiseArchivedPingById(ping.id));
return Promise.all(pingData);
}

async function pingsReport () {
async function pingsReport() {
async function getPings() {
const ar = ["shield-study", "shield-study-addon"];
return getTelemetryPings({type: ["shield-study", "shield-study-addon"]});
return getTelemetryPings({ type: ["shield-study", "shield-study-addon"] });
}

const pings = (await getPings()).reverse();
if (pings.length == 0) {
return {"report": "No pings found"}
return { report: "No pings found" };
}
const p0 = pings[0].payload;
// print common fields
const report = `
const report =
`
// common fields
branch ${p0.branch} // should describe Question text
study_name ${p0.study_name}
addon_version ${p0.addon_version}
version ${p0.version}
` + pings.map((p,i)=>`${i} ${p.creationDate} ${p.payload.type}
${JSON.stringify(p.payload.data,null,2)}
` +
pings
.map(
(p, i) => `${i} ${p.creationDate} ${p.payload.type}
${JSON.stringify(p.payload.data, null, 2)}
`).join('\n');
`,
)
.join("\n");

return {"report": report};
return { report: report };
//pings.forEach(p=>{
// console.log(p.creationDate, p.payload.type);
// console.log(JSON.stringify(p.payload.data,null,2))
//})
}



async function listenFromWebExtension(msg, sender, sendResponse) {
//await pingsReport();
console.log(`got ${msg}`);
Expand All @@ -76,12 +82,11 @@ async function listenFromWebExtension(msg, sender, sendResponse) {
return false;
}


async function startup(addonData, reason) {
console.log('starting up debugger')
console.log("starting up debugger");
const webExtension = addonData.webExtension;
webExtension.startup().then(api => {
const {browser} = api;
const { browser } = api;
// messages intended for shieldn: {shield:true,msg=[info|endStudy|telemetry],data=data}
browser.runtime.onMessage.addListener(listenFromWebExtension);
// other message handlers from your addon, if any
Expand Down
20 changes: 9 additions & 11 deletions shield-study-helper-addon/addon/webextension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"env": {
"browser": true,
"es6": true,
"webextensions": true
},
"extends": [
"eslint:recommended"
],
"rules": {
"no-console": "warn"
}
"env": {
"browser": true,
"es6": true,
"webextensions": true
},
"extends": ["eslint:recommended"],
"rules": {
"no-console": "warn"
}
}
20 changes: 9 additions & 11 deletions shield-study-helper-addon/addon/webextension/qa.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ has a bunch of pings and stuff
`;

function printReport (text) {
function printReport(text) {
console.log(`about to replace: ${text}`);
document.querySelector('#timestamp').textContent=`${new Date()}`;
document.querySelector('#qa').textContent=text;
document.querySelector("#timestamp").textContent = `${new Date()}`;
document.querySelector("#qa").textContent = text;
}


async function tryReportFromFirefox () {
console.log(`has browser runtime? ${browser.runtime}`)
async function tryReportFromFirefox() {
console.log(`has browser runtime? ${browser.runtime}`);
if (browser.runtime) {
const reply = await browser.runtime.sendMessage("qa-report")
const reply = await browser.runtime.sendMessage("qa-report");
console.log("got reply!", reply);
if (reply) {
printReport(reply.report);
//console.log("response from legacy add-on: " + reply.content);
};
}
}
}

function startup () {
function startup() {
printReport(PLACEHOLDER);
console.log("asking firefox");
tryReportFromFirefox();
Expand All @@ -39,5 +38,4 @@ page starts up.
- once it arrives, insert it.
*/


document.addEventListener('DOMContentLoaded', startup);
document.addEventListener("DOMContentLoaded", startup);
27 changes: 17 additions & 10 deletions shield-study-helper-addon/run-firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

console.log("Starting up firefox");


require("geckodriver");
const firefox = require("selenium-webdriver/firefox");
const cmd = require("selenium-webdriver/lib/command");
Expand Down Expand Up @@ -60,11 +59,11 @@ async function promiseActualBinary(binary) {
}
}

promiseSetupDriver = async() => {
promiseSetupDriver = async () => {
const profile = new firefox.Profile();

// TODO, allow 'actually send telemetry' here.
Object.keys(FIREFOX_PREFERENCES).forEach((key) => {
Object.keys(FIREFOX_PREFERENCES).forEach(key => {
profile.setPreference(key, FIREFOX_PREFERENCES[key]);
});

Expand All @@ -76,7 +75,9 @@ promiseSetupDriver = async() => {
.forBrowser("firefox")
.setFirefoxOptions(options);

const binaryLocation = await promiseActualBinary(process.env.FIREFOX_BINARY || "nightly");
const binaryLocation = await promiseActualBinary(
process.env.FIREFOX_BINARY || "nightly",
);
await options.setBinary(new firefox.Binary(binaryLocation));
const driver = await builder.build();
// Firefox will be started up by now
Expand All @@ -85,21 +86,28 @@ promiseSetupDriver = async() => {
return driver;
};

installAddon = async(driver, fileLocation) => {
installAddon = async (driver, fileLocation) => {
// references:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1298025
// https://github.com/mozilla/geckodriver/releases/tag/v0.17.0
const executor = driver.getExecutor();
executor.defineCommand("installAddon", "POST", "/session/:sessionId/moz/addon/install");
executor.defineCommand(
"installAddon",
"POST",
"/session/:sessionId/moz/addon/install",
);
const installCmd = new cmd.Command("installAddon");

const session = await driver.getSession();
installCmd.setParameters({ sessionId: session.getId(), path: fileLocation, temporary: true });
installCmd.setParameters({
sessionId: session.getId(),
path: fileLocation,
temporary: true,
});
return executor.execute(installCmd);
};


(async() => {
(async () => {
try {
const driver = await promiseSetupDriver();

Expand All @@ -114,7 +122,6 @@ installAddon = async(driver, fileLocation) => {
// navigate to a regular page
driver.setContext(Context.CONTENT);
driver.get("about:debugging");

} catch (e) {
console.error(e); // eslint-disable-line no-console
}
Expand Down
Loading

0 comments on commit aaf6290

Please sign in to comment.