From e47c28bf91ddbe0ec117c4a20374b08d0faa51a3 Mon Sep 17 00:00:00 2001 From: Marshall Rose Date: Mon, 29 Aug 2016 21:42:42 -0700 Subject: [PATCH 1/2] a few minor things MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. if `process.env-NODE_ENV === ‘test’` then set the `synopsis` option `minDuration` to 0 msecs 2. if `process.env.LEDGER_PUBLISHER_DEBUG === true` then show how visits are counted 3. better error printing in one case 4. include the `ledger-publisher` code for handling `new Set()` --- .../brave/content/scripts/pageInformation.js | 9 +++++++++ app/ledger.js | 17 ++++++++++------- js/about/preferences.js | 2 +- package.json | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/extensions/brave/content/scripts/pageInformation.js b/app/extensions/brave/content/scripts/pageInformation.js index 176f4f54ebf..e11232798ae 100644 --- a/app/extensions/brave/content/scripts/pageInformation.js +++ b/app/extensions/brave/content/scripts/pageInformation.js @@ -59,6 +59,15 @@ expr['arguments'].forEach((argument) => { args.push(traverse(argument)) }) return value[traverse(op1.property, true)].apply(value, args) + case 'NewExpression': + op1 = expr.callee + if (op1.type !== 'Identifier') throw new Error('unexpected callee: ' + op1.type) + if (op1.name !== 'Set') throw new Error('only new Set(...) is allowed, not new ' + op1.name) + args = [] + expr['arguments'].forEach((argument) => { args.push(traverse(argument)) }) + if (args.length > 1) throw new Error('Set(...) takes at most one argument') + return new Set(args[0]) + case 'ConditionalExpression': return (traverse(expr.test) ? traverse(expr.consequent) : traverse(expr.alternate)) diff --git a/app/ledger.js b/app/ledger.js index b1d285d05c1..900dfd67a9a 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -238,9 +238,6 @@ eventStore.addChangeListener(() => { var entry, faviconURL, publisher var location = page.url -/* - console.log('\npage=' + JSON.stringify(page, null, 2)) - */ if ((location.match(/^about/)) || ((locations[location]) && (locations[location].publisher))) return if (!page.publisher) { @@ -403,6 +400,7 @@ var enable = (onoff) => { } catch (ex) { console.log('synopsisPath parse error: ' + ex.toString()) } + if (process.env.NODE_ENV === 'test') synopsis.options.minDuration = 0 underscore.keys(synopsis.publishers).forEach((publisher) => { if (synopsis.publishers[publisher].faviconURL === null) delete synopsis.publishers[publisher].faviconURL }) @@ -467,16 +465,19 @@ var updatePublisherInfo = () => { syncWriter(pathName(publisherPath), data, () => {}) syncWriter(pathName(scoresPath), synopsis.allN(), () => {}) + if (synopsis.options.minDuration === 0) synopsis.options.minDuration = 8 * msecs.second syncWriter(pathName(synopsisPath), synopsis, () => {}) publisherInfo.synopsis = synopsisNormalizer() if (publisherInfo._internal.debugP) { +/* data = [] publisherInfo.synopsis.forEach((entry) => { data.push(underscore.extend(underscore.omit(entry, [ 'faviconURL' ]), { faviconURL: entry.faviconURL && '...' })) }) console.log('\nupdatePublisherInfo: ' + JSON.stringify(data, null, 2)) + */ } appActions.updatePublisherInfo(underscore.omit(publisherInfo, [ '_internal' ])) @@ -584,9 +585,10 @@ var visit = (location, timestamp) => { if (!synopsis) return -/* - console.log('locations[' + currentLocation + ']=' + JSON.stringify(locations[currentLocation], null, 2)) - */ + if (publisherInfo._internal.debugP) { + console.log('locations[' + currentLocation + ']=' + JSON.stringify(locations[currentLocation], null, 2) + + ' duration=' + (timestamp - currentTimestamp) + ' msec') + } if ((location === currentLocation) || (!locations[currentLocation])) return publisher = locations[currentLocation].publisher @@ -596,6 +598,7 @@ var visit = (location, timestamp) => { publishers[publisher][currentLocation] = timestamp duration = timestamp - currentTimestamp + if (publisherInfo._internal.debugP) console.log('\nadd publisher ' + publisher + ': ' + duration + ' msec') synopsis.addPublisher(publisher, duration) updatePublisherInfo() } @@ -795,7 +798,7 @@ var callback = (err, result, delayTime) => { } if (err) { - console.log('ledger client error(1): ' + err.toString() + (err.stack ? ('\n' + err.stack) : '')) + console.log('ledger client error(1): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : '')) if (!client) return if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1, max: 10 * msecs.minute }) diff --git a/js/about/preferences.js b/js/about/preferences.js index fc3c989279f..b39395bdbf4 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -692,7 +692,7 @@ class PaymentsTab extends ImmutableComponent { {this.btcToCurrencyString(this.props.ledgerData.get('balance'))} - + {this.walletButton} diff --git a/package.json b/package.json index 29fc6657908..1ff6da14007 100644 --- a/package.json +++ b/package.json @@ -89,8 +89,8 @@ "keytar": "^3.0.0", "l20n": "^3.5.1", "ledger-balance": "^0.8.46", - "ledger-client": "^0.8.50", - "ledger-publisher": "^0.8.47", + "ledger-client": "^0.8.52", + "ledger-publisher": "^0.8.52", "lru_cache": "^1.0.0", "random-lib": "2.1.0", "qr-image": "^3.1.0", From 6805bba2389259251abbd63d0b7daccf4cd16dcc Mon Sep 17 00:00:00 2001 From: Marshall Rose Date: Mon, 29 Aug 2016 21:57:01 -0700 Subject: [PATCH 2/2] if process.env.NODE_ENV === 'test' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit then use `’-test’` as suffix for state files --- app/ledger.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/ledger.js b/app/ledger.js index 900dfd67a9a..70095a96eee 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -465,7 +465,6 @@ var updatePublisherInfo = () => { syncWriter(pathName(publisherPath), data, () => {}) syncWriter(pathName(scoresPath), synopsis.allN(), () => {}) - if (synopsis.options.minDuration === 0) synopsis.options.minDuration = 8 * msecs.second syncWriter(pathName(synopsisPath), synopsis, () => {}) publisherInfo.synopsis = synopsisNormalizer() @@ -1108,7 +1107,7 @@ var syncWriter = (path, obj, options, cb) => { }) } -const pathSuffix = (process.env.NODE_ENV === 'development') ? '-dev' : '' +const pathSuffix = { development: '-dev', test: '-test' }[process.env.NODE_ENV] || '' var pathName = (name) => { var parts = path.parse(name)