2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-02-11 06:01:56 -05:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
use crate::cache;
|
|
|
|
use crate::cache::CacherLoader;
|
2021-04-28 14:17:04 -04:00
|
|
|
use crate::colors;
|
2021-12-30 11:18:30 -05:00
|
|
|
use crate::compat;
|
2021-04-28 14:17:04 -04:00
|
|
|
use crate::create_main_worker;
|
2021-10-10 17:26:22 -04:00
|
|
|
use crate::emit;
|
2021-04-28 14:17:04 -04:00
|
|
|
use crate::file_fetcher::File;
|
2021-08-26 15:21:58 -04:00
|
|
|
use crate::file_watcher;
|
|
|
|
use crate::file_watcher::ResolutionResult;
|
2021-12-16 05:45:41 -05:00
|
|
|
use crate::flags::CheckFlag;
|
2021-08-26 15:21:58 -04:00
|
|
|
use crate::flags::Flags;
|
2021-12-20 16:29:02 -05:00
|
|
|
use crate::flags::TestFlags;
|
2021-08-26 15:21:58 -04:00
|
|
|
use crate::fs_util::collect_specifiers;
|
|
|
|
use crate::fs_util::is_supported_test_ext;
|
|
|
|
use crate::fs_util::is_supported_test_path;
|
2021-12-16 05:45:41 -05:00
|
|
|
use crate::graph_util::graph_valid;
|
2021-09-04 14:19:26 -04:00
|
|
|
use crate::located_script_name;
|
2021-10-10 17:26:22 -04:00
|
|
|
use crate::lockfile;
|
2021-08-17 06:08:39 -04:00
|
|
|
use crate::ops;
|
2021-09-24 11:10:42 -04:00
|
|
|
use crate::proc_state::ProcState;
|
2021-10-10 17:26:22 -04:00
|
|
|
use crate::resolver::ImportMapResolver;
|
2021-11-08 20:26:39 -05:00
|
|
|
use crate::resolver::JsxResolver;
|
2021-04-28 14:17:04 -04:00
|
|
|
use crate::tools::coverage::CoverageCollector;
|
2021-10-10 17:26:22 -04:00
|
|
|
|
2021-09-07 10:39:32 -04:00
|
|
|
use deno_ast::swc::common::comments::CommentKind;
|
|
|
|
use deno_ast::MediaType;
|
2021-07-22 07:34:29 -04:00
|
|
|
use deno_core::error::generic_error;
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2021-04-28 14:17:04 -04:00
|
|
|
use deno_core::futures::future;
|
|
|
|
use deno_core::futures::stream;
|
2021-05-26 11:47:33 -04:00
|
|
|
use deno_core::futures::FutureExt;
|
2021-04-28 14:17:04 -04:00
|
|
|
use deno_core::futures::StreamExt;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::serde_json::json;
|
2021-04-28 14:17:04 -04:00
|
|
|
use deno_core::ModuleSpecifier;
|
2021-12-14 15:39:20 -05:00
|
|
|
use deno_graph::Module;
|
2021-04-28 14:17:04 -04:00
|
|
|
use deno_runtime::permissions::Permissions;
|
2021-10-21 07:05:43 -04:00
|
|
|
use deno_runtime::tokio_util::run_basic;
|
2021-08-23 10:03:57 -04:00
|
|
|
use log::Level;
|
2021-07-05 21:20:33 -04:00
|
|
|
use rand::rngs::SmallRng;
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
use rand::SeedableRng;
|
2021-05-10 19:54:39 -04:00
|
|
|
use regex::Regex;
|
2021-04-28 14:17:04 -04:00
|
|
|
use serde::Deserialize;
|
2021-10-11 09:45:02 -04:00
|
|
|
use std::collections::HashMap;
|
2021-08-26 15:21:58 -04:00
|
|
|
use std::collections::HashSet;
|
2021-10-11 09:45:02 -04:00
|
|
|
use std::io::Write;
|
2021-08-23 06:35:38 -04:00
|
|
|
use std::num::NonZeroUsize;
|
2021-04-28 14:17:04 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
use std::sync::mpsc::Sender;
|
|
|
|
use std::sync::Arc;
|
2021-07-13 18:11:58 -04:00
|
|
|
use std::time::Duration;
|
2021-04-29 07:42:35 -04:00
|
|
|
use std::time::Instant;
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
/// The test mode is used to determine how a specifier is to be tested.
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
enum TestMode {
|
|
|
|
/// Test as documentation, type-checking fenced code blocks.
|
|
|
|
Documentation,
|
|
|
|
/// Test as an executable module, loading the module into the isolate and running each test it
|
|
|
|
/// defines.
|
|
|
|
Executable,
|
|
|
|
/// Test as both documentation and an executable module.
|
|
|
|
Both,
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Eq, Hash)]
|
2021-07-14 15:05:16 -04:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TestDescription {
|
|
|
|
pub origin: String,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
2021-09-04 09:16:35 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum TestOutput {
|
|
|
|
// TODO(caspervonb): add stdout and stderr redirection.
|
|
|
|
Console(String),
|
|
|
|
}
|
|
|
|
|
2021-04-28 14:17:04 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum TestResult {
|
|
|
|
Ok,
|
|
|
|
Ignored,
|
|
|
|
Failed(String),
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TestStepDescription {
|
|
|
|
pub test: TestDescription,
|
|
|
|
pub level: usize,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum TestStepResult {
|
|
|
|
Ok,
|
|
|
|
Ignored,
|
|
|
|
Failed(Option<String>),
|
|
|
|
Pending(Option<String>),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestStepResult {
|
|
|
|
fn error(&self) -> Option<&str> {
|
|
|
|
match self {
|
|
|
|
TestStepResult::Failed(Some(text)) => Some(text.as_str()),
|
|
|
|
TestStepResult::Pending(Some(text)) => Some(text.as_str()),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TestPlan {
|
|
|
|
pub origin: String,
|
|
|
|
pub total: usize,
|
|
|
|
pub filtered_out: usize,
|
|
|
|
pub used_only: bool,
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
2020-02-11 06:01:56 -05:00
|
|
|
|
2021-04-30 11:56:47 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
2021-07-14 15:05:16 -04:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum TestEvent {
|
|
|
|
Plan(TestPlan),
|
|
|
|
Wait(TestDescription),
|
2021-09-04 09:16:35 -04:00
|
|
|
Output(TestOutput),
|
2021-07-14 15:05:16 -04:00
|
|
|
Result(TestDescription, TestResult, u64),
|
2021-10-11 09:45:02 -04:00
|
|
|
StepWait(TestStepDescription),
|
|
|
|
StepResult(TestStepDescription, TestStepResult, u64),
|
2021-04-30 11:56:47 -04:00
|
|
|
}
|
|
|
|
|
2021-07-13 18:11:58 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
pub struct TestSummary {
|
|
|
|
pub total: usize,
|
|
|
|
pub passed: usize,
|
|
|
|
pub failed: usize,
|
|
|
|
pub ignored: usize,
|
2021-11-15 10:20:37 -05:00
|
|
|
pub passed_steps: usize,
|
|
|
|
pub failed_steps: usize,
|
|
|
|
pub pending_steps: usize,
|
|
|
|
pub ignored_steps: usize,
|
2021-07-13 18:11:58 -04:00
|
|
|
pub filtered_out: usize,
|
|
|
|
pub measured: usize,
|
2021-07-14 15:05:16 -04:00
|
|
|
pub failures: Vec<(TestDescription, String)>,
|
2021-07-13 18:11:58 -04:00
|
|
|
}
|
|
|
|
|
2021-12-30 11:18:30 -05:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
struct TestSpecifierOptions {
|
|
|
|
compat_mode: bool,
|
|
|
|
concurrent_jobs: NonZeroUsize,
|
|
|
|
fail_fast: Option<NonZeroUsize>,
|
|
|
|
filter: Option<String>,
|
|
|
|
shuffle: Option<u64>,
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:11:58 -04:00
|
|
|
impl TestSummary {
|
|
|
|
fn new() -> TestSummary {
|
|
|
|
TestSummary {
|
|
|
|
total: 0,
|
|
|
|
passed: 0,
|
|
|
|
failed: 0,
|
|
|
|
ignored: 0,
|
2021-11-15 10:20:37 -05:00
|
|
|
passed_steps: 0,
|
|
|
|
failed_steps: 0,
|
|
|
|
pending_steps: 0,
|
|
|
|
ignored_steps: 0,
|
2021-07-13 18:11:58 -04:00
|
|
|
filtered_out: 0,
|
|
|
|
measured: 0,
|
|
|
|
failures: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn has_failed(&self) -> bool {
|
|
|
|
self.failed > 0 || !self.failures.is_empty()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn has_pending(&self) -> bool {
|
|
|
|
self.total - self.passed - self.failed - self.ignored > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 07:42:35 -04:00
|
|
|
trait TestReporter {
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_plan(&mut self, plan: &TestPlan);
|
|
|
|
fn report_wait(&mut self, description: &TestDescription);
|
2021-09-04 09:16:35 -04:00
|
|
|
fn report_output(&mut self, output: &TestOutput);
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_result(
|
|
|
|
&mut self,
|
|
|
|
description: &TestDescription,
|
|
|
|
result: &TestResult,
|
|
|
|
elapsed: u64,
|
|
|
|
);
|
2021-10-11 09:45:02 -04:00
|
|
|
fn report_step_wait(&mut self, description: &TestStepDescription);
|
|
|
|
fn report_step_result(
|
|
|
|
&mut self,
|
|
|
|
description: &TestStepDescription,
|
|
|
|
result: &TestStepResult,
|
|
|
|
elapsed: u64,
|
|
|
|
);
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_summary(&mut self, summary: &TestSummary, elapsed: &Duration);
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
enum DeferredStepOutput {
|
|
|
|
StepWait(TestStepDescription),
|
|
|
|
StepResult(TestStepDescription, TestStepResult, u64),
|
|
|
|
}
|
|
|
|
|
2021-04-29 07:42:35 -04:00
|
|
|
struct PrettyTestReporter {
|
|
|
|
concurrent: bool,
|
2021-09-04 09:16:35 -04:00
|
|
|
echo_output: bool,
|
2021-10-11 09:45:02 -04:00
|
|
|
deferred_step_output: HashMap<TestDescription, Vec<DeferredStepOutput>>,
|
|
|
|
last_wait_output_level: usize,
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PrettyTestReporter {
|
2021-09-04 09:16:35 -04:00
|
|
|
fn new(concurrent: bool, echo_output: bool) -> PrettyTestReporter {
|
|
|
|
PrettyTestReporter {
|
|
|
|
concurrent,
|
|
|
|
echo_output,
|
2021-10-11 09:45:02 -04:00
|
|
|
deferred_step_output: HashMap::new(),
|
|
|
|
last_wait_output_level: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn force_report_wait(&mut self, description: &TestDescription) {
|
|
|
|
print!("test {} ...", description.name);
|
|
|
|
// flush for faster feedback when line buffered
|
|
|
|
std::io::stdout().flush().unwrap();
|
|
|
|
self.last_wait_output_level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn force_report_step_wait(&mut self, description: &TestStepDescription) {
|
|
|
|
if self.last_wait_output_level < description.level {
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
print!(
|
|
|
|
"{}test {} ...",
|
|
|
|
" ".repeat(description.level),
|
|
|
|
description.name
|
|
|
|
);
|
|
|
|
// flush for faster feedback when line buffered
|
|
|
|
std::io::stdout().flush().unwrap();
|
|
|
|
self.last_wait_output_level = description.level;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn force_report_step_result(
|
|
|
|
&mut self,
|
|
|
|
description: &TestStepDescription,
|
|
|
|
result: &TestStepResult,
|
|
|
|
elapsed: u64,
|
|
|
|
) {
|
|
|
|
let status = match result {
|
|
|
|
TestStepResult::Ok => colors::green("ok").to_string(),
|
|
|
|
TestStepResult::Ignored => colors::yellow("ignored").to_string(),
|
|
|
|
TestStepResult::Pending(_) => colors::gray("pending").to_string(),
|
|
|
|
TestStepResult::Failed(_) => colors::red("FAILED").to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if self.last_wait_output_level == description.level {
|
|
|
|
print!(" ");
|
|
|
|
} else {
|
|
|
|
print!("{}", " ".repeat(description.level));
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:10:12 -05:00
|
|
|
println!("{} {}", status, colors::gray(human_elapsed(elapsed.into())));
|
2021-10-11 09:45:02 -04:00
|
|
|
|
|
|
|
if let Some(error_text) = result.error() {
|
|
|
|
for line in error_text.lines() {
|
|
|
|
println!("{}{}", " ".repeat(description.level + 1), line);
|
|
|
|
}
|
2021-09-04 09:16:35 -04:00
|
|
|
}
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 16:49:46 -04:00
|
|
|
/// A function that converts a milisecond elapsed time to a string that
|
|
|
|
/// represents a human readable version of that time.
|
|
|
|
fn human_elapsed(elapsed: u128) -> String {
|
|
|
|
if elapsed < 1_000 {
|
|
|
|
return format!("({}ms)", elapsed);
|
|
|
|
}
|
|
|
|
if elapsed < 1_000 * 60 {
|
|
|
|
return format!("({}s)", elapsed / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
let seconds = elapsed / 1_000;
|
|
|
|
let minutes = seconds / 60;
|
2021-10-31 17:34:58 -04:00
|
|
|
let seconds_remainder = seconds % 60;
|
|
|
|
format!("({}m{}s)", minutes, seconds_remainder)
|
2021-10-30 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
2021-04-29 07:42:35 -04:00
|
|
|
impl TestReporter for PrettyTestReporter {
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_plan(&mut self, plan: &TestPlan) {
|
|
|
|
let inflection = if plan.total == 1 { "test" } else { "tests" };
|
|
|
|
println!("running {} {} from {}", plan.total, inflection, plan.origin);
|
|
|
|
}
|
2021-04-29 07:42:35 -04:00
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_wait(&mut self, description: &TestDescription) {
|
|
|
|
if !self.concurrent {
|
2021-10-11 09:45:02 -04:00
|
|
|
self.force_report_wait(description);
|
2021-07-14 15:05:16 -04:00
|
|
|
}
|
|
|
|
}
|
2021-04-29 07:42:35 -04:00
|
|
|
|
2021-09-04 09:16:35 -04:00
|
|
|
fn report_output(&mut self, output: &TestOutput) {
|
|
|
|
if self.echo_output {
|
|
|
|
match output {
|
|
|
|
TestOutput::Console(line) => println!("{}", line),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_result(
|
|
|
|
&mut self,
|
|
|
|
description: &TestDescription,
|
|
|
|
result: &TestResult,
|
|
|
|
elapsed: u64,
|
|
|
|
) {
|
|
|
|
if self.concurrent {
|
2021-10-11 09:45:02 -04:00
|
|
|
self.force_report_wait(description);
|
|
|
|
|
|
|
|
if let Some(step_outputs) = self.deferred_step_output.remove(description)
|
|
|
|
{
|
|
|
|
for step_output in step_outputs {
|
|
|
|
match step_output {
|
|
|
|
DeferredStepOutput::StepWait(description) => {
|
|
|
|
self.force_report_step_wait(&description)
|
|
|
|
}
|
|
|
|
DeferredStepOutput::StepResult(
|
|
|
|
step_description,
|
|
|
|
step_result,
|
|
|
|
elapsed,
|
|
|
|
) => self.force_report_step_result(
|
|
|
|
&step_description,
|
|
|
|
&step_result,
|
|
|
|
elapsed,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 15:05:16 -04:00
|
|
|
}
|
2021-07-13 18:11:58 -04:00
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
let status = match result {
|
|
|
|
TestResult::Ok => colors::green("ok").to_string(),
|
|
|
|
TestResult::Ignored => colors::yellow("ignored").to_string(),
|
|
|
|
TestResult::Failed(_) => colors::red("FAILED").to_string(),
|
|
|
|
};
|
2021-07-13 18:11:58 -04:00
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
if self.last_wait_output_level == 0 {
|
|
|
|
print!(" ");
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:10:12 -05:00
|
|
|
println!("{} {}", status, colors::gray(human_elapsed(elapsed.into())));
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
fn report_step_wait(&mut self, description: &TestStepDescription) {
|
|
|
|
if self.concurrent {
|
|
|
|
self
|
|
|
|
.deferred_step_output
|
|
|
|
.entry(description.test.to_owned())
|
|
|
|
.or_insert_with(Vec::new)
|
|
|
|
.push(DeferredStepOutput::StepWait(description.clone()));
|
|
|
|
} else {
|
|
|
|
self.force_report_step_wait(description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn report_step_result(
|
|
|
|
&mut self,
|
|
|
|
description: &TestStepDescription,
|
|
|
|
result: &TestStepResult,
|
|
|
|
elapsed: u64,
|
|
|
|
) {
|
|
|
|
if self.concurrent {
|
|
|
|
self
|
|
|
|
.deferred_step_output
|
|
|
|
.entry(description.test.to_owned())
|
|
|
|
.or_insert_with(Vec::new)
|
|
|
|
.push(DeferredStepOutput::StepResult(
|
|
|
|
description.clone(),
|
|
|
|
result.clone(),
|
|
|
|
elapsed,
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
self.force_report_step_result(description, result, elapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
fn report_summary(&mut self, summary: &TestSummary, elapsed: &Duration) {
|
2021-07-13 18:11:58 -04:00
|
|
|
if !summary.failures.is_empty() {
|
2021-04-29 07:42:35 -04:00
|
|
|
println!("\nfailures:\n");
|
2021-07-14 15:05:16 -04:00
|
|
|
for (description, error) in &summary.failures {
|
|
|
|
println!("{}", description.name);
|
2021-04-29 07:42:35 -04:00
|
|
|
println!("{}", error);
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("failures:\n");
|
2021-07-14 15:05:16 -04:00
|
|
|
for (description, _) in &summary.failures {
|
|
|
|
println!("\t{}", description.name);
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:11:58 -04:00
|
|
|
let status = if summary.has_failed() || summary.has_pending() {
|
2021-04-29 07:42:35 -04:00
|
|
|
colors::red("FAILED").to_string()
|
|
|
|
} else {
|
|
|
|
colors::green("ok").to_string()
|
|
|
|
};
|
|
|
|
|
2021-11-15 10:20:37 -05:00
|
|
|
let get_steps_text = |count: usize| -> String {
|
|
|
|
if count == 0 {
|
|
|
|
String::new()
|
|
|
|
} else if count == 1 {
|
|
|
|
" (1 step)".to_string()
|
|
|
|
} else {
|
|
|
|
format!(" ({} steps)", count)
|
|
|
|
}
|
|
|
|
};
|
2021-04-29 07:42:35 -04:00
|
|
|
println!(
|
2021-11-15 10:20:37 -05:00
|
|
|
"\ntest result: {}. {} passed{}; {} failed{}; {} ignored{}; {} measured; {} filtered out {}\n",
|
2021-07-14 15:05:16 -04:00
|
|
|
status,
|
|
|
|
summary.passed,
|
2021-11-15 10:20:37 -05:00
|
|
|
get_steps_text(summary.passed_steps),
|
2021-07-14 15:05:16 -04:00
|
|
|
summary.failed,
|
2021-11-15 10:20:37 -05:00
|
|
|
get_steps_text(summary.failed_steps + summary.pending_steps),
|
2021-07-14 15:05:16 -04:00
|
|
|
summary.ignored,
|
2021-11-15 10:20:37 -05:00
|
|
|
get_steps_text(summary.ignored_steps),
|
2021-07-14 15:05:16 -04:00
|
|
|
summary.measured,
|
|
|
|
summary.filtered_out,
|
2021-10-30 16:49:46 -04:00
|
|
|
colors::gray(human_elapsed(elapsed.as_millis())),
|
2021-07-14 15:05:16 -04:00
|
|
|
);
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-04 09:16:35 -04:00
|
|
|
fn create_reporter(
|
|
|
|
concurrent: bool,
|
|
|
|
echo_output: bool,
|
|
|
|
) -> Box<dyn TestReporter + Send> {
|
|
|
|
Box::new(PrettyTestReporter::new(concurrent, echo_output))
|
2021-04-29 07:42:35 -04:00
|
|
|
}
|
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
/// Test a single specifier as documentation containing test programs, an executable test module or
|
|
|
|
/// both.
|
|
|
|
async fn test_specifier(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps: ProcState,
|
2021-04-28 14:17:04 -04:00
|
|
|
permissions: Permissions,
|
2021-08-26 15:21:58 -04:00
|
|
|
specifier: ModuleSpecifier,
|
|
|
|
mode: TestMode,
|
2021-04-30 11:56:47 -04:00
|
|
|
channel: Sender<TestEvent>,
|
2021-12-30 11:18:30 -05:00
|
|
|
options: TestSpecifierOptions,
|
2021-04-28 14:17:04 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2021-12-29 08:30:08 -05:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps,
|
|
|
|
specifier.clone(),
|
|
|
|
permissions,
|
|
|
|
vec![ops::testing::init(channel.clone())],
|
|
|
|
);
|
2021-04-28 14:17:04 -04:00
|
|
|
|
|
|
|
let mut maybe_coverage_collector = if let Some(ref coverage_dir) =
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.coverage_dir
|
2021-04-28 14:17:04 -04:00
|
|
|
{
|
2021-05-26 11:47:33 -04:00
|
|
|
let session = worker.create_inspector_session().await;
|
2021-04-28 14:17:04 -04:00
|
|
|
let coverage_dir = PathBuf::from(coverage_dir);
|
|
|
|
let mut coverage_collector = CoverageCollector::new(coverage_dir, session);
|
2021-05-26 11:47:33 -04:00
|
|
|
worker
|
|
|
|
.with_event_loop(coverage_collector.start_collecting().boxed_local())
|
|
|
|
.await?;
|
2021-04-28 14:17:04 -04:00
|
|
|
|
|
|
|
Some(coverage_collector)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-09-18 10:12:50 -04:00
|
|
|
// We only execute the specifier as a module if it is tagged with TestMode::Module or
|
|
|
|
// TestMode::Both.
|
|
|
|
if mode != TestMode::Documentation {
|
2021-12-30 11:18:30 -05:00
|
|
|
if options.compat_mode {
|
|
|
|
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
|
|
|
worker.execute_side_module(&compat::MODULE_URL).await?;
|
|
|
|
|
|
|
|
let use_esm_loader = compat::check_if_should_use_esm_loader(&specifier)?;
|
|
|
|
|
|
|
|
if use_esm_loader {
|
|
|
|
worker.execute_side_module(&specifier).await?;
|
|
|
|
} else {
|
|
|
|
compat::load_cjs_module(
|
|
|
|
&mut worker.js_runtime,
|
|
|
|
&specifier.to_file_path().unwrap().display().to_string(),
|
|
|
|
false,
|
|
|
|
)?;
|
|
|
|
worker.run_event_loop(false).await?;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We execute the module module as a side module so that import.meta.main is not set.
|
|
|
|
worker.execute_side_module(&specifier).await?;
|
|
|
|
}
|
2021-09-18 10:12:50 -04:00
|
|
|
}
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-12-21 09:49:27 -05:00
|
|
|
worker.dispatch_load_event(&located_script_name!())?;
|
2021-09-04 14:19:26 -04:00
|
|
|
|
|
|
|
let test_result = worker.js_runtime.execute_script(
|
|
|
|
&located_script_name!(),
|
|
|
|
&format!(
|
|
|
|
r#"Deno[Deno.internal].runTests({})"#,
|
|
|
|
json!({
|
2021-12-30 11:18:30 -05:00
|
|
|
"filter": options.filter,
|
|
|
|
"shuffle": options.shuffle,
|
2021-09-04 14:19:26 -04:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
worker.js_runtime.resolve_value(test_result).await?;
|
|
|
|
|
2021-12-21 09:49:27 -05:00
|
|
|
worker.dispatch_unload_event(&located_script_name!())?;
|
2021-04-28 14:17:04 -04:00
|
|
|
|
|
|
|
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
|
2021-05-26 11:47:33 -04:00
|
|
|
worker
|
|
|
|
.with_event_loop(coverage_collector.stop_collecting().boxed_local())
|
|
|
|
.await?;
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-07-29 15:03:06 -04:00
|
|
|
fn extract_files_from_regex_blocks(
|
2022-01-13 11:58:00 -05:00
|
|
|
specifier: &ModuleSpecifier,
|
2021-07-29 15:03:06 -04:00
|
|
|
source: &str,
|
2021-09-07 10:39:32 -04:00
|
|
|
media_type: MediaType,
|
2022-01-13 11:58:00 -05:00
|
|
|
file_line_index: usize,
|
2021-07-29 15:03:06 -04:00
|
|
|
blocks_regex: &Regex,
|
|
|
|
lines_regex: &Regex,
|
|
|
|
) -> Result<Vec<File>, AnyError> {
|
|
|
|
let files = blocks_regex
|
2021-07-30 09:03:41 -04:00
|
|
|
.captures_iter(source)
|
2021-07-29 15:03:06 -04:00
|
|
|
.filter_map(|block| {
|
2021-08-14 06:33:58 -04:00
|
|
|
let maybe_attributes: Option<Vec<_>> = block
|
2021-07-29 15:03:06 -04:00
|
|
|
.get(1)
|
2021-08-14 06:33:58 -04:00
|
|
|
.map(|attributes| attributes.as_str().split(' ').collect());
|
|
|
|
|
|
|
|
let file_media_type = if let Some(attributes) = maybe_attributes {
|
|
|
|
if attributes.contains(&"ignore") {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
match attributes.get(0) {
|
|
|
|
Some(&"js") => MediaType::JavaScript,
|
2021-11-01 16:22:27 -04:00
|
|
|
Some(&"mjs") => MediaType::Mjs,
|
|
|
|
Some(&"cjs") => MediaType::Cjs,
|
2021-08-14 06:33:58 -04:00
|
|
|
Some(&"jsx") => MediaType::Jsx,
|
|
|
|
Some(&"ts") => MediaType::TypeScript,
|
2021-11-01 16:22:27 -04:00
|
|
|
Some(&"mts") => MediaType::Mts,
|
|
|
|
Some(&"cts") => MediaType::Cts,
|
2021-08-14 06:33:58 -04:00
|
|
|
Some(&"tsx") => MediaType::Tsx,
|
2021-09-07 10:39:32 -04:00
|
|
|
Some(&"") => media_type,
|
2021-07-29 15:03:06 -04:00
|
|
|
_ => MediaType::Unknown,
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-07 10:39:32 -04:00
|
|
|
media_type
|
2021-07-29 15:03:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if file_media_type == MediaType::Unknown {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let line_offset = source[0..block.get(0).unwrap().start()]
|
|
|
|
.chars()
|
|
|
|
.filter(|c| *c == '\n')
|
|
|
|
.count();
|
|
|
|
|
|
|
|
let line_count = block.get(0).unwrap().as_str().split('\n').count();
|
|
|
|
|
|
|
|
let body = block.get(2).unwrap();
|
|
|
|
let text = body.as_str();
|
|
|
|
|
|
|
|
// TODO(caspervonb) generate an inline source map
|
|
|
|
let mut file_source = String::new();
|
2021-07-30 09:03:41 -04:00
|
|
|
for line in lines_regex.captures_iter(text) {
|
2021-07-29 15:03:06 -04:00
|
|
|
let text = line.get(1).unwrap();
|
|
|
|
file_source.push_str(&format!("{}\n", text.as_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
file_source.push_str("export {};");
|
|
|
|
|
|
|
|
let file_specifier = deno_core::resolve_url_or_path(&format!(
|
|
|
|
"{}${}-{}{}",
|
2022-01-13 11:58:00 -05:00
|
|
|
specifier,
|
|
|
|
file_line_index + line_offset + 1,
|
|
|
|
file_line_index + line_offset + line_count + 1,
|
2021-07-29 15:03:06 -04:00
|
|
|
file_media_type.as_ts_extension(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
Some(File {
|
|
|
|
local: file_specifier.to_file_path().unwrap(),
|
|
|
|
maybe_types: None,
|
|
|
|
media_type: file_media_type,
|
2021-09-07 10:39:32 -04:00
|
|
|
source: Arc::new(file_source),
|
2021-07-29 15:03:06 -04:00
|
|
|
specifier: file_specifier,
|
2021-09-02 11:38:19 -04:00
|
|
|
maybe_headers: None,
|
2021-07-29 15:03:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(files)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn extract_files_from_source_comments(
|
|
|
|
specifier: &ModuleSpecifier,
|
2021-09-07 10:39:32 -04:00
|
|
|
source: Arc<String>,
|
|
|
|
media_type: MediaType,
|
2021-07-29 15:03:06 -04:00
|
|
|
) -> Result<Vec<File>, AnyError> {
|
2021-09-07 10:39:32 -04:00
|
|
|
let parsed_source = deno_ast::parse_module(deno_ast::ParseParams {
|
|
|
|
specifier: specifier.as_str().to_string(),
|
2021-09-12 20:06:36 -04:00
|
|
|
source: deno_ast::SourceTextInfo::new(source),
|
2021-09-07 10:39:32 -04:00
|
|
|
media_type,
|
|
|
|
capture_tokens: false,
|
|
|
|
maybe_syntax: None,
|
2021-10-12 09:58:04 -04:00
|
|
|
scope_analysis: false,
|
2021-09-07 10:39:32 -04:00
|
|
|
})?;
|
|
|
|
let comments = parsed_source.comments().get_vec();
|
2021-11-15 09:58:04 -05:00
|
|
|
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
|
2021-07-29 15:03:06 -04:00
|
|
|
let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?;
|
|
|
|
|
|
|
|
let files = comments
|
|
|
|
.iter()
|
|
|
|
.filter(|comment| {
|
|
|
|
if comment.kind != CommentKind::Block || !comment.text.starts_with('*') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
})
|
|
|
|
.flat_map(|comment| {
|
|
|
|
extract_files_from_regex_blocks(
|
2022-01-13 11:58:00 -05:00
|
|
|
specifier,
|
2021-07-29 15:03:06 -04:00
|
|
|
&comment.text,
|
2021-07-30 09:03:41 -04:00
|
|
|
media_type,
|
2022-01-13 11:58:00 -05:00
|
|
|
parsed_source.source().line_index(comment.span.lo),
|
2021-07-29 15:03:06 -04:00
|
|
|
&blocks_regex,
|
|
|
|
&lines_regex,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.flatten()
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(files)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn extract_files_from_fenced_blocks(
|
|
|
|
specifier: &ModuleSpecifier,
|
|
|
|
source: &str,
|
2021-09-07 10:39:32 -04:00
|
|
|
media_type: MediaType,
|
2021-07-29 15:03:06 -04:00
|
|
|
) -> Result<Vec<File>, AnyError> {
|
2021-11-15 09:58:04 -05:00
|
|
|
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
|
2021-07-29 15:03:06 -04:00
|
|
|
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
|
|
|
|
|
|
|
|
extract_files_from_regex_blocks(
|
2022-01-13 11:58:00 -05:00
|
|
|
specifier,
|
2021-07-30 09:03:41 -04:00
|
|
|
source,
|
|
|
|
media_type,
|
2022-01-13 11:58:00 -05:00
|
|
|
/* file line index */ 0,
|
2021-07-29 15:03:06 -04:00
|
|
|
&blocks_regex,
|
|
|
|
&lines_regex,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn fetch_inline_files(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps: ProcState,
|
2021-07-29 15:03:06 -04:00
|
|
|
specifiers: Vec<ModuleSpecifier>,
|
|
|
|
) -> Result<Vec<File>, AnyError> {
|
|
|
|
let mut files = Vec::new();
|
|
|
|
for specifier in specifiers {
|
|
|
|
let mut fetch_permissions = Permissions::allow_all();
|
2021-09-24 11:10:42 -04:00
|
|
|
let file = ps
|
2021-07-29 15:03:06 -04:00
|
|
|
.file_fetcher
|
|
|
|
.fetch(&specifier, &mut fetch_permissions)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let inline_files = if file.media_type == MediaType::Unknown {
|
|
|
|
extract_files_from_fenced_blocks(
|
|
|
|
&file.specifier,
|
|
|
|
&file.source,
|
2021-09-07 10:39:32 -04:00
|
|
|
file.media_type,
|
2021-07-29 15:03:06 -04:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
extract_files_from_source_comments(
|
|
|
|
&file.specifier,
|
2021-09-07 10:39:32 -04:00
|
|
|
file.source.clone(),
|
|
|
|
file.media_type,
|
2021-07-29 15:03:06 -04:00
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
files.extend(inline_files?);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(files)
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
/// Type check a collection of module and document specifiers.
|
|
|
|
async fn check_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps: ProcState,
|
2021-05-10 02:06:13 -04:00
|
|
|
permissions: Permissions,
|
2021-08-26 15:21:58 -04:00
|
|
|
specifiers: Vec<(ModuleSpecifier, TestMode)>,
|
2021-10-10 17:26:22 -04:00
|
|
|
lib: emit::TypeLib,
|
2021-07-22 07:34:29 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2021-08-26 15:21:58 -04:00
|
|
|
let inline_files = fetch_inline_files(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-08-26 15:21:58 -04:00
|
|
|
specifiers
|
|
|
|
.iter()
|
|
|
|
.filter_map(|(specifier, mode)| {
|
|
|
|
if *mode != TestMode::Executable {
|
|
|
|
Some(specifier.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
.await?;
|
2021-07-05 21:20:33 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
if !inline_files.is_empty() {
|
|
|
|
let specifiers = inline_files
|
|
|
|
.iter()
|
|
|
|
.map(|file| file.specifier.clone())
|
|
|
|
.collect();
|
2021-05-10 19:54:39 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
for file in inline_files {
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.file_fetcher.insert_cached(file);
|
2021-05-10 19:54:39 -04:00
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
ps.prepare_module_load(
|
2021-09-24 11:10:42 -04:00
|
|
|
specifiers,
|
2021-10-10 17:26:22 -04:00
|
|
|
false,
|
2021-09-24 11:10:42 -04:00
|
|
|
lib.clone(),
|
|
|
|
Permissions::allow_all(),
|
|
|
|
permissions.clone(),
|
2021-11-15 18:25:52 -05:00
|
|
|
false,
|
2021-09-24 11:10:42 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2021-05-10 19:54:39 -04:00
|
|
|
}
|
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
let module_specifiers = specifiers
|
|
|
|
.iter()
|
|
|
|
.filter_map(|(specifier, mode)| {
|
|
|
|
if *mode != TestMode::Documentation {
|
|
|
|
Some(specifier.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
2021-08-12 14:10:14 -04:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
ps.prepare_module_load(
|
2021-09-24 11:10:42 -04:00
|
|
|
module_specifiers,
|
2021-10-10 17:26:22 -04:00
|
|
|
false,
|
2021-09-24 11:10:42 -04:00
|
|
|
lib,
|
|
|
|
Permissions::allow_all(),
|
|
|
|
permissions,
|
2021-11-15 18:25:52 -05:00
|
|
|
true,
|
2021-09-24 11:10:42 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
/// Test a collection of specifiers with test modes concurrently.
|
|
|
|
async fn test_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps: ProcState,
|
2021-08-26 15:21:58 -04:00
|
|
|
permissions: Permissions,
|
|
|
|
specifiers_with_mode: Vec<(ModuleSpecifier, TestMode)>,
|
2021-12-30 11:18:30 -05:00
|
|
|
options: TestSpecifierOptions,
|
2021-08-26 15:21:58 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2021-09-24 11:10:42 -04:00
|
|
|
let log_level = ps.flags.log_level;
|
2021-12-30 11:18:30 -05:00
|
|
|
let specifiers_with_mode = if let Some(seed) = options.shuffle {
|
2021-08-26 15:21:58 -04:00
|
|
|
let mut rng = SmallRng::seed_from_u64(seed);
|
|
|
|
let mut specifiers_with_mode = specifiers_with_mode.clone();
|
|
|
|
specifiers_with_mode.sort_by_key(|(specifier, _)| specifier.clone());
|
|
|
|
specifiers_with_mode.shuffle(&mut rng);
|
|
|
|
specifiers_with_mode
|
|
|
|
} else {
|
|
|
|
specifiers_with_mode
|
|
|
|
};
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
let (sender, receiver) = channel::<TestEvent>();
|
2021-12-30 11:18:30 -05:00
|
|
|
let concurrent_jobs = options.concurrent_jobs;
|
|
|
|
let fail_fast = options.fail_fast;
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
let join_handles =
|
|
|
|
specifiers_with_mode.iter().map(move |(specifier, mode)| {
|
2021-09-24 11:10:42 -04:00
|
|
|
let ps = ps.clone();
|
2021-08-26 15:21:58 -04:00
|
|
|
let permissions = permissions.clone();
|
|
|
|
let specifier = specifier.clone();
|
|
|
|
let mode = mode.clone();
|
|
|
|
let sender = sender.clone();
|
2021-12-30 11:18:30 -05:00
|
|
|
let options = options.clone();
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
|
|
let join_handle = std::thread::spawn(move || {
|
2021-12-30 11:18:30 -05:00
|
|
|
let future =
|
|
|
|
test_specifier(ps, permissions, specifier, mode, sender, options);
|
2021-08-26 15:21:58 -04:00
|
|
|
|
2021-10-21 07:05:43 -04:00
|
|
|
run_basic(future)
|
2021-08-26 15:21:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
join_handle.join().unwrap()
|
|
|
|
})
|
|
|
|
});
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-07-22 07:34:29 -04:00
|
|
|
let join_stream = stream::iter(join_handles)
|
2021-08-23 06:35:38 -04:00
|
|
|
.buffer_unordered(concurrent_jobs.get())
|
2021-04-28 14:17:04 -04:00
|
|
|
.collect::<Vec<Result<Result<(), AnyError>, tokio::task::JoinError>>>();
|
|
|
|
|
2021-09-04 09:16:35 -04:00
|
|
|
let mut reporter =
|
|
|
|
create_reporter(concurrent_jobs.get() > 1, log_level != Some(Level::Error));
|
|
|
|
|
2021-04-28 14:17:04 -04:00
|
|
|
let handler = {
|
|
|
|
tokio::task::spawn_blocking(move || {
|
2021-07-13 18:11:58 -04:00
|
|
|
let earlier = Instant::now();
|
|
|
|
let mut summary = TestSummary::new();
|
2021-04-28 14:17:04 -04:00
|
|
|
let mut used_only = false;
|
|
|
|
|
2021-04-30 11:56:47 -04:00
|
|
|
for event in receiver.iter() {
|
2021-07-14 15:05:16 -04:00
|
|
|
match event {
|
|
|
|
TestEvent::Plan(plan) => {
|
|
|
|
summary.total += plan.total;
|
|
|
|
summary.filtered_out += plan.filtered_out;
|
|
|
|
|
|
|
|
if plan.used_only {
|
2021-04-28 14:17:04 -04:00
|
|
|
used_only = true;
|
|
|
|
}
|
2021-07-14 15:05:16 -04:00
|
|
|
|
|
|
|
reporter.report_plan(&plan);
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
2021-07-13 18:11:58 -04:00
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
TestEvent::Wait(description) => {
|
|
|
|
reporter.report_wait(&description);
|
|
|
|
}
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-09-04 09:16:35 -04:00
|
|
|
TestEvent::Output(output) => {
|
|
|
|
reporter.report_output(&output);
|
|
|
|
}
|
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
TestEvent::Result(description, result, elapsed) => {
|
|
|
|
match &result {
|
|
|
|
TestResult::Ok => {
|
|
|
|
summary.passed += 1;
|
|
|
|
}
|
|
|
|
TestResult::Ignored => {
|
|
|
|
summary.ignored += 1;
|
|
|
|
}
|
|
|
|
TestResult::Failed(error) => {
|
|
|
|
summary.failed += 1;
|
|
|
|
summary.failures.push((description.clone(), error.clone()));
|
|
|
|
}
|
2021-07-13 18:11:58 -04:00
|
|
|
}
|
2021-04-28 14:17:04 -04:00
|
|
|
|
2021-07-14 15:05:16 -04:00
|
|
|
reporter.report_result(&description, &result, elapsed);
|
|
|
|
}
|
2021-10-11 09:45:02 -04:00
|
|
|
|
|
|
|
TestEvent::StepWait(description) => {
|
|
|
|
reporter.report_step_wait(&description);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestEvent::StepResult(description, result, duration) => {
|
2021-11-15 10:20:37 -05:00
|
|
|
match &result {
|
|
|
|
TestStepResult::Ok => {
|
|
|
|
summary.passed_steps += 1;
|
|
|
|
}
|
|
|
|
TestStepResult::Ignored => {
|
|
|
|
summary.ignored_steps += 1;
|
|
|
|
}
|
|
|
|
TestStepResult::Failed(_) => {
|
|
|
|
summary.failed_steps += 1;
|
|
|
|
}
|
|
|
|
TestStepResult::Pending(_) => {
|
|
|
|
summary.pending_steps += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:45:02 -04:00
|
|
|
reporter.report_step_result(&description, &result, duration);
|
|
|
|
}
|
2021-07-14 15:05:16 -04:00
|
|
|
}
|
2021-04-29 07:42:35 -04:00
|
|
|
|
2021-07-12 06:55:42 -04:00
|
|
|
if let Some(x) = fail_fast {
|
2021-08-23 06:37:02 -04:00
|
|
|
if summary.failed >= x.get() {
|
2021-07-12 06:55:42 -04:00
|
|
|
break;
|
|
|
|
}
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:11:58 -04:00
|
|
|
let elapsed = Instant::now().duration_since(earlier);
|
2021-07-14 15:05:16 -04:00
|
|
|
reporter.report_summary(&summary, &elapsed);
|
2021-04-28 14:17:04 -04:00
|
|
|
|
|
|
|
if used_only {
|
2021-07-22 07:34:29 -04:00
|
|
|
return Err(generic_error(
|
|
|
|
"Test failed because the \"only\" option was used",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if summary.failed > 0 {
|
|
|
|
return Err(generic_error("Test failed"));
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:34:29 -04:00
|
|
|
Ok(())
|
2021-04-28 14:17:04 -04:00
|
|
|
})
|
2020-04-02 09:26:40 -04:00
|
|
|
};
|
|
|
|
|
2021-07-22 07:34:29 -04:00
|
|
|
let (join_results, result) = future::join(join_stream, handler).await;
|
2020-10-14 09:19:13 -04:00
|
|
|
|
2021-09-08 11:18:07 -04:00
|
|
|
// propagate any errors
|
|
|
|
for join_result in join_results {
|
|
|
|
join_result??;
|
2021-04-28 14:17:04 -04:00
|
|
|
}
|
2021-07-22 07:34:29 -04:00
|
|
|
|
2021-09-08 11:18:07 -04:00
|
|
|
result??;
|
2021-07-22 07:34:29 -04:00
|
|
|
|
|
|
|
Ok(())
|
2020-02-11 06:01:56 -05:00
|
|
|
}
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
/// Collects specifiers marking them with the appropriate test mode while maintaining the natural
|
|
|
|
/// input order.
|
|
|
|
///
|
|
|
|
/// - Specifiers matching the `is_supported_test_ext` predicate are marked as
|
|
|
|
/// `TestMode::Documentation`.
|
|
|
|
/// - Specifiers matching the `is_supported_test_path` are marked as `TestMode::Executable`.
|
|
|
|
/// - Specifiers matching both predicates are marked as `TestMode::Both`
|
|
|
|
fn collect_specifiers_with_test_mode(
|
|
|
|
include: Vec<String>,
|
|
|
|
ignore: Vec<PathBuf>,
|
|
|
|
include_inline: bool,
|
|
|
|
) -> Result<Vec<(ModuleSpecifier, TestMode)>, AnyError> {
|
|
|
|
let module_specifiers =
|
|
|
|
collect_specifiers(include.clone(), &ignore, is_supported_test_path)?;
|
|
|
|
|
|
|
|
if include_inline {
|
|
|
|
return collect_specifiers(include, &ignore, is_supported_test_ext).map(
|
|
|
|
|specifiers| {
|
|
|
|
specifiers
|
|
|
|
.into_iter()
|
|
|
|
.map(|specifier| {
|
|
|
|
let mode = if module_specifiers.contains(&specifier) {
|
|
|
|
TestMode::Both
|
|
|
|
} else {
|
|
|
|
TestMode::Documentation
|
|
|
|
};
|
|
|
|
|
|
|
|
(specifier, mode)
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let specifiers_with_mode = module_specifiers
|
|
|
|
.into_iter()
|
|
|
|
.map(|specifier| (specifier, TestMode::Executable))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(specifiers_with_mode)
|
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
/// Collects module and document specifiers with test modes via
|
|
|
|
/// `collect_specifiers_with_test_mode` which are then pre-fetched and adjusted
|
|
|
|
/// based on the media type.
|
2021-08-26 15:21:58 -04:00
|
|
|
///
|
2021-10-10 17:26:22 -04:00
|
|
|
/// Specifiers that do not have a known media type that can be executed as a
|
|
|
|
/// module are marked as `TestMode::Documentation`. Type definition files
|
|
|
|
/// cannot be run, and therefore need to be marked as `TestMode::Documentation`
|
|
|
|
/// as well.
|
2021-08-26 15:21:58 -04:00
|
|
|
async fn fetch_specifiers_with_test_mode(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps: ProcState,
|
2021-08-26 15:21:58 -04:00
|
|
|
include: Vec<String>,
|
|
|
|
ignore: Vec<PathBuf>,
|
|
|
|
include_inline: bool,
|
|
|
|
) -> Result<Vec<(ModuleSpecifier, TestMode)>, AnyError> {
|
|
|
|
let mut specifiers_with_mode =
|
|
|
|
collect_specifiers_with_test_mode(include, ignore, include_inline)?;
|
|
|
|
for (specifier, mode) in &mut specifiers_with_mode {
|
2021-09-24 11:10:42 -04:00
|
|
|
let file = ps
|
2021-08-26 15:21:58 -04:00
|
|
|
.file_fetcher
|
|
|
|
.fetch(specifier, &mut Permissions::allow_all())
|
|
|
|
.await?;
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
if file.media_type == MediaType::Unknown
|
|
|
|
|| file.media_type == MediaType::Dts
|
|
|
|
{
|
2021-08-26 15:21:58 -04:00
|
|
|
*mode = TestMode::Documentation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(specifiers_with_mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_tests(
|
|
|
|
flags: Flags,
|
2021-12-20 16:29:02 -05:00
|
|
|
test_flags: TestFlags,
|
2021-08-26 15:21:58 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2021-09-24 11:10:42 -04:00
|
|
|
let ps = ProcState::build(flags.clone()).await?;
|
2021-08-26 15:21:58 -04:00
|
|
|
let permissions = Permissions::from_options(&flags.clone().into());
|
|
|
|
let specifiers_with_mode = fetch_specifiers_with_test_mode(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-12-20 16:29:02 -05:00
|
|
|
test_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
|
|
|
test_flags.ignore.clone(),
|
|
|
|
test_flags.doc,
|
2021-08-26 15:21:58 -04:00
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2021-12-20 16:29:02 -05:00
|
|
|
if !test_flags.allow_none && specifiers_with_mode.is_empty() {
|
2021-08-26 15:21:58 -04:00
|
|
|
return Err(generic_error("No test modules found"));
|
|
|
|
}
|
|
|
|
|
|
|
|
let lib = if flags.unstable {
|
2021-10-10 17:26:22 -04:00
|
|
|
emit::TypeLib::UnstableDenoWindow
|
2021-08-26 15:21:58 -04:00
|
|
|
} else {
|
2021-10-10 17:26:22 -04:00
|
|
|
emit::TypeLib::DenoWindow
|
2021-08-26 15:21:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
check_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-08-26 15:21:58 -04:00
|
|
|
permissions.clone(),
|
|
|
|
specifiers_with_mode.clone(),
|
|
|
|
lib,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2021-12-20 16:29:02 -05:00
|
|
|
if test_flags.no_run {
|
2021-08-26 15:21:58 -04:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
test_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps,
|
2021-08-26 15:21:58 -04:00
|
|
|
permissions,
|
|
|
|
specifiers_with_mode,
|
2021-12-30 11:18:30 -05:00
|
|
|
TestSpecifierOptions {
|
|
|
|
compat_mode: flags.compat,
|
|
|
|
concurrent_jobs: test_flags.concurrent_jobs,
|
|
|
|
fail_fast: test_flags.fail_fast,
|
|
|
|
filter: test_flags.filter,
|
|
|
|
shuffle: test_flags.shuffle,
|
|
|
|
},
|
2021-08-26 15:21:58 -04:00
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_tests_with_watch(
|
|
|
|
flags: Flags,
|
2021-12-20 16:29:02 -05:00
|
|
|
test_flags: TestFlags,
|
2021-08-26 15:21:58 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2021-09-24 11:10:42 -04:00
|
|
|
let ps = ProcState::build(flags.clone()).await?;
|
2021-08-26 15:21:58 -04:00
|
|
|
let permissions = Permissions::from_options(&flags.clone().into());
|
|
|
|
|
|
|
|
let lib = if flags.unstable {
|
2021-10-10 17:26:22 -04:00
|
|
|
emit::TypeLib::UnstableDenoWindow
|
2021-08-26 15:21:58 -04:00
|
|
|
} else {
|
2021-10-10 17:26:22 -04:00
|
|
|
emit::TypeLib::DenoWindow
|
2021-08-26 15:21:58 -04:00
|
|
|
};
|
|
|
|
|
2021-12-20 16:29:02 -05:00
|
|
|
let include = test_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
|
|
|
let ignore = test_flags.ignore.clone();
|
2021-08-26 15:21:58 -04:00
|
|
|
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
2021-12-16 05:45:41 -05:00
|
|
|
let no_check = ps.flags.check == CheckFlag::None;
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
let resolver = |changed: Option<Vec<PathBuf>>| {
|
2021-10-10 17:26:22 -04:00
|
|
|
let mut cache = cache::FetchCacher::new(
|
|
|
|
ps.dir.gen_cache.clone(),
|
|
|
|
ps.file_fetcher.clone(),
|
|
|
|
Permissions::allow_all(),
|
|
|
|
Permissions::allow_all(),
|
|
|
|
);
|
|
|
|
|
2021-08-26 15:21:58 -04:00
|
|
|
let paths_to_watch = paths_to_watch.clone();
|
|
|
|
let paths_to_watch_clone = paths_to_watch.clone();
|
|
|
|
|
2021-11-08 20:26:39 -05:00
|
|
|
let maybe_import_map_resolver =
|
|
|
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
|
|
|
let maybe_jsx_resolver = ps
|
|
|
|
.maybe_config_file
|
|
|
|
.as_ref()
|
|
|
|
.map(|cf| {
|
|
|
|
cf.to_maybe_jsx_import_source_module()
|
|
|
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()))
|
|
|
|
})
|
|
|
|
.flatten();
|
2021-10-10 17:26:22 -04:00
|
|
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
|
|
|
let maybe_imports = ps
|
|
|
|
.maybe_config_file
|
|
|
|
.as_ref()
|
2021-11-08 20:26:39 -05:00
|
|
|
.map(|cf| cf.to_maybe_imports());
|
2021-08-26 15:21:58 -04:00
|
|
|
let files_changed = changed.is_some();
|
|
|
|
let include = include.clone();
|
|
|
|
let ignore = ignore.clone();
|
2021-12-22 08:25:06 -05:00
|
|
|
let check_js = ps
|
|
|
|
.maybe_config_file
|
|
|
|
.as_ref()
|
|
|
|
.map(|cf| cf.get_check_js())
|
|
|
|
.unwrap_or(false);
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
async move {
|
2021-12-20 16:29:02 -05:00
|
|
|
let test_modules = if test_flags.doc {
|
2021-08-26 15:21:58 -04:00
|
|
|
collect_specifiers(include.clone(), &ignore, is_supported_test_ext)
|
|
|
|
} else {
|
|
|
|
collect_specifiers(include.clone(), &ignore, is_supported_test_path)
|
|
|
|
}?;
|
|
|
|
|
|
|
|
let mut paths_to_watch = paths_to_watch_clone;
|
|
|
|
let mut modules_to_reload = if files_changed {
|
|
|
|
Vec::new()
|
|
|
|
} else {
|
|
|
|
test_modules
|
|
|
|
.iter()
|
|
|
|
.filter_map(|url| deno_core::resolve_url(url.as_str()).ok())
|
|
|
|
.collect()
|
|
|
|
};
|
2021-11-08 20:26:39 -05:00
|
|
|
let maybe_imports = if let Some(result) = maybe_imports {
|
|
|
|
result?
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
|
|
|
maybe_jsx_resolver.as_ref().map(|jr| jr.as_resolver())
|
|
|
|
} else {
|
|
|
|
maybe_import_map_resolver
|
|
|
|
.as_ref()
|
|
|
|
.map(|im| im.as_resolver())
|
|
|
|
};
|
2021-10-10 17:26:22 -04:00
|
|
|
let graph = deno_graph::create_graph(
|
|
|
|
test_modules.clone(),
|
|
|
|
false,
|
|
|
|
maybe_imports,
|
|
|
|
cache.as_mut_loader(),
|
2021-11-08 20:26:39 -05:00
|
|
|
maybe_resolver,
|
2021-10-10 17:26:22 -04:00
|
|
|
maybe_locker,
|
|
|
|
None,
|
2022-01-13 11:58:00 -05:00
|
|
|
None,
|
2021-10-10 17:26:22 -04:00
|
|
|
)
|
|
|
|
.await;
|
2021-12-22 08:25:06 -05:00
|
|
|
graph_valid(&graph, !no_check, check_js)?;
|
2021-08-26 15:21:58 -04:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
// TODO(@kitsonk) - This should be totally derivable from the graph.
|
2021-08-26 15:21:58 -04:00
|
|
|
for specifier in test_modules {
|
|
|
|
fn get_dependencies<'a>(
|
2021-10-10 17:26:22 -04:00
|
|
|
graph: &'a deno_graph::ModuleGraph,
|
|
|
|
maybe_module: Option<&'a deno_graph::Module>,
|
2021-08-26 15:21:58 -04:00
|
|
|
// This needs to be accessible to skip getting dependencies if they're already there,
|
|
|
|
// otherwise this will cause a stack overflow with circular dependencies
|
|
|
|
output: &mut HashSet<&'a ModuleSpecifier>,
|
2021-12-16 05:45:41 -05:00
|
|
|
no_check: bool,
|
2021-10-10 17:26:22 -04:00
|
|
|
) {
|
2021-12-14 15:39:20 -05:00
|
|
|
if let Some(Module::Es(module)) = maybe_module {
|
2021-10-10 17:26:22 -04:00
|
|
|
for dep in module.dependencies.values() {
|
|
|
|
if let Some(specifier) = &dep.get_code() {
|
|
|
|
if !output.contains(specifier) {
|
|
|
|
output.insert(specifier);
|
2021-12-16 05:45:41 -05:00
|
|
|
get_dependencies(
|
|
|
|
graph,
|
|
|
|
graph.get(specifier),
|
|
|
|
output,
|
|
|
|
no_check,
|
|
|
|
);
|
2021-10-10 17:26:22 -04:00
|
|
|
}
|
2021-08-26 15:21:58 -04:00
|
|
|
}
|
2021-12-16 05:45:41 -05:00
|
|
|
if !no_check {
|
|
|
|
if let Some(specifier) = &dep.get_type() {
|
|
|
|
if !output.contains(specifier) {
|
|
|
|
output.insert(specifier);
|
|
|
|
get_dependencies(
|
|
|
|
graph,
|
|
|
|
graph.get(specifier),
|
|
|
|
output,
|
|
|
|
no_check,
|
|
|
|
);
|
|
|
|
}
|
2021-10-10 17:26:22 -04:00
|
|
|
}
|
2021-08-26 15:21:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test module and all it's dependencies
|
|
|
|
let mut modules = HashSet::new();
|
|
|
|
modules.insert(&specifier);
|
2021-12-16 05:45:41 -05:00
|
|
|
get_dependencies(&graph, graph.get(&specifier), &mut modules, no_check);
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
paths_to_watch.extend(
|
|
|
|
modules
|
|
|
|
.iter()
|
|
|
|
.filter_map(|specifier| specifier.to_file_path().ok()),
|
|
|
|
);
|
|
|
|
|
|
|
|
if let Some(changed) = &changed {
|
|
|
|
for path in changed.iter().filter_map(|path| {
|
|
|
|
deno_core::resolve_url_or_path(&path.to_string_lossy()).ok()
|
|
|
|
}) {
|
|
|
|
if modules.contains(&&path) {
|
|
|
|
modules_to_reload.push(specifier);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok((paths_to_watch, modules_to_reload))
|
|
|
|
}
|
|
|
|
.map(move |result| {
|
|
|
|
if files_changed
|
|
|
|
&& matches!(result, Ok((_, ref modules)) if modules.is_empty())
|
|
|
|
{
|
|
|
|
ResolutionResult::Ignore
|
|
|
|
} else {
|
|
|
|
match result {
|
|
|
|
Ok((paths_to_watch, modules_to_reload)) => {
|
|
|
|
ResolutionResult::Restart {
|
|
|
|
paths_to_watch,
|
|
|
|
result: Ok(modules_to_reload),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => ResolutionResult::Restart {
|
|
|
|
paths_to_watch,
|
|
|
|
result: Err(e),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
|
2021-12-20 16:29:02 -05:00
|
|
|
let filter = test_flags.filter.clone();
|
2021-08-26 15:21:58 -04:00
|
|
|
let include = include.clone();
|
|
|
|
let ignore = ignore.clone();
|
|
|
|
let lib = lib.clone();
|
|
|
|
let permissions = permissions.clone();
|
2021-09-24 11:10:42 -04:00
|
|
|
let ps = ps.clone();
|
2021-08-26 15:21:58 -04:00
|
|
|
|
|
|
|
async move {
|
|
|
|
let specifiers_with_mode = fetch_specifiers_with_test_mode(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-08-26 15:21:58 -04:00
|
|
|
include.clone(),
|
|
|
|
ignore.clone(),
|
2021-12-20 16:29:02 -05:00
|
|
|
test_flags.doc,
|
2021-08-26 15:21:58 -04:00
|
|
|
)
|
|
|
|
.await?
|
|
|
|
.iter()
|
|
|
|
.filter(|(specifier, _)| modules_to_reload.contains(specifier))
|
|
|
|
.cloned()
|
|
|
|
.collect::<Vec<(ModuleSpecifier, TestMode)>>();
|
|
|
|
|
|
|
|
check_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-08-26 15:21:58 -04:00
|
|
|
permissions.clone(),
|
|
|
|
specifiers_with_mode.clone(),
|
|
|
|
lib,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2021-12-20 16:29:02 -05:00
|
|
|
if test_flags.no_run {
|
2021-08-26 15:21:58 -04:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
test_specifiers(
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.clone(),
|
2021-08-26 15:21:58 -04:00
|
|
|
permissions.clone(),
|
|
|
|
specifiers_with_mode,
|
2021-12-30 11:18:30 -05:00
|
|
|
TestSpecifierOptions {
|
|
|
|
compat_mode: flags.compat,
|
|
|
|
concurrent_jobs: test_flags.concurrent_jobs,
|
|
|
|
fail_fast: test_flags.fail_fast,
|
|
|
|
filter: filter.clone(),
|
|
|
|
shuffle: test_flags.shuffle,
|
|
|
|
},
|
2021-08-26 15:21:58 -04:00
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
file_watcher::watch_func(resolver, operation, "Test").await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-10-30 16:49:46 -04:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_human_elapsed() {
|
|
|
|
assert_eq!(human_elapsed(1), "(1ms)");
|
|
|
|
assert_eq!(human_elapsed(256), "(256ms)");
|
|
|
|
assert_eq!(human_elapsed(1000), "(1s)");
|
|
|
|
assert_eq!(human_elapsed(1001), "(1s)");
|
|
|
|
assert_eq!(human_elapsed(1020), "(1s)");
|
|
|
|
assert_eq!(human_elapsed(70 * 1000), "(1m10s)");
|
|
|
|
assert_eq!(human_elapsed(86 * 1000 + 100), "(1m26s)");
|
|
|
|
}
|
|
|
|
}
|