Skip to content

Commit

Permalink
Revert "feat(cli): Add deno cache --test and --worker (denoland#7920)" (
Browse files Browse the repository at this point in the history
denoland#8089)

This reverts commit be15cf2.
  • Loading branch information
bartlomieju authored Oct 23, 2020
1 parent be15cf2 commit 9d36331
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 176 deletions.
95 changes: 5 additions & 90 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use clap::App;
use clap::AppSettings;
use clap::Arg;
use clap::ArgGroup;
use clap::ArgMatches;
use clap::ArgSettings;
use clap::SubCommand;
Expand Down Expand Up @@ -38,8 +37,6 @@ pub enum DenoSubcommand {
},
Cache {
files: Vec<String>,
worker_specifiers: Option<Vec<String>>,
test_patterns: Option<Vec<String>>,
},
Fmt {
check: bool,
Expand Down Expand Up @@ -484,20 +481,10 @@ fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
compile_args_parse(flags, matches);
let files = matches
.values_of("file")
.unwrap_or_default()
.unwrap()
.map(String::from)
.collect();
let worker_specifiers = matches
.values_of("worker")
.map(|v| v.map(String::from).collect());
let test_patterns = matches
.values_of("test")
.map(|v| v.map(String::from).collect());
flags.subcommand = DenoSubcommand::Cache {
files,
worker_specifiers,
test_patterns,
};
flags.subcommand = DenoSubcommand::Cache { files };
}

fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
Expand Down Expand Up @@ -884,31 +871,11 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",

fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
compile_args(SubCommand::with_name("cache"))
.arg(Arg::with_name("file").takes_value(true).multiple(true))
.arg(
Arg::with_name("worker")
.long("worker")
.help("Compile <WORKER_SPECIFIERS> as Deno web workers")
.takes_value(true)
.value_name("WORKER_SPECIFIERS")
.min_values(1)
.use_delimiter(true),
)
.arg(
Arg::with_name("test")
.long("test")
.help("Includes files captured by: deno test <PATTERN_LIST>")
Arg::with_name("file")
.takes_value(true)
.value_name("PATTERN_LIST")
.min_values(0)
.use_delimiter(true)
.require_equals(true),
)
.group(
ArgGroup::with_name("target")
.args(&["file", "test", "worker"])
.multiple(true)
.required(true),
.required(true)
.min_values(1),
)
.about("Cache the dependencies")
.long_about(
Expand Down Expand Up @@ -1946,52 +1913,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Cache {
files: svec!["script.ts"],
worker_specifiers: None,
test_patterns: None,
},
..Flags::default()
}
);

let r = flags_from_vec_safe(svec!["deno", "cache", "--test"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Cache {
files: svec![],
worker_specifiers: None,
test_patterns: Some(svec![]),
},
..Flags::default()
}
);

let r = flags_from_vec_safe(svec!["deno", "cache", "--test=a,b"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Cache {
files: svec![],
test_patterns: Some(svec!["a", "b"]),
worker_specifiers: None,
},
..Flags::default()
}
);

let r = flags_from_vec_safe(svec![
"deno",
"cache",
"--worker",
"worker1.ts,worker2.ts"
]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Cache {
files: svec![],
test_patterns: None,
worker_specifiers: Some(svec!["worker1.ts", "worker2.ts"]),
},
..Flags::default()
}
Expand Down Expand Up @@ -2493,8 +2414,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Cache {
files: svec!["script.ts"],
worker_specifiers: None,
test_patterns: None,
},
unstable: true,
import_map_path: Some("import_map.json".to_owned()),
Expand Down Expand Up @@ -2537,8 +2456,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Cache {
files: svec!["script.ts", "script_two.ts"],
worker_specifiers: None,
test_patterns: None,
},
..Flags::default()
}
Expand Down Expand Up @@ -3062,8 +2979,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Cache {
files: svec!["script.ts", "script_two.ts"],
worker_specifiers: None,
test_patterns: None,
},
ca_file: Some("example.crt".to_owned()),
..Flags::default()
Expand Down
88 changes: 21 additions & 67 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ use std::pin::Pin;
use std::rc::Rc;
use std::sync::Arc;
use upgrade::upgrade_command;
use worker::WebWorker;

