@@ -2,19 +2,24 @@ import 'should'
22
33import { strict as assert } from 'node:assert'
44import fs from 'node:fs'
5+ import fsProm from 'node:fs/promises'
56import path from 'node:path'
67
78import sinon from 'sinon'
89
9- import { FileStore } from './'
10+ import { FileStore , FileConfigstore } from './'
1011import { Upload } from '@tus/server'
1112
1213import * as shared from '../../test/stores.test'
13- import { MemoryConfigstore } from './configstores/MemoryConfigstore'
1414
1515const fixturesPath = path . resolve ( '../' , '../' , 'test' , 'fixtures' )
1616const storePath = path . resolve ( '../' , '../' , 'test' , 'output' )
1717
18+ async function cleanup ( ) {
19+ await fsProm . rm ( storePath , { recursive : true } )
20+ await fsProm . mkdir ( storePath )
21+ }
22+
1823describe ( 'FileStore' , function ( ) {
1924 before ( function ( ) {
2025 this . testFileSize = 960_244
@@ -28,13 +33,13 @@ describe('FileStore', function () {
2833 sinon . spy ( fs , 'mkdir' )
2934 this . datastore = new FileStore ( {
3035 directory : this . storePath ,
31- configstore : new MemoryConfigstore ( ) ,
3236 } )
3337 } )
3438
35- this . afterEach ( ( ) => {
39+ this . afterEach ( async ( ) => {
3640 // @ts -expect-error ignore
3741 fs . mkdir . restore ( )
42+ await cleanup ( )
3843 } )
3944
4045 it ( 'should create a directory for the files' , function ( done ) {
@@ -89,9 +94,26 @@ describe('FileStore', function () {
8994 } )
9095 } )
9196
97+ describe ( 'FileConfigstore' , ( ) => {
98+ it ( 'should ignore random files in directory when calling list()' , async function ( ) {
99+ const store = new FileConfigstore ( storePath )
100+ const files = [ 'tus' , 'tus.json' , 'tu' , 'tuss.json' , 'random' ]
101+ for ( const file of files ) {
102+ await fsProm . writeFile ( path . resolve ( storePath , file ) , '' )
103+ }
104+ const list = await store . list ( )
105+
106+ // list returns the amount of uploads.
107+ // One upload consists of the file and the JSON info file.
108+ // But from the list perspective that is only one upload.
109+ assert . strictEqual ( list . length , 1 )
110+ } )
111+ } )
112+
92113 shared . shouldHaveStoreMethods ( )
93114 shared . shouldCreateUploads ( )
94115 shared . shouldRemoveUploads ( ) // Termination extension
116+ shared . shouldExpireUploads ( ) // Expiration extension
95117 shared . shouldWriteUploads ( )
96118 shared . shouldHandleOffset ( )
97119 shared . shouldDeclareUploadLength ( ) // Creation-defer-length extension
0 commit comments