fix: do not throw when no dir (#48)
This commit is contained in:
Родитель
13328b9a23
Коммит
6dc14c3cbe
|
@ -59,7 +59,11 @@ export class FileSystemPersist implements PersistentStorage {
|
|||
|
||||
fs.stat(tempDir, (statErr: Error | null, stats: fs.Stats) => {
|
||||
if (statErr) {
|
||||
if (((statErr as unknown) as { code: string }).code === 'ENOENT') {
|
||||
callback(null);
|
||||
} else {
|
||||
callback(statErr);
|
||||
}
|
||||
} else if (stats.isDirectory()) {
|
||||
fs.readdir(tempDir, (error, origFiles) => {
|
||||
if (!error) {
|
||||
|
|
|
@ -94,15 +94,24 @@ describe('FileSystemPersist', () => {
|
|||
});
|
||||
|
||||
describe('#shift()', () => {
|
||||
it('should not crash if folder does not exist', (done) => {
|
||||
const persister = new FileSystemPersist({ instrumentationKey });
|
||||
persister.shift((err) => {
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash if file does not exist', (done) => {
|
||||
const persister = new FileSystemPersist({ instrumentationKey });
|
||||
assert.doesNotThrow(() => {
|
||||
fs.mkdir(tempDir, () => {
|
||||
persister.shift((err) => {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the first file on disk and return it', (done) => {
|
||||
const persister = new FileSystemPersist({ instrumentationKey });
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче