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.

Revisions

  1. KoenBrouwer revised this gist Oct 21, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions calculate-permutations.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    // 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");

  2. KoenBrouwer created this gist Oct 21, 2023.
    40 changes: 40 additions & 0 deletions calculate-permutations.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    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);