Skip to content

Commit

Permalink
Merge branch 'main' into fix_lsp_open_docs_root
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 30, 2023
2 parents 2216402 + 206c593 commit 8fe2597
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cli/npm/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl NpmPackageResolver {
}
}

pub fn root_dir_url(&self) -> &Url {
self.fs_resolver.root_dir_url()
}

pub fn resolve_pkg_id_from_pkg_req(
&self,
req: &NpmPackageReq,
Expand Down
48 changes: 48 additions & 0 deletions cli/tests/integration/coverage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,54 @@ fn no_snaps_included(test_name: &str, extension: &str) {
output.assert_exit_code(0);
}

#[test]
fn no_npm_cache_coverage() {
let context = TestContext::default();
let tempdir = context.deno_dir();
let tempdir = tempdir.path().join("cov");

let output = context
.new_command()
.args_vec(vec![
"test".to_string(),
"--quiet".to_string(),
"--allow-read".to_string(),
format!("--coverage={}", tempdir.to_str().unwrap()),
format!("coverage/no_npm_coverage/no_npm_coverage_test.ts"),
])
.run();

output.assert_exit_code(0);
output.skip_output_check();

let output = context
.new_command()
.args_vec(vec![
"coverage".to_string(),
format!("{}/", tempdir.to_str().unwrap()),
])
.split_output()
.run();

// Verify there's no "Check" being printed
assert!(output.stderr().is_empty());

let actual = util::strip_ansi_codes(output.stdout()).to_string();

let expected = fs::read_to_string(
util::testdata_path().join("coverage/no_npm_coverage/expected.out"),
)
.unwrap();

if !util::wildcard_match(&expected, &actual) {
println!("OUTPUT\n{actual}\nOUTPUT");
println!("EXPECTED\n{expected}\nEXPECTED");
panic!("pattern match failed");
}

output.assert_exit_code(0);
}

#[test]
fn no_transpiled_lines() {
let context = TestContext::default();
Expand Down
1 change: 1 addition & 0 deletions cli/tests/testdata/coverage/no_npm_coverage/expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cover [WILDCARD]/no_npm_coverage/no_npm_coverage.ts ... 100.000% (4/4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import chalk from "npm:chalk";
export function main() {
console.log(chalk.red("RED"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { main } from "./no_npm_coverage.ts";
Deno.test("main", () => {
main();
});
4 changes: 4 additions & 0 deletions cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ fn filter_coverages(
coverages: Vec<ScriptCoverage>,
include: Vec<String>,
exclude: Vec<String>,
npm_root_dir: &str,
) -> Vec<ScriptCoverage> {
let include: Vec<Regex> =
include.iter().map(|e| Regex::new(e).unwrap()).collect();
Expand All @@ -599,6 +600,7 @@ fn filter_coverages(
.into_iter()
.filter(|e| {
let is_internal = e.url.starts_with("ext:")
|| e.url.starts_with(npm_root_dir)
|| e.url.ends_with("__anonymous__")
|| e.url.ends_with("$deno$test.js")
|| e.url.ends_with(".snap");
Expand All @@ -620,12 +622,14 @@ pub async fn cover_files(
}

let ps = ProcState::build(flags).await?;
let root_dir_url = ps.npm_resolver.root_dir_url();

let script_coverages = collect_coverages(coverage_flags.files)?;
let script_coverages = filter_coverages(
script_coverages,
coverage_flags.include,
coverage_flags.exclude,
root_dir_url.as_str(),
);

let proc_coverages: Vec<_> = script_coverages
Expand Down
5 changes: 1 addition & 4 deletions ext/websocket/01_websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ class WebSocket extends EventTarget {
const sendTypedArray = (ta) => {
this[_bufferedAmount] += ta.byteLength;
PromisePrototypeThen(
core.opAsync("op_ws_send", this[_rid], {
kind: "binary",
value: ta,
}),
core.opAsync("op_ws_send_binary", this[_rid], ta),
() => {
this[_bufferedAmount] -= ta.byteLength;
},
Expand Down
15 changes: 15 additions & 0 deletions ext/websocket/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,20 @@ pub enum SendValue {
Ping,
}

#[op]
pub async fn op_ws_send_binary(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
data: ZeroCopyBuf,
) -> Result<(), AnyError> {
let resource = state
.borrow_mut()
.resource_table
.get::<WsStreamResource>(rid)?;
resource.send(Message::Binary(data.to_vec())).await?;
Ok(())
}

#[op]
pub async fn op_ws_send_text(
state: Rc<RefCell<OpState>>,
Expand Down Expand Up @@ -518,6 +532,7 @@ deno_core::extension!(deno_websocket,
op_ws_send,
op_ws_close,
op_ws_next_event,
op_ws_send_binary,
op_ws_send_text,
],
esm = [ "01_websocket.js", "02_websocketstream.js" ],
Expand Down

0 comments on commit 8fe2597

Please sign in to comment.