Skip to content

Commit

Permalink
update WebSQL gatherer to use Errors for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Feb 4, 2017
1 parent f92b8ed commit 5bd18e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
13 changes: 3 additions & 10 deletions lighthouse-core/audits/dobetterweb/no-websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,9 @@ class NoWebSQLAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (artifacts.WebSQL.database === -1) {
return NoWebSQLAudit.generateAuditResult({
rawValue: -1,
debugString: artifacts.WebSQL.debugString
});
}

const db = artifacts.WebSQL.database;
const debugString = (db && db.database ?
`Found database "${db.database.name}", version: ${db.database.version}.` : '');
const db = artifacts.WebSQL;
const debugString = (db ?
`Found database "${db.name}", version: ${db.version}.` : '');

return NoWebSQLAudit.generateAuditResult({
rawValue: !db,
Expand Down
20 changes: 7 additions & 13 deletions lighthouse-core/gather/gatherers/dobetterweb/websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ class WebSQL extends Gatherer {
});
}

/**
* Returns WebSQL database information or null if none was found.
* @param {!Object} options
* @return {?{id: string, domain: string, name: string, version: string}}
*/
afterPass(options) {
return this.listenForDatabaseEvents(options.driver)
.then(database => {
const artifact = {
database
};
if (!database) {
artifact.debugString = 'No WebSQL databases were opened';
}
return artifact;
}).catch(_ => {
return {
database: -1,
debugString: 'Unable to gather WebSQL database state'
};
.then(result => {
return result && result.database;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,23 @@ const assert = require('assert');
/* eslint-env mocha */

describe('No websql audit', () => {
it('fails when gatherer returns error', () => {
const debugString = 'websql is the best';
const auditResult = NoWebSQLAudit.audit({
WebSQL: {
database: -1,
debugString
}
});
assert.equal(auditResult.rawValue, -1);
assert.equal(auditResult.debugString, debugString);
});

it('passes when no database is created', () => {
assert.equal(NoWebSQLAudit.audit({
WebSQL: {
database: null
}
WebSQL: null
}).rawValue, true);
});

it('fails when database is created', () => {
const auditResult = NoWebSQLAudit.audit({
WebSQL: {
database: {
database: 'db-name', version: 1.0
}
id: '1',
domain: 'example.com',
name: 'db-name',
version: '1.0'
}
});

assert.equal(auditResult.rawValue, false);
assert.ok(auditResult.debugString.match(/Found database (.*), version: (.*)/));
assert.ok(auditResult.debugString.match(/Found database "db-name", version: 1.0/));
});
});

0 comments on commit 5bd18e9

Please sign in to comment.