1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix(cli): pretty print coverage files (#11157)

This commit is contained in:
Casper Beyer 2021-06-29 09:39:19 +08:00 committed by GitHub
parent c577c273a4
commit 96d0582900
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,9 @@ use serde::Deserialize;
use serde::Serialize;
use sourcemap::SourceMap;
use std::fs;
use std::fs::File;
use std::io::BufWriter;
use std::io::Write;
use std::path::PathBuf;
use swc_common::Span;
use uuid::Uuid;
@ -61,8 +64,12 @@ impl CoverageCollector {
let script_coverages = take_coverage_result.result;
for script_coverage in script_coverages {
let filename = format!("{}.json", Uuid::new_v4());
let json = serde_json::to_string(&script_coverage)?;
fs::write(self.dir.join(filename), &json)?;
let filepath = self.dir.join(filename);
let mut out = BufWriter::new(File::create(filepath)?);
serde_json::to_writer_pretty(&mut out, &script_coverage)?;
out.write_all(b"\n")?;
out.flush()?;
}
self.session.post_message("Profiler.disable", None).await?;