diff --git a/test/file.spec.js b/test/file.spec.js index 48badfaab..c49a7dbde 100644 --- a/test/file.spec.js +++ b/test/file.spec.js @@ -2,16 +2,12 @@ import { unlink, readFile } from '../lib/file' describe('unlink', () => { it('should throw when second argument is false and file is not found', async () => { - await expect(unlink('example', false)).rejects.toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, unlink 'example'"` - ) + await expect(unlink('example', false)).rejects.toThrowError() }) }) describe('readFile', () => { it('should throw when second argument is false and file is not found', async () => { - await expect(readFile('example', false)).rejects.toThrowErrorMatchingInlineSnapshot( - `"ENOENT: no such file or directory, open 'example'"` - ) + await expect(readFile('example', false)).rejects.toThrowError() }) }) diff --git a/test/runAll.unmocked.spec.js b/test/runAll.unmocked.spec.js index 092e585a1..d5df38ef6 100644 --- a/test/runAll.unmocked.spec.js +++ b/test/runAll.unmocked.spec.js @@ -609,18 +609,40 @@ describe('runAll', () => { await fs.remove(readmeFile) // Remove file from previous commit await appendFile('test.js', testJsFilePretty) await execGit(['add', 'test.js']) - - try { - await runAll({ cwd, config: { '*.{js,md}': 'prettier --list-different' } }) - } catch (error) { - globalConsoleTemp.warn(error) - globalConsoleTemp.error(console.printHistory()) - } - + await runAll({ cwd, config: { '*.{js,md}': 'prettier --list-different' } }) const exists = await fs.exists(readmeFile) expect(exists).toEqual(false) }) + it('should not resurrect removed files in complex case', async () => { + // Add file to index, and remove it from disk + await appendFile('test.js', testJsFilePretty) + await execGit(['add', 'test.js']) + const testFile = path.resolve(cwd, 'test.js') + await fs.remove(testFile) + + // Rename file in index, and remove it from disk + const readmeFile = path.resolve(cwd, 'README.md') + const readme = await readFile(readmeFile) + await fs.remove(readmeFile) + await execGit(['add', readmeFile]) + const newReadmeFile = path.resolve(cwd, 'README_NEW.md') + await appendFile(newReadmeFile, readme) + await execGit(['add', newReadmeFile]) + await fs.remove(newReadmeFile) + + const status = await execGit(['status', '--porcelain']) + expect(status).toMatchInlineSnapshot(` + "RD README.md -> README_NEW.md + AD test.js" + `) + + await runAll({ cwd, config: { '*.{js,md}': 'prettier --list-different' } }) + expect(await fs.exists(testFile)).toEqual(false) + expect(await fs.exists(newReadmeFile)).toEqual(false) + expect(await execGit(['status', '--porcelain'])).toEqual(status) + }) + it('should not resurrect removed files due to git bug when tasks fail', async () => { const readmeFile = path.resolve(cwd, 'README.md') await fs.remove(readmeFile) // Remove file from previous commit