Skip to content

Running a test with the node-runner reports an error after everything was sucessfull #933

Description

@JonasDoe

I've created a minimal example: https://github.com/JonasDoe/swc-node-issue

When I run a test in this example, I get this log:

> swc-node@1.0.0 test:swc-node
> node --import @swc-node/register/esm-register --test src/**/*.test.ts

▶ MyClass
  ✔ should not return an error after the assertion (0.5667ms)
✔ MyClass (1.3728ms)
✖ src\myClass.test.ts (507.915ms)
ℹ tests 2
ℹ suites 1
ℹ pass 1
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 514.5506

✖ failing tests:

test at src\myClass.test.ts:1:1
✖ src\myClass.test.ts (507.915ms)
  'test failed'

The tests does nothing more than creating an instance of myClass (without that, it would succeed):

import * as assert from 'assert';
import {describe, it} from 'node:test';
import {MyClass} from "./myClass.js";

describe('MyClass', () => {
    it('should not return an error after the assertion', () => {
        new MyClass()
        assert.ok(true)
    })
})

MyClass looks like this:

export class MyClass {
     prop1?: string;
     prop2?: string;
     prop3?: string;
     prop4?: string;
     prop5?: string;

    constructor() {}

    get p1() {return this.prop1;}
    get p2() {return this.prop2;}
    method1() {}
    method2() {}
    method3() {}
    method4() {}
}

So for some reason my tests is reported as failure besides everything was successful.

The curious thing is: when I remove even a single property or method in MyClass, the test succeds, though.

I'm using @swc-node/register@1.10.10 and Node.js@v22.15.0 under Windows 11 with type: 'module'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions