Skip to content

Commit

Permalink
Merge branch 'main' into fix/#21658/respect-exclude-option-for-check
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn authored Jan 3, 2024
2 parents 4780fab + 9526520 commit 744a463
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 53 deletions.
119 changes: 117 additions & 2 deletions cli/lsp/code_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,25 @@ impl Visit for DenoTestCollector {
}
ast::Expr::Member(member_expr) => {
if let ast::MemberProp::Ident(ns_prop_ident) = &member_expr.prop {
let mut member_expr = member_expr;
let mut ns_prop_ident = ns_prop_ident;
let range = ns_prop_ident.range();
if matches!(ns_prop_ident.sym.as_str(), "ignore" | "only") {
let ast::Expr::Member(member_expr_) = member_expr.obj.as_ref()
else {
return;
};
member_expr = member_expr_;
let ast::MemberProp::Ident(ns_prop_ident_) = &member_expr.prop
else {
return;
};
ns_prop_ident = ns_prop_ident_;
}
if ns_prop_ident.sym == "test" {
if let ast::Expr::Ident(ident) = member_expr.obj.as_ref() {
if ident.sym == "Deno" {
self.check_call_expr(node, &ns_prop_ident.range());
self.check_call_expr(node, &range);
}
}
}
Expand Down Expand Up @@ -528,6 +543,10 @@ mod tests {
Deno.test(function useFnName() {});
Deno.test("test b", function anotherTest() {});
Deno.test.ignore("test ignore", () => {});
Deno.test.only("test only", () => {});
"#;
let parsed_module = deno_ast::parse_module(deno_ast::ParseParams {
specifier: specifier.to_string(),
Expand Down Expand Up @@ -687,7 +706,103 @@ mod tests {
])
}),
data: None,
}
},
lsp::CodeLens {
range: lsp::Range {
start: lsp::Position {
line: 10,
character: 16,
},
end: lsp::Position {
line: 10,
character: 22,
},
},
command: Some(lsp::Command {
title: "▶\u{fe0e} Run Test".to_string(),
command: "deno.test".to_string(),
arguments: Some(vec![
json!("https://deno.land/x/mod.ts"),
json!("test ignore"),
json!({
"inspect": false,
}),
]),
}),
data: None,
},
lsp::CodeLens {
range: lsp::Range {
start: lsp::Position {
line: 10,
character: 16,
},
end: lsp::Position {
line: 10,
character: 22,
},
},
command: Some(lsp::Command {
title: "Debug".to_string(),
command: "deno.test".to_string(),
arguments: Some(vec![
json!("https://deno.land/x/mod.ts"),
json!("test ignore"),
json!({
"inspect": true,
}),
]),
}),
data: None,
},
lsp::CodeLens {
range: lsp::Range {
start: lsp::Position {
line: 12,
character: 16,
},
end: lsp::Position {
line: 12,
character: 20,
},
},
command: Some(lsp::Command {
title: "▶\u{fe0e} Run Test".to_string(),
command: "deno.test".to_string(),
arguments: Some(vec![
json!("https://deno.land/x/mod.ts"),
json!("test only"),
json!({
"inspect": false,
}),
]),
}),
data: None,
},
lsp::CodeLens {
range: lsp::Range {
start: lsp::Position {
line: 12,
character: 16,
},
end: lsp::Position {
line: 12,
character: 20,
},
},
command: Some(lsp::Command {
title: "Debug".to_string(),
command: "deno.test".to_string(),
arguments: Some(vec![
json!("https://deno.land/x/mod.ts"),
json!("test only"),
json!({
"inspect": true,
}),
]),
}),
data: None,
},
]
);
}
Expand Down
8 changes: 8 additions & 0 deletions cli/tests/integration/jupyter_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

itest!(jupyter_install_command_not_exists {
args: "jupyter --unstable --install",
output: "jupyter/install_command_not_exists.out",
envs: vec![("PATH".to_string(), "".to_string())],
exit_code: 1,
});
5 changes: 4 additions & 1 deletion cli/tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ mod inspector;
mod install;
#[path = "js_unit_tests.rs"]
mod js_unit_tests;
mod jsr_tests;
#[path = "jsr_tests.rs"]
mod jsr;
#[path = "jupyter_tests.rs"]
mod jupyter;
#[path = "lint_tests.rs"]
mod lint;
#[path = "lsp_tests.rs"]
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/testdata/jupyter/install_command_not_exists.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: Failed to spawn 'jupyter' command. Is JupyterLab installed (https://jupyter.org/install) and available on the PATH?

Caused by:
[WILDCARD]
77 changes: 40 additions & 37 deletions cli/tests/unit/signal_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,25 @@ Deno.test(
permissions: { run: true },
},
async function signalListenerTest() {
const { promise, resolve } = Promise.withResolvers<void>();
let c = 0;
const listener = () => {
c += 1;
};
// This test needs to be careful that it doesn't accidentally aggregate multiple
// signals into one. Sending two or more SIGxxx before the handler can be run will
// result in signal coalescing.
Deno.addSignalListener("SIGUSR1", listener);
setTimeout(async () => {
// Sends SIGUSR1 3 times.
for (const _ of Array(3)) {
// Sends SIGUSR1 3 times.
for (let i = 1; i <= 3; i++) {
await delay(1);
Deno.kill(Deno.pid, "SIGUSR1");
while (c < i) {
await delay(20);
Deno.kill(Deno.pid, "SIGUSR1");
}
await promise;
Deno.removeSignalListener("SIGUSR1", listener);
});

// We'll get three signals eventually
while (c < 3) {
await delay(20);
}
resolve();
Deno.removeSignalListener("SIGUSR1", listener);
await delay(100);
assertEquals(c, 3);
},
);

Expand All @@ -140,47 +138,52 @@ Deno.test(
permissions: { run: true },
},
async function multipleSignalListenerTest() {
const { promise, resolve } = Promise.withResolvers<void>();
let c = "";
const listener0 = () => {
c += "0";
};
const listener1 = () => {
c += "1";
};
// This test needs to be careful that it doesn't accidentally aggregate multiple
// signals into one. Sending two or more SIGxxx before the handler can be run will
// result in signal coalescing.
Deno.addSignalListener("SIGUSR2", listener0);
Deno.addSignalListener("SIGUSR2", listener1);
setTimeout(async () => {
// Sends SIGUSR2 3 times.
for (const _ of Array(3)) {
await delay(20);
Deno.kill(Deno.pid, "SIGUSR2");
}
while (c.length < 6) {

// Sends SIGUSR2 3 times.
for (let i = 1; i <= 3; i++) {
await delay(1);
Deno.kill(Deno.pid, "SIGUSR2");
while (c.length < i * 2) {
await delay(20);
}
Deno.removeSignalListener("SIGUSR2", listener1);
// Sends SIGUSR2 3 times.
for (const _ of Array(3)) {
}

Deno.removeSignalListener("SIGUSR2", listener1);

// Sends SIGUSR2 3 times.
for (let i = 1; i <= 3; i++) {
await delay(1);
Deno.kill(Deno.pid, "SIGUSR2");
while (c.length < 6 + i) {
await delay(20);
Deno.kill(Deno.pid, "SIGUSR2");
}
}

// Sends SIGUSR1 (irrelevant signal) 3 times.
for (const _ of Array(3)) {
await delay(20);
// Sends SIGUSR1 (irrelevant signal) 3 times.
for (const _ of Array(3)) {
await delay(20);
Deno.kill(Deno.pid, "SIGUSR1");
}
Deno.kill(Deno.pid, "SIGUSR1");
}

while (c.length < 9) {
await delay(20);
}
// No change
assertEquals(c, "010101000");

Deno.removeSignalListener("SIGUSR2", listener0);

Deno.removeSignalListener("SIGUSR2", listener0);
resolve();
});
await delay(100);

await promise;
// The first 3 events are handled by both handlers
// The last 3 events are handled only by handler0
assertEquals(c, "010101000");
Expand Down
30 changes: 30 additions & 0 deletions cli/tests/unit_node/zlib_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
createBrotliCompress,
createBrotliDecompress,
createDeflate,
gzipSync,
unzipSync,
} from "node:zlib";
import { Buffer } from "node:buffer";
import { createReadStream, createWriteStream } from "node:fs";
Expand All @@ -32,6 +34,13 @@ Deno.test("brotli compression async", async () => {
assertEquals(decompressed.toString(), "hello world");
});

Deno.test("gzip compression sync", { sanitizeResources: false }, () => {
const buf = Buffer.from("hello world");
const compressed = gzipSync(buf);
const decompressed = unzipSync(compressed);
assertEquals(decompressed.toString(), "hello world");
});

Deno.test("brotli compression", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const compress = createBrotliCompress();
Expand Down Expand Up @@ -125,3 +134,24 @@ Deno.test("should work with a buffer from an encoded string", () => {
const decompressed = brotliDecompressSync(compressed);
assertEquals(decompressed.toString(), "hello world");
});

Deno.test(
"zlib compression with dataview",
{ sanitizeResources: false },
() => {
const buf = Buffer.from("hello world");
const compressed = gzipSync(new DataView(buf.buffer));
const decompressed = unzipSync(compressed);
assertEquals(decompressed.toString(), "hello world");
},
);

Deno.test("zlib compression with an encoded string", {
sanitizeResources: false,
}, () => {
const encoder = new TextEncoder();
const buffer = encoder.encode("hello world");
const compressed = gzipSync(buffer);
const decompressed = unzipSync(compressed);
assertEquals(decompressed.toString(), "hello world");
});
36 changes: 26 additions & 10 deletions cli/tools/jupyter/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
use std::env::current_exe;
use std::io::ErrorKind;
use std::io::Write;
use std::path::Path;
use tempfile::TempDir;
Expand Down Expand Up @@ -76,19 +77,34 @@ pub fn install() -> Result<(), AnyError> {
&temp_dir.path().to_string_lossy(),
])
.spawn();
let mut child = match child_result {
Ok(child) => child,
Err(err)
if matches!(
err.kind(),
ErrorKind::NotFound | ErrorKind::PermissionDenied
) =>
{
return Err(err).context(concat!(
"Failed to spawn 'jupyter' command. Is JupyterLab installed ",
"(https://jupyter.org/install) and available on the PATH?"
));
}
Err(err) => {
return Err(err).context("Failed to spawn 'jupyter' command.");
}
};

if let Ok(mut child) = child_result {
let wait_result = child.wait();
match wait_result {
Ok(status) => {
if !status.success() {
bail!("Failed to install kernelspec, try again.");
}
}
Err(err) => {
bail!("Failed to install kernelspec: {}", err);
let wait_result = child.wait();
match wait_result {
Ok(status) => {
if !status.success() {
bail!("Failed to install kernelspec, try again.");
}
}
Err(err) => {
bail!("Failed to install kernelspec: {}", err);
}
}

let _ = std::fs::remove_dir(temp_dir);
Expand Down
Loading

0 comments on commit 744a463

Please sign in to comment.