var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import * as fs from "fs";
import * as path from "path";
import * as url from "url";
import { expect } from "chai";
import { TEST_FIXTURE_SRC_DIRECTORY } from "../utils";
import { resolveAllPaperclipFiles } from "../../utils";
import { resolveImportFile, resolveImportUri } from "paperclip-utils";
describe(__filename + "#", () => {
    it("returns nested module when resolving", () => __awaiter(void 0, void 0, void 0, function* () {
        const results = resolveAllPaperclipFiles(fs)(url.pathToFileURL(path.join(TEST_FIXTURE_SRC_DIRECTORY, "nested-mod-import.pc")).href, true);
        expect(results.map(path => {
            return path.replace(/^\.\//, "");
        })).to.eql([
            "bad-css-url.pc",
            "bad-import.pc",
            "good-import.pc",
            "hello-world.pc",
            "mod-a-import.pc",
            "mod-import.pc",
            "module.pc",
            "@nested/in/a/folder/src/component.pc",
            "@nested/in/a/folder/src/imp-mod-a.pc",
            "@nested/in/a/folder/src/module.pc",
            "@nested/in/a/folder/src/test.pc",
            "module-a/src/component.pc",
            "module-a/src/module.pc",
            "module-a/src/test.pc"
        ]);
    }));
    it("can resolve local file with the output directory", () => __awaiter(void 0, void 0, void 0, function* () {
        const outputPath = resolveImportFile(fs)(path.join(TEST_FIXTURE_SRC_DIRECTORY, "nested-mod-import.pc"), "@nested/in/a/folder/src/component.pc", true);
        expect(outputPath).to.contain("test-fixtures/modules/@nested/in/a/folder/lib/component.pc");
    }));
    it("traverses parent to resolve module", () => __awaiter(void 0, void 0, void 0, function* () {
        const outputPath = resolveImportUri(fs)(path.join(TEST_FIXTURE_SRC_DIRECTORY, "../modules/@nested/in/a/folder/src/imp-mod-a.pc"), "module-a/src/module.pc");
        expect(outputPath).to.contain("modules/module-a/src/module.pc");
    }));
});
