1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
This commit is contained in:
Marvin Hagemeister 2024-10-10 16:09:48 +02:00
parent 777c935603
commit b55d7f91cb
4 changed files with 58 additions and 26 deletions

View file

@ -333,6 +333,7 @@ function testInner(
testDesc.name = escapeName(testDesc.name);
op_register_test(
ROOT_TEST_GROUP.id,
testDesc.fn,
testDesc.name,
testDesc.ignore,
@ -539,6 +540,7 @@ globalThis.Deno.test = test;
/**
* @typedef {{
* id: number,
* parentId: number,
* name: string,
* fn: () => any,
* only: boolean,
@ -549,6 +551,7 @@ globalThis.Deno.test = test;
*
* @typedef {{
* id: number,
* parentId: number,
* name: string,
* ignore: boolean,
* only: boolean,
@ -563,6 +566,7 @@ globalThis.Deno.test = test;
/** @type {TestGroup} */
const ROOT_TEST_GROUP = {
id: 0,
parentId: 0,
name: "__DENO_TEST_ROOT__",
ignore: false,
only: false,
@ -577,7 +581,7 @@ if (typeof op_register_test === "function") {
op_test_group_register(
registerTestGroupIdRetBufU8,
ROOT_TEST_GROUP.name,
true,
ROOT_TEST_GROUP.parentId,
);
ROOT_TEST_GROUP.id = registerTestGroupIdRetBuf[0];
}
@ -621,18 +625,22 @@ function itInner(name, fn, ignore, only) {
}
};
const parent = getGroupParent();
/** @type {BddTest} */
const testDef = {
id: 0,
parentId: parent.id,
name,
fn: testFn,
ignore,
only,
};
getGroupParent().children.push(testDef);
parent.children.push(testDef);
BDD_CONTEXT.total++;
op_register_test(
parent.id,
testFn,
escapeName(name),
ignore,
@ -696,13 +704,14 @@ function describeInner(name, fn, ignore, only) {
return;
}
op_test_group_register(registerTestGroupIdRetBufU8, name, false);
const parent = getGroupParent();
op_test_group_register(registerTestGroupIdRetBufU8, name, parent.id);
const id = registerTestGroupIdRetBuf[0];
const parent = getGroupParent();
/** @type {TestGroup} */
const group = {
id,
parentId: parent.id,
name,
ignore,
only,
@ -829,7 +838,7 @@ async function runTests(seed, ...rest) {
ROOT_TEST_GROUP.only = ROOT_TEST_GROUP.children.some((child) => child.only);
}
console.log("RUN TESTS", seed, rest, ROOT_TEST_GROUP);
// console.log("RUN TESTS", BDD_CONTEXT.hasOnly, seed, rest, ROOT_TEST_GROUP);
try {
await runGroup(seed, ROOT_TEST_GROUP);
} finally {
@ -844,7 +853,11 @@ async function runTests(seed, ...rest) {
async function runGroup(seed, group) {
op_test_group_event_start(group.id);
if (seed > 0 && group.children.length > 1) {
if (BDD_CONTEXT.hasOnly && !group.only) {
group.ignore = true;
}
if (seed > 0 && !group.ignore && group.children.length > 1) {
shuffle(group.children, seed);
}
@ -854,26 +867,20 @@ async function runGroup(seed, group) {
// - groups last
group.children.sort(sortTestItems);
// Short circuit if the whole group is ignored
if (group.ignore) {
// FIXME
return;
}
try {
if (group.beforeAll !== null) {
if (!group.ignore && group.beforeAll !== null) {
await group.beforeAll();
}
for (let i = 0; i < group.children.length; i++) {
const child = group.children[i];
if (group.beforeEach !== null) {
if (!group.ignore && group.beforeEach !== null) {
await group.beforeEach();
}
if (isTestGroup(child)) {
await runGroup(seed, child);
} else if (child.ignore) {
} else if (child.ignore || BDD_CONTEXT.hasOnly && !child.only) {
op_test_event_result_ignored(child.id);
} else {
op_test_event_start(child.id);
@ -889,12 +896,12 @@ async function runGroup(seed, group) {
}
}
if (group.afterEach !== null) {
if (!group.ignore && group.afterEach !== null) {
await group.afterEach();
}
}
if (group.afterAll !== null) {
if (!group.ignore && group.afterAll !== null) {
await group.afterAll();
}
} finally {
@ -910,12 +917,12 @@ function sortTestItems(a, b) {
const isAGroup = isTestGroup(a);
const isBGroup = isTestGroup(b);
if (isAGroup && isBGroup) return 0;
if (isAGroup && !isBGroup) return -1;
if (!isAGroup && isBGroup) return 1;
if (isAGroup && !isBGroup) return 1;
if (!isAGroup && isBGroup) return -1;
if (a.ignore && b.ignore) return 0;
if (a.ignore && !b.ignore) return -1;
if (!a.ignore && b.ignore) return 1;
if (a.ignore && !b.ignore) return 1;
if (!a.ignore && b.ignore) return -1;
return 0;
}

View file

@ -103,6 +103,7 @@ static NEXT_GROUP_ID: AtomicUsize = AtomicUsize::new(0);
#[op2]
fn op_register_test(
state: &mut OpState,
#[smi] parent_id: usize,
#[global] function: v8::Global<v8::Function>,
#[string] name: String,
ignore: bool,
@ -124,6 +125,7 @@ fn op_register_test(
let origin = state.borrow::<ModuleSpecifier>().to_string();
let description = TestDescription {
id,
parent_id,
name,
ignore,
only,
@ -147,11 +149,15 @@ fn op_test_group_register(
state: &mut OpState,
#[buffer] ret_buf: &mut [u8],
#[string] name: String,
is_root: bool,
#[smi] parent_id: usize,
) -> Result<(), AnyError> {
let id = NEXT_GROUP_ID.fetch_add(1, Ordering::SeqCst);
let sender = state.borrow_mut::<TestEventSender>();
let description = TestGroupDescription { id, name, is_root };
let description = TestGroupDescription {
id,
parent_id,
name,
};
sender.send(TestEvent::GroupRegister(description)).ok();
ret_buf.copy_from_slice(&(id as u32).to_le_bytes());
Ok(())

View file

@ -292,6 +292,7 @@ impl<'a> IntoIterator for &'a TestDescriptions {
#[serde(rename_all = "camelCase")]
pub struct TestDescription {
pub id: usize,
pub parent_id: usize,
pub name: String,
pub ignore: bool,
pub only: bool,
@ -306,7 +307,7 @@ pub struct TestDescription {
pub struct TestGroupDescription {
pub id: usize,
pub name: String,
pub is_root: bool,
pub parent_id: usize,
}
/// May represent a failure of a test or test step.

View file

@ -6,6 +6,7 @@ use super::*;
pub struct PrettyTestReporter {
parallel: bool,
groups: IndexMap<usize, TestGroupDescription>,
echo_output: bool,
in_new_line: bool,
phase: &'static str,
@ -39,6 +40,7 @@ impl PrettyTestReporter {
phase: "",
filter,
repl,
groups: IndexMap::new(),
scope_test_id: None,
cwd,
did_have_user_output: false,
@ -70,7 +72,21 @@ impl PrettyTestReporter {
)
.unwrap();
}
write!(&mut self.writer, "{} ...", description.name).unwrap();
let mut group_names = "".to_string();
let mut parent_id = description.parent_id;
while parent_id > 0 {
if let Some((_, parent)) = self.groups.get_index(parent_id) {
group_names = format!("{} :: {}", parent.name, group_names);
parent_id = parent.parent_id;
} else {
break;
}
}
write!(&mut self.writer, "{}{} ...", group_names, description.name)
.unwrap();
self.in_new_line = false;
// flush for faster feedback when line buffered
std::io::stdout().flush().unwrap();
@ -167,7 +183,9 @@ impl PrettyTestReporter {
}
impl TestReporter for PrettyTestReporter {
fn report_register_group(&mut self, _description: &TestGroupDescription) {}
fn report_register_group(&mut self, description: &TestGroupDescription) {
self.groups.insert(description.id, description.clone());
}
fn report_register(&mut self, _description: &TestDescription) {}
fn report_plan(&mut self, plan: &TestPlan) {