/
githubmirror
/
lerna
Обзор
Документация
Войти
/
githubmirror
/
lerna
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
libs/core/src/lib/temp-write.spec.ts
39 строк
1 KB
James Henry
chore: initial codebase refactor (#3517)
31 янв 2023, 15:20
Не верифицирован
31 янв 2023, 15:20
fc094da
Код
Авторство
О чём код?
import fs from "fs"; import path from "path"; import stream from "stream"; import tempWrite from "./temp-write"; describe("@lerna/temp-write", () => { it("tempWrite(string)", async () => { const filePath = await tempWrite("unicorn", "test.png"); expect(fs.readFileSync(filePath, "utf8")).toEqual("unicorn"); expect(path.basename(filePath)).toEqual("test.png"); }); it("tempWrite(buffer)", async () => { const filePath = await tempWrite(Buffer.from("unicorn"), "test.png"); expect(fs.readFileSync(filePath, "utf8")).toEqual("unicorn"); }); it("tempWrite(buffer, path)", async () => { const filePath = await tempWrite(Buffer.from("unicorn"), "foo/bar/test.png"); expect(fs.readFileSync(filePath, "utf8")).toEqual("unicorn"); const regexp = process.platform === "win32" ? /foo\\bar\\test\.png$/ : /foo\/bar\/test\.png$/; expect(filePath).toMatch(regexp); }); it("tempWrite(stream)", async () => { const readable = new stream.Readable({ read() {}, // Noop }); readable.push("unicorn"); readable.push(null); const filePath = await tempWrite(readable, "test.png"); expect(fs.readFileSync(filePath, "utf8")).toEqual("unicorn"); }); it("tempWrite.sync()", () => { expect(fs.readFileSync(tempWrite.sync("unicorn"), "utf8")).toEqual("unicorn"); }); });