import { promises as fsp } from 'node:fs'; import { expect } from '../../../test-utils'; import { writeFile } from '../write-file'; describe('writes correctly to file', function () { it('should not add an extra line at the end of a pdf file', async function () { const pdfPath = 'test.pdf'; await writeFile(pdfPath, 'testing123'); const pdfContent = await fsp.readFile(pdfPath, { encoding: 'utf-8' }); expect(pdfContent.slice(-1)).to.equal('3'); await fsp.unlink(pdfPath); }); it('should keep a new line at the end of a pdf file if in the content string', async function () { const pdfPath = 'test2.pdf'; await writeFile(pdfPath, 'testing123\n'); const pdfContent = await fsp.readFile(pdfPath, { encoding: 'utf-8' }); expect(pdfContent.slice(-1)).to.equal('\n'); await fsp.unlink(pdfPath); }); it('should add a new line at the end of a js file', async function () { const pdfPath = 'test.js'; await writeFile(pdfPath, 'testing123'); const pdfContent = await fsp.readFile(pdfPath, { encoding: 'utf-8' }); expect(pdfContent.slice(-1)).to.equal('\n'); await fsp.unlink(pdfPath); }); it('should not add a new line at the end of a js file if it ends with a new line', async function () { const pdfPath = 'test2.js'; await writeFile(pdfPath, 'testing123\n'); const pdfContent = await fsp.readFile(pdfPath, { encoding: 'utf-8' }); expect(pdfContent).to.equal('testing123\n'); await fsp.unlink(pdfPath); }); });