firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Colorize Firestore Emulator Coverage

Open alixaxel opened this issue 6 years ago • 10 comments

Context: we have pretty extensive Firestore security rules and when viewing the emulator coverage report, it gets really difficult to see what went wrong and where due to the sheer size of it.

I'm using the following CSS overrides to provide some visual cues:

.coverage-expr:hover {
    border-bottom: 3px dashed rgb(0, 0, 0);
    cursor: default;
}

.coverage-expr[title="Expression never evaluated"] {
    background: lightyellow;
}

.coverage-expr[title^="Value true returned"] {
    background: lightgreen;
}

.coverage-expr[title^="Value false returned"] {
    background: lightcoral;
}

.coverage-expr[title^="Expression short-circuited"] {
    background: lightgrey;
}

Sample:

image

image

The CSS selectors might not be perfect, but we find them pretty helpful while analyzing coverage.

It would be great if something like this was incorportated into the emulator by default.

alixaxel avatar May 14 '19 17:05 alixaxel

@ryanpbrewster Please take a look and feel free to re-assign back to me if this isn't in your wheelhouse.

abeisgoat avatar May 14 '19 17:05 abeisgoat

Actually we've been prototyping some much slicker UIs for this report this week. Will update here if there is concrete progress.

samtstern avatar May 14 '19 17:05 samtstern

@samtstern any news?

wiedzmin26 avatar Nov 16 '19 12:11 wiedzmin26

@wiedzmin26 no specific news, we are still pursuing a more general "UI" for the emulator suite where we can put this and other features.

samtstern avatar Nov 18 '19 17:11 samtstern

@samtstern Any news one year later? It would be great if the new Firestore emulator UI had a link to a colorized version of the rules coverage. It should not be too complicated and make the rules coverage useful at last :wink:

laurentpayot avatar Nov 25 '20 10:11 laurentpayot

@laurentpayot I agree, as is the rules coverage html is useless 😞 .

mvergarair avatar Nov 27 '20 18:11 mvergarair

bump, the OP css is VERY useful. in the meantime just add those under a flag or something until you decide on a better approach (if any)

erlichmen avatar Jun 08 '21 06:06 erlichmen

@yuchenshi you gave a generated coverage html file as an example of Rules Unit Tests V2. I had to add a few lines to your example to concatenate @alixaxel’s <style> section to the generated coverage file to make it useful. As you were once assigned to this issue I am gently pinging you for a fix :wink:

laurentpayot avatar Sep 06 '21 07:09 laurentpayot

I store all override CSS styles in a file override.css and I modify after function to override the css

after(async () => {
  // Close any open apps
  await Promise.all(firebase.apps().map((app) => app.delete()));

  // Write the coverage report to a file
  const coverageFile = 'database-coverage.html';
  await new Promise((resolve, reject) => {
    http.get(COVERAGE_URL, (res) => {
    let body = '';
    res.on('data', chunk => body += chunk);
    res.on("end", () => {
      let start = body.indexOf('<style>');
      let end = body.indexOf('</style>');
      body = body.substring(0, start + '<style>'.length) + fs.readFileSync('override.css').toString() + body.substring(end);
      fs.writeFileSync(coverageFile, body);
      resolve();
    });
    res.on("error", reject);
    });
  });

   console.log(`View database rule coverage information at ${coverageFile}\n`);
});

new-carrot avatar May 26 '22 14:05 new-carrot

Still no updates on this?

imolorhe avatar Dec 27 '22 23:12 imolorhe