# test.build/core/loaders/source.loader.test.ts

> 17 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-loaders-source-loader-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/loaders/source.loader.test.ts.txt

Listed in [test.build/core/loaders](https://banes-lab.com/api/source/testing/test.build/core/loaders.md), after [test.build/core/loaders/site.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/site.loader.test.ts.md) and before [test.build/core/loaders/structure.loader.test.ts](https://banes-lab.com/source/testing/test.build/core/loaders/structure.loader.test.ts.md).

## Contained in

- [test.build/core/loaders](https://banes-lab.com/anatomy/testing/folder-testing-test-build-core-loaders.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
import { sourceSizeOf, sourceTextOf } from "@banes-lab/build-scripts/core/loaders/source.loader.ts";
import { absolutePath } from "@ssot/paths";
import { join } from "node:path";

describe("sourceTextOf and sourceSizeOf", () => {
    it("reads a source asset and its size by its name, and answers null and 0 for one the anatomy did not write", () => {
        const folder = absolutePath("app.sources");
        const [first] = existsSync(folder) ? readdirSync(folder) : [];
        if (first !== undefined) {
            expect(sourceTextOf(first)).toBe(readFileSync(join(folder, first), "utf8"));
            expect(sourceSizeOf(first)).toBe(statSync(join(folder, first)).size);
        }
        expect(sourceTextOf("source.none.generated.txt")).toBeNull();
        expect(sourceSizeOf("source.none.generated.txt")).toBe(0);
    });
});
```
