Skip to content

Commit

Permalink
testing: code coverage and more exhaustive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Dec 17, 2024
1 parent 437f27c commit bf12ec8
Show file tree
Hide file tree
Showing 70 changed files with 10,351 additions and 2,873 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ jobs:
cargo test --locked --all-targets
deno test --allow-read --allow-net --allow-env --allow-write
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: true

- name: Publish
if: |
contains(matrix.os, 'ubuntu') &&
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ anyhow = "1.0.86"
cfg-if = "1.0.0"
deno_ast.workspace = true
deno_graph.workspace = true
deno_terminal = "0.2.0"
indexmap = "2.3.0"
import_map.workspace = true
lazy_static = "1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::ParamDef;

cfg_if! {
if #[cfg(feature = "rust")] {
use crate::colors;
use deno_terminal::colors;
use crate::display::display_abstract;
use crate::display::display_accessibility;
use crate::display::display_async;
Expand Down
106 changes: 0 additions & 106 deletions src/colors.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/decorators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use crate::colors;
use crate::node::Location;
use crate::util::swc::get_location;

use deno_ast::swc::ast::Decorator;
use deno_ast::swc::ast::Expr;
use deno_ast::ParsedSource;
use deno_ast::SourceRangedForSpanned;
use deno_terminal::colors;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Display;
Expand Down
3 changes: 2 additions & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::colors;

use deno_terminal::colors;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;
Expand Down
2 changes: 1 addition & 1 deletion src/html/symbols/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn render_class_method(
tags.insert(Tag::Abstract);
}
if method.optional {
tags.insert(Tag::Abstract);
tags.insert(Tag::Optional);
}

Some(DocEntryCtx::new(
Expand Down
2 changes: 1 addition & 1 deletion src/html/symbols/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub(crate) fn render_methods(
.iter()
.enumerate()
.map(|(i, method)| {
let id = name_to_id("call_signature", &format!("{}_{i}", method.name));
let id = name_to_id("methods", &format!("{}_{i}", method.name));

let name = if method.name == "new" {
"<span>new</span>".to_string()
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ extern crate lazy_static;
extern crate serde_json;

pub mod class;
mod colors;
mod decorators;
mod diagnostics;
mod display;
Expand Down
37 changes: 21 additions & 16 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ use crate::js_doc::JsDocTag;
use crate::node::DeclarationKind;
use crate::node::DocNode;
use crate::node::DocNodeKind;
use crate::{colors, Location};
use crate::Location;

use deno_terminal::colors;
use deno_terminal::colors::Style;

use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;

fn italic_cyan<'a, S: Display + 'a>(s: S) -> Style<Style<S>> {
colors::italic(colors::cyan(s))
}

pub struct DocPrinter<'a> {
doc_nodes: &'a [DocNode],
use_color: bool,
Expand Down Expand Up @@ -44,9 +51,7 @@ impl<'a> DocPrinter<'a> {
doc_nodes: &[DocNode],
indent: i64,
) -> FmtResult {
if self.use_color {
colors::enable_color();
}
colors::set_use_color(self.use_color);

let mut sorted = Vec::from(doc_nodes);
sorted.sort_unstable_by(|a, b| {
Expand Down Expand Up @@ -101,7 +106,7 @@ impl<'a> DocPrinter<'a> {
}

if self.use_color {
colors::disable_color();
colors::set_use_color(false);
}

Ok(())
Expand Down Expand Up @@ -231,7 +236,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}}",
Indent(indent),
colors::magenta("default"),
colors::italic_cyan(value)
italic_cyan(value),
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
}
Expand All @@ -245,7 +250,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}}",
Indent(indent),
colors::magenta("enum"),
colors::italic_cyan(type_ref)
italic_cyan(type_ref),
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
}
Expand All @@ -262,7 +267,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}}",
Indent(indent),
colors::magenta("extends"),
colors::italic_cyan(type_ref)
italic_cyan(type_ref)
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
}
Expand All @@ -285,12 +290,12 @@ impl<'a> DocPrinter<'a> {
} => {
write!(w, "{}@{}", Indent(indent), colors::magenta("param"))?;
if let Some(type_ref) = type_ref {
write!(w, " {{{}}}", colors::italic_cyan(type_ref))?;
write!(w, " {{{}}}", italic_cyan(type_ref))?;
}
if *optional {
write!(w, " [?]")?;
} else if let Some(default) = default {
write!(w, " [{}]", colors::italic_cyan(default))?;
write!(w, " [{}]", italic_cyan(default))?;
}
writeln!(w, " {}", colors::bold(name))?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
Expand All @@ -311,7 +316,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}} {}",
Indent(indent),
colors::magenta("property"),
colors::italic_cyan(type_ref),
italic_cyan(type_ref),
colors::bold(name)
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
Expand All @@ -325,7 +330,7 @@ impl<'a> DocPrinter<'a> {
JsDocTag::Return { type_ref, doc } => {
write!(w, "{}@{}", Indent(indent), colors::magenta("return"))?;
if let Some(type_ref) = type_ref {
writeln!(w, " {{{}}}", colors::italic_cyan(type_ref))?;
writeln!(w, " {{{}}}", italic_cyan(type_ref))?;
} else {
writeln!(w)?;
}
Expand Down Expand Up @@ -356,7 +361,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}}",
Indent(indent),
colors::magenta("this"),
colors::italic_cyan(type_ref)
italic_cyan(type_ref)
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
}
Expand All @@ -370,7 +375,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}} {}",
Indent(indent),
colors::magenta("typedef"),
colors::italic_cyan(type_ref),
italic_cyan(type_ref),
colors::bold(name)
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
Expand All @@ -381,7 +386,7 @@ impl<'a> DocPrinter<'a> {
"{}@{} {{{}}}",
Indent(indent),
colors::magenta("typeref"),
colors::italic_cyan(type_ref)
italic_cyan(type_ref)
)?;
self.format_jsdoc_tag_maybe_doc(w, doc, indent)
}
Expand All @@ -407,7 +412,7 @@ impl<'a> DocPrinter<'a> {
JsDocTag::Throws { type_ref, doc } => {
write!(w, "{}@{}", Indent(indent), colors::magenta("return"))?;
if let Some(type_ref) = type_ref {
writeln!(w, " {{{}}}", colors::italic_cyan(type_ref))?;
writeln!(w, " {{{}}}", italic_cyan(type_ref))?;
} else {
writeln!(w)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ async fn deep_reexports() {

assert!(DocPrinter::new(&entries, false, false)
.to_string()
.contains("const foo"))
.contains("const foo"));
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/ts_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use crate::colors;
use crate::display::display_computed;
use crate::display::display_optional;
use crate::display::display_readonly;
Expand All @@ -26,6 +25,7 @@ use crate::variable::VariableDef;
use deno_ast::swc::ast::*;
use deno_ast::ParsedSource;
use deno_ast::SourceRangedForSpanned;
use deno_terminal::colors;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Display;
Expand Down
Loading

0 comments on commit bf12ec8

Please sign in to comment.