<commit_before>import uSite from "./usite";
import { InMemoryFileSystem } from "./fileSystem/inMemory/inMemoryFileSystem";

describe("usite test suite", () => {
    it("should read global settings", () => {
        const fs = new InMemoryFileSystem();
        const settings = {
            title: "Blog",
            url: "http://blog.blog/"
        };

        fs.writeFile("./website.json", JSON.stringify(settings));

        const blog = new uSite();
        blog.context.cwd = "./";
        blog.context.fs = fs;
        blog.context.global = blog.loadOptions("website.json");

        expect(blog.context.fs).toBe(fs);
        expect(blog.context.global).toEqual(settings);
    });

    it("should support loading and transforming content", () => {
        const fs = new InMemoryFileSystem();
        fs.mkdirs("content/post/");
        fs.writeFile("content/post/1.md", "meta+++content");
        fs.writeFile("content/post/2.md", "Post2");

        const blog = new TestUsite();
        blog.context.cwd = "./";
        blog.context.fs = fs;
        blog.context.global = {
            title: "TestBlog"
        };
        blog.globResult = [
            "content/post/1.md",
            "content/post/2.md"
        ];

        const posts = blog.loadContent("content/post/*").map((post) => {
            return {};
        });

        expect(posts.count()).toBe(2);

        const mappedPosts = posts.map((post) => {
            const separator = "+++";

            const [meta] = post.rawContent.split(separator, 1);
            const content = post.rawContent.replace(meta + separator, "");

            return {
                meta: {
                    title: meta,
                },
                content: content,
            };
        });

        expect(mappedPosts.count()).toBe(2);
        expect(mappedPosts.get(0).meta.title).toBe("meta");
        expect(mappedPosts.get(0).content).toBe("content");
    });

    it("should emit to file 1 to 1", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "meta+++content1" },
            { path: "content/post/2.md", content: "meta+++content2" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post, index) => {
            const [meta, content] = post.rawContent.split("+++");
            return { meta, content, slug: `post${index}` };
        });

        posts.emit((item) => {
            return `<div>${item.content}</div>`;
        }, "www/post/{slug}");

        expect(blog.context.fs.readFile("www/post/post0/index.html", "utf-8")).toBe("<div>content1</div>");
        expect(blog.context.fs.readFile("www/post/post1/index.html", "utf-8")).toBe("<div>content2</div>");
    });

    it("should support map after map", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "title1+++content1" },
            { path: "content/post/2.md", content: "meta+++content2" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post, index) => {
            const [meta, content] = post.rawContent.split("+++");
            return {
                meta: {
                    title: meta,
                    slug: `post${index}`
                }, content
            };
        });

        const posts2 = posts.map((post) => {
            return {
                slug: post.meta.slug,
                title: post.meta.title,
            };
        });

        expect(posts2.get(0).slug).toBe("post0");
        expect(posts2.get(0).title).toBe("title1");
    });

    it("should support group", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "title1+++content1" },
            { path: "content/post/2.md", content: "title2+++content2" },
            { path: "content/post/3.md", content: "title1+++content3" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post) => {
            const [title, content] = post.rawContent.split("+++");<commit_msg>Added more assertions<commit_after>import uSite from "./usite";
import { InMemoryFileSystem } from "./fileSystem/inMemory/inMemoryFileSystem";

describe("usite test suite", () => {
    it("should read global settings", () => {
        const fs = new InMemoryFileSystem();
        const settings = {
            title: "Blog",
            url: "http://blog.blog/"
        };

        fs.writeFile("./website.json", JSON.stringify(settings));

        const blog = new uSite();
        blog.context.cwd = "./";
        blog.context.fs = fs;
        blog.context.global = blog.loadOptions("website.json");

        expect(blog.context.fs).toBe(fs);
        expect(blog.context.global).toEqual(settings);
    });

    it("should support loading and transforming content", () => {
        const fs = new InMemoryFileSystem();
        fs.mkdirs("content/post/");
        fs.writeFile("content/post/1.md", "meta+++content");
        fs.writeFile("content/post/2.md", "Post2");

        const blog = new TestUsite();
        blog.context.cwd = "./";
        blog.context.fs = fs;
        blog.context.global = {
            title: "TestBlog"
        };
        blog.globResult = [
            "content/post/1.md",
            "content/post/2.md"
        ];

        const posts = blog.loadContent("content/post/*").map((post) => {
            return {};
        });

        expect(posts.count()).toBe(2);

        const mappedPosts = posts.map((post) => {
            const separator = "+++";

            const [meta] = post.rawContent.split(separator, 1);
            const content = post.rawContent.replace(meta + separator, "");

            return {
                meta: {
                    title: meta,
                },
                content: content,
            };
        });

        expect(mappedPosts.count()).toBe(2);
        expect(mappedPosts.get(0).meta.title).toBe("meta");
        expect(mappedPosts.get(0).content).toBe("content");
    });

    it("should emit to file 1 to 1", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "meta+++content1" },
            { path: "content/post/2.md", content: "meta+++content2" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post, index) => {
            const [meta, content] = post.rawContent.split("+++");
            return { meta, content, slug: `post${index}` };
        });

        posts.emit((item) => {
            return `<div>${item.content}</div>`;
        }, "www/post/{slug}");

        expect(blog.context.fs.readFile("www/post/post0/index.html", "utf-8")).toBe("<div>content1</div>");
        expect(blog.context.fs.readFile("www/post/post1/index.html", "utf-8")).toBe("<div>content2</div>");
    });

    it("should support map after map", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "title1+++content1" },
            { path: "content/post/2.md", content: "meta+++content2" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post, index) => {
            const [meta, content] = post.rawContent.split("+++");
            return {
                meta: {
                    title: meta,
                    slug: `post${index}`
                }, content
            };
        });

        const posts2 = posts.map((post) => {
            return {
                slug: post.meta.slug,
                title: post.meta.title,
            };
        });

        expect(posts2.get(0).slug).toBe("post0");
        expect(posts2.get(0).title).toBe("title1");
        expect(posts2.get(0).filePath).toBe("content/post/1.md");
        expect(posts2.get(1).filePath).toBe("content/post/2.md");
    });

    it("should support group", () => {
        const blog = setupBlog([
            { path: "content/post/1.md", content: "title1+++content1" },
            { path: "content/post/2.md", content: "title2+++content2" },
            { path: "content/post/3.md", content: "title1+++content3" },
        ]);

        const posts = blog.loadContent("content/post/*").map((post) => {
            const [title, content] = post.rawContent.split("+++");
{'fraction_non_alphanumeric': 0.18343917928676112, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 1.8926174496644295, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2594712', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2392, 'n_words': 399}