fn write_to_stdout_ignore_sigpipe(bytes: &[u8]) -> Result<(), std::io::Error> {
use std::io::ErrorKind;
Expand Down Expand Up @@ -237,8 +236,6 @@ async fn lint_command(
async fn cache_command(
flags: Flags,
files: Vec<String>,
worker_specifiers: Option<Vec<String>>,
test_patterns: Option<Vec<String>>,
) -> Result<(), AnyError> {
let main_module =
ModuleSpecifier::resolve_url_or_path("./$deno$cache.ts").unwrap();
Expand All @@ -252,48 +249,6 @@ async fn cache_command(
worker.preload_module(&specifier).await.map(|_| ())?;
}

if let Some(worker_specifiers) = worker_specifiers {
let mut web_worker = WebWorker::new(
"".to_string(),
Permissions::allow_all(),
main_module,
program_state.clone(),
true,
);
for specifier in worker_specifiers {
let specifier = ModuleSpecifier::resolve_url_or_path(&specifier)?;
web_worker.preload_module(&specifier).await.map(|_| ())?;
}
}

if let Some(test_patterns) = test_patterns {
let cwd = std::env::current_dir().expect("No current directory");
let mut include = test_patterns;
if include.is_empty() {
include.push(".".to_string());
}
let specifier = ModuleSpecifier::resolve_path("$deno$test.ts")?;
// Create a dummy source file.
let source_file = SourceFile {
filename: specifier.as_url().to_file_path().unwrap(),
url: specifier.as_url().clone(),
types_header: None,
media_type: MediaType::TypeScript,
source_code: test_runner::render_test_file(
test_runner::prepare_test_modules_urls(include, &cwd)?,
false,
false,
None,
),
};
// Save our fake file into file fetcher cache
// to allow module access by TS compiler
program_state
.file_fetcher
.save_source_file_in_cache(&specifier, source_file);
worker.preload_module(&specifier).await.map(|_| ())?;
}

Ok(())
}

Expand Down Expand Up @@ -677,28 +632,33 @@ async fn test_command(
}
return Ok(());
}
let main_module = ModuleSpecifier::resolve_path("$deno$test.ts")?;

let test_file_path = cwd.join("$deno$test.ts");
let test_file_url =
Url::from_file_path(&test_file_path).expect("Should be valid file url");
let test_file = test_runner::render_test_file(
test_modules.clone(),
fail_fast,
quiet,
filter,
);
let main_module =
ModuleSpecifier::resolve_url(&test_file_url.to_string()).unwrap();
let mut worker = MainWorker::new(&program_state, main_module.clone());
// Create a dummy source file.
let source_file = SourceFile {
filename: main_module.as_url().to_file_path().unwrap(),
url: main_module.as_url().clone(),
filename: test_file_url.to_file_path().unwrap(),
url: test_file_url.clone(),
types_header: None,
media_type: MediaType::TypeScript,
source_code: test_runner::render_test_file(
test_modules.clone(),
fail_fast,
quiet,
filter,
),
source_code: test_file.clone(),
};
// Save our fake file into file fetcher cache
// to allow module access by TS compiler
program_state
.file_fetcher
.save_source_file_in_cache(&main_module, source_file);

let mut worker = MainWorker::new(&program_state, main_module.clone());

let mut maybe_coverage_collector = if flags.coverage {
let session = worker.create_inspector_session();
let mut coverage_collector = CoverageCollector::new(session);
Expand All @@ -720,11 +680,8 @@ async fn test_command(
let coverages = coverage_collector.collect().await?;
coverage_collector.stop_collecting().await?;

let filtered_coverages = coverage::filter_script_coverages(
coverages,
main_module.as_url().clone(),
test_modules,
);
let filtered_coverages =
coverage::filter_script_coverages(coverages, test_file_url, test_modules);

let mut coverage_reporter = PrettyCoverageReporter::new(quiet);
for coverage in filtered_coverages {
Expand Down Expand Up @@ -814,12 +771,9 @@ pub fn main() {
code,
as_typescript,
} => eval_command(flags, code, as_typescript, print).boxed_local(),
DenoSubcommand::Cache {
files,
worker_specifiers,
test_patterns,
} => cache_command(flags, files, worker_specifiers, test_patterns)
.boxed_local(),
DenoSubcommand::Cache { files } => {
cache_command(flags, files).boxed_local()
}
DenoSubcommand::Fmt {
check,
files,
Expand Down
4 changes: 0 additions & 4 deletions cli/tests/068_cache_test_type_error.out

This file was deleted.

12 changes: 0 additions & 12 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2137,18 +2137,6 @@ fn _066_prompt() {
util::test_pty(args, output, input);
}

itest!(_068_cache_test_type_error {
args: "cache --test=test_type_error",
output: "068_cache_test_type_error.out",
exit_code: 1,
});

itest!(_069_cache_worker {
args: "cache --worker subdir/worker_globals.ts",
output_str: Some("[WILDCARD]"),
exit_code: 0,
});

itest!(_073_worker_error {
args: "run -A 073_worker_error.ts",
output: "073_worker_error.ts.out",
Expand Down
2 changes: 0 additions & 2 deletions cli/tests/test_type_error/foo_test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion core/module_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl ModuleSpecifier {
/// Converts a string representing a relative or absolute path into a
/// ModuleSpecifier. A relative path is considered relative to the current
/// working directory.
pub fn resolve_path(
fn resolve_path(
path_str: &str,
) -> Result<ModuleSpecifier, ModuleResolutionError> {
let path = current_dir().unwrap().join(path_str);
Expand Down

0 comments on commit 9d36331

Please sign in to comment.