Skip to content

[Test Runner] Dynamic tests yielding "test did not finish before its parent and was cancelled" #54163

@khaosdoctor

Description

@khaosdoctor

Version

20.11.1

Platform

Darwin Watt.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:59 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8122 arm64

Subsystem

Test Runner

What steps will reproduce the bug?

I'm not sure if I can provide a test without any external libraries, theres a large chance this is something related to my code as well, but here's the bit I'm testing

import testerWrap, { AxiosInstance } from 'axiosist';
import assert from 'node:assert';
import { after, before, describe, it } from 'node:test';

import { env } from '../../src/config';
import { initApp } from '../../src/init';
import { router } from '../../src/module/router';
import { testAccount } from './fixtures/test-account';

describe('Module Test', () => {
    let api: AxiosInstance;

    before(async () => {
        const server = await initApp(env);
        api = testerWrap(server);
    });

    describe('Public routes', () => {
        it('should return 401 for calls without authentication', () => {
            for (const layer of router.stack) {
                const path = layer.route?.path.replace(':id', 'someid');
                const methods = Object.keys(layer?.route?.methods ?? {});
                if (path && methods.length > 0) {
                    for (const method of methods) {
                        it(`[${method}] at ${path}`, async () => {
                            const response = await api[method](`/v1/module/${path}`);
                            assert.strictEqual(response.status, 401);
                        });
                    }
                }
            }
        });
    });

How often does it reproduce? Is there a required condition?

This is my current script for running the tests: node --env-file=.env --import=tsx --test *.test it's been consistently failing up until now, but it has worked before without any code changes, so I'm not sure what could be happening

What is the expected behavior? Why is that the expected behavior?

Tests would run dynamically

What do you see instead?

All tests fail with 'test did not finish before its parent and was cancelled'

Additional information

Again, I'm not sure if this is a problem related to my coding (which most likely is) or some promise not being handled in the runner. I've tried removing and modifying several parts but it keeps early exiting, it seems like the promises are being resolved before the assertion is made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions