export function nodeTestPrepPlugin(argv, options) {
    const aliases = Object.keys(options);
    const re = new RegExp(`^(${aliases.map((x) => escapeRegExp(x)).join("|")})$`);
    return {
        name: "alias",
        setup(build) {
            build.onResolve({ filter: re }, (args) => {
                if (/@zuplo\/test/.test(args.path)) {
                    return {
                        path: args.path,
                        namespace: "zuplo-url",
                    };
                }
                else {
                    return {
                        path: options[args.path],
                        namespace: "zuplo-url",
                        external: true,
                    };
                }
            });
            build.onLoad({ filter: /.*/, namespace: "zuplo-url" }, (args) => {
                if (/@zuplo\/test/.test(args.path)) {
                    return { contents: generateTestContents(argv), loader: "ts" };
                }
            });
        },
    };
}
function escapeRegExp(value) {
    return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function generateTestContents(argv) {
    return `
import 'dotenv/config'
import { after, afterEach, describe, it, before, beforeEach } from "node:test"

export class TestHelper {
  static get TEST_URL() {
    const url = "${argv.endpoint}";
    if (url !== "undefined") {
      return url;
    }

    throw new Error("TEST_URL is not set. Pass --endpoint <URL> to \`zuplo test\` on the CLI to set a value.");
  }

  static get environment() {
      return process.env;
  }
}

const afterAll = after;
const beforeAll = before;

describe.ignore = describe.skip;
it.ignore = it.skip;

export {afterAll, afterEach, beforeAll, beforeEach, describe, it};
  `;
}
//# sourceMappingURL=node-test-prep-plugin.js.map