import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { after, before, describe, it } from "node:test";
import { expect } from "chai";
import { TEST_IN_FOLDER } from "../common/constants.js";
import { findTestFiles } from "./test-files.js";
function createTestFile(filePath) {
    const dir = path.dirname(filePath);
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
    }
    fs.writeFileSync(filePath, "// test file");
}
describe("findTestFiles", () => {
    const testDir = path.join(os.tmpdir(), "findTestFilesTest");
    const testSubDir = path.join(testDir, TEST_IN_FOLDER);
    const testFilePath = path.join(testSubDir, "example.test.ts");
    before(() => {
        createTestFile(testFilePath);
    });
    after(() => {
        fs.rmSync(testDir, { recursive: true, force: true });
    });
    it("should find test files in the specified directory", () => {
        const result = findTestFiles(testDir);
        const normalizedResult = result.map((p) => path.normalize(p));
        const normalizedExpected = path.normalize(testFilePath);
        expect(normalizedResult).to.include(normalizedExpected);
    });
    it("should return an empty array if no test files are found", () => {
        const emptyDir = path.join(os.tmpdir(), "emptyTestDir");
        fs.mkdirSync(emptyDir, { recursive: true });
        const result = findTestFiles(emptyDir);
        expect(result).to.be.an("array").that.is.empty;
        fs.rmdirSync(emptyDir);
    });
    it("should handle Windows paths correctly", function (t) {
        if (os.platform() !== "win32") {
            t.skip("Skipping Windows-specific test on non-Windows platform");
            return;
        }
        const windowsPath = testDir.replace(/\//g, "\\");
        const result = findTestFiles(windowsPath);
        const normalizedResult = result.map((p) => path.normalize(p));
        const normalizedExpected = path.normalize(testFilePath);
        expect(normalizedResult).to.include(normalizedExpected);
    });
});
//# sourceMappingURL=test-files.test.js.map