chore: activer ESLint sur le backend
Installe eslint, ajoute le script lint, modernise le parser (retrait de babel-eslint obsolète) et applique l'autofix (points-virgules manquants sur l'ensemble du code, conformément à la règle "semi" déjà présente dans .eslintrc mais jamais appliquée faute d'ESLint installé et d'un script pour l'exécuter).
This commit is contained in:
@@ -1,62 +1,62 @@
|
||||
import {describe, it, expect, afterEach} from 'vitest'
|
||||
import fs from 'fs'
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import {backupDatabase} from '../backup-database.js'
|
||||
import {describe, it, expect, afterEach} from 'vitest';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import {backupDatabase} from '../backup-database.js';
|
||||
|
||||
const tmpDirs = []
|
||||
const tmpDirs = [];
|
||||
|
||||
function makeTmpDir() {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'backup-database-test-'))
|
||||
tmpDirs.push(dir)
|
||||
return dir
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'backup-database-test-'));
|
||||
tmpDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
describe('backupDatabase', () => {
|
||||
afterEach(() => {
|
||||
for (const dir of tmpDirs.splice(0)) {
|
||||
fs.rmSync(dir, {recursive: true, force: true})
|
||||
fs.rmSync(dir, {recursive: true, force: true});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it("ne fait rien quand le fichier de base n'existe pas", () => {
|
||||
const root = makeTmpDir()
|
||||
it('ne fait rien quand le fichier de base n\'existe pas', () => {
|
||||
const root = makeTmpDir();
|
||||
const result = backupDatabase({
|
||||
dbPath: path.join(root, 'inexistant.db'),
|
||||
backupsDir: path.join(root, 'backups')
|
||||
})
|
||||
});
|
||||
|
||||
expect(result).toBeNull()
|
||||
expect(fs.existsSync(path.join(root, 'backups'))).toBe(false)
|
||||
})
|
||||
expect(result).toBeNull();
|
||||
expect(fs.existsSync(path.join(root, 'backups'))).toBe(false);
|
||||
});
|
||||
|
||||
it('copie le fichier de base dans le dossier de sauvegardes', () => {
|
||||
const root = makeTmpDir()
|
||||
const dbPath = path.join(root, 'data.db')
|
||||
fs.writeFileSync(dbPath, 'contenu-de-la-base')
|
||||
const backupsDir = path.join(root, 'backups')
|
||||
const root = makeTmpDir();
|
||||
const dbPath = path.join(root, 'data.db');
|
||||
fs.writeFileSync(dbPath, 'contenu-de-la-base');
|
||||
const backupsDir = path.join(root, 'backups');
|
||||
|
||||
const result = backupDatabase({dbPath, backupsDir})
|
||||
const result = backupDatabase({dbPath, backupsDir});
|
||||
|
||||
expect(result).not.toBeNull()
|
||||
expect(fs.existsSync(result)).toBe(true)
|
||||
expect(fs.readFileSync(result, 'utf8')).toBe('contenu-de-la-base')
|
||||
})
|
||||
expect(result).not.toBeNull();
|
||||
expect(fs.existsSync(result)).toBe(true);
|
||||
expect(fs.readFileSync(result, 'utf8')).toBe('contenu-de-la-base');
|
||||
});
|
||||
|
||||
it('ne conserve que les 8 sauvegardes les plus récentes', () => {
|
||||
const root = makeTmpDir()
|
||||
const dbPath = path.join(root, 'data.db')
|
||||
fs.writeFileSync(dbPath, 'contenu')
|
||||
const backupsDir = path.join(root, 'backups')
|
||||
fs.mkdirSync(backupsDir, {recursive: true})
|
||||
const root = makeTmpDir();
|
||||
const dbPath = path.join(root, 'data.db');
|
||||
fs.writeFileSync(dbPath, 'contenu');
|
||||
const backupsDir = path.join(root, 'backups');
|
||||
fs.mkdirSync(backupsDir, {recursive: true});
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
fs.writeFileSync(path.join(backupsDir, `data-2020-01-0${i}.db`), 'ancien')
|
||||
fs.writeFileSync(path.join(backupsDir, `data-2020-01-0${i}.db`), 'ancien');
|
||||
}
|
||||
|
||||
backupDatabase({dbPath, backupsDir})
|
||||
backupDatabase({dbPath, backupsDir});
|
||||
|
||||
const remaining = fs.readdirSync(backupsDir).filter(name => name.startsWith('data-'))
|
||||
expect(remaining).toHaveLength(8)
|
||||
})
|
||||
})
|
||||
const remaining = fs.readdirSync(backupsDir).filter(name => name.startsWith('data-'));
|
||||
expect(remaining).toHaveLength(8);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user