Skip to content

Instantly share code, notes, and snippets.

@KoenBrouwer
Last active October 21, 2023 14:37
Show Gist options
  • Save KoenBrouwer/e1df9ff68d0a3fc2d98f34a1d23f41a6 to your computer and use it in GitHub Desktop.
Save KoenBrouwer/e1df9ff68d0a3fc2d98f34a1d23f41a6 to your computer and use it in GitHub Desktop.
Simple NodeJS script that I used to create a list of all possible permutations of call chains for Vitest.
// This script creates a list of all possible permutations of call chains based on the Vitest Test API Reference (https://vitest.dev/api/).
// I used this to improve a package called veritem/eslint-plugin-vitest.
// For further context see: https://github.com/veritem/eslint-plugin-vitest/issues/275.
const fs = require("fs");
const percom = require("percom");
const data = [
{
names: ["beforeEach", "beforeAll", "afterEach", "afterAll"],
methods: [],
},
{
names: ["it", "test"],
methods: ["extend", "skip", "skipIf", "runIf", "only", "concurrent", "todo", "fails", "each"],
},
{
names: ["bench"],
methods: ["skip", "only", "todo"],
},
{
names: ["describe"],
methods: ["skip", "skipIf", "only", "concurrent", "sequential", "shuffle", "todo", "each"],
},
];
const DEPTH = 3;
const allPermutations = [];
data.forEach((q) => {
q.names.map((name) => {
allPermutations.push(name);
const maxDepth = Math.min(DEPTH, q.methods.length);
for (let i = 0; i < maxDepth; i++) {
const perms = percom.com(q.methods, i + 1);
const allPerms = perms.map((p) => [name, ...p].join("."));
allPermutations.push(...allPerms);
}
});
});
console.log(allPermutations);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment