mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Separate the tests to each part os the public api of the RotatingLogs.
This commit is contained in:
parent
a3d14353fa
commit
4a6bca7924
@ -2,12 +2,16 @@ import { writeFile, readdir, remove } from 'fs-extra';
|
||||
import { createTempDir, msleep } from './testing/test-utils';
|
||||
import RotatingLogs from './RotatingLogs';
|
||||
|
||||
const createTestLogFile = async (dir: string) => {
|
||||
await writeFile(`${dir}/log.txt`, 'some content');
|
||||
};
|
||||
|
||||
describe('RotatingLogs', () => {
|
||||
test('should rename log.txt to log-TIMESTAMP.txt and then delete it after 1ms', async () => {
|
||||
test('should rename log.txt to log-TIMESTAMP.txt', async () => {
|
||||
let dir: string;
|
||||
try {
|
||||
dir = await createTempDir();
|
||||
await writeFile(`${dir}/log.txt`, 'some content');
|
||||
await createTestLogFile(dir);
|
||||
let files: string[] = await readdir(dir);
|
||||
expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy();
|
||||
expect(files.length).toBe(1);
|
||||
@ -17,9 +21,21 @@ describe('RotatingLogs', () => {
|
||||
expect(files.find(file => file.match(/^log.txt$/gi))).toBeFalsy();
|
||||
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeTruthy();
|
||||
expect(files.length).toBe(1);
|
||||
await msleep(2);
|
||||
} finally {
|
||||
await remove(dir);
|
||||
}
|
||||
});
|
||||
|
||||
test('should delete inative log file after 1ms', async () => {
|
||||
let dir: string;
|
||||
try {
|
||||
dir = await createTempDir();
|
||||
await createTestLogFile(dir);
|
||||
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 1);
|
||||
await rotatingLogs.cleanActiveLogFile();
|
||||
await msleep(1);
|
||||
await rotatingLogs.deleteNonActiveLogFiles();
|
||||
files = await readdir(dir);
|
||||
const files = await readdir(dir);
|
||||
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeFalsy();
|
||||
expect(files.length).toBe(0);
|
||||
} finally {
|
||||
|
Loading…
Reference in New Issue
Block a user