Executing the same test code on different objects

I have several files created using generated code. Each file contains an object with the same interface and almost exactly the same code, called Level_0 to Level_3.

In case you’re wondering, each one is a level of an array-mapped trie, and I need separate code for each level to keep all the function calls monomorphic.

Anyway, since they’re still different bits of code, I’d like to test them separately.

I’m using jest. Although I need separate code for each object due to performance reasons, I would really like to avoid having to duplicate test code too. So what I’ve done is have a folder called level_n with functions like this:

export function test_index(
    iface
) {
    describe("index", () => {
        test("key to local int index", () => {
            expect(iface.intIndex(0)).toBe(0);
        });

        test("key to local bit index", () => {
            expect(iface.bitIndex(0)).toBe(0);
        });
    });
}

And I’ve written several stubs that just contain a call to the test function:

// level_1.spec.ts
import { Level_1 } from "./putrie/level_1";
import { test_index} from "./level_n/index-operation";

test_index(Level_1);

It works, but not very well

This does work, but when I do this, vscode’s jest extension gets confused about the location of the test and when one fails it just points me towards the stub. Besides being inconvenient, it feels like a bad sign.

I’m not too familiar with Jest’s more advanced features, but I do know it has stuff like test.each to generate test cases programmatically.

Does it have something I can use instead of my homebrew solution? Hopefully something that will make vscode point me towards generic test?