Merge pull request #355 from RomanBurunkov/master

Remove static test files.
master
Roman Burunkov 8 months ago committed by GitHub
commit ee8e711a4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      .circleci/config.yml
  2. 1
      .gitignore
  3. 3
      .mocharc.json
  4. 6100
      package-lock.json
  5. 5
      package.json
  6. 2
      test/fileFactory.spec.js
  7. 12
      test/fileLimitUploads.spec.js
  8. BIN
      test/files/basket.ball.bp
  9. BIN
      test/files/basketball.png
  10. BIN
      test/files/car.png
  11. 0
      test/files/emptyfile.txt
  12. BIN
      test/files/my$Invalid#fileName.png123
  13. BIN
      test/files/tree.png
  14. 4
      test/multipartFields.spec.js
  15. 80
      test/multipartUploads.spec.js
  16. 2
      test/options.spec.js
  17. 5
      test/posttests.js
  18. 5
      test/pretests.js
  19. 2
      test/processNested.spec.js
  20. 27
      test/server.js
  21. 28
      test/tempFile.spec.js
  22. 2
      test/uploadtimer.spec.js
  23. 4
      test/utilities.spec.js

@ -1,10 +1,10 @@
version: 2.1
orbs:
node: circleci/node@4.7
node: circleci/node@5.1.0
jobs:
lintandcoverage:
docker:
- image: cimg/node:16.13.2
- image: cimg/node:16.20.2
steps:
- checkout
- run: npm install
@ -18,35 +18,35 @@ workflows:
context:
- COVERALLS
- node/test:
version: '12.22.6'
version: '16.20.2'
pkg-manager: npm
filters:
tags:
ignore:
- /.*/
- node/test:
version: '14.19.0'
version: '17.9.1'
pkg-manager: npm
filters:
tags:
ignore:
- /.*/
- node/test:
version: '15.14.0'
version: '18.17.1'
pkg-manager: npm
filters:
tags:
ignore:
- /.*/
- node/test:
version: '16.13.2'
version: '19.9.0'
pkg-manager: npm
filters:
tags:
ignore:
- /.*/
- node/test:
version: '17.4.0'
version: '20.6.0'
pkg-manager: npm
filters:
tags:

1
.gitignore vendored

@ -15,6 +15,7 @@ node_modules
coverage
.nyc_output
test/uploads
test/files/*
example/uploads/*
!example/uploads/placeholder.txt

@ -0,0 +1,3 @@
{
"spec": "test/**/*.spec.js"
}

6100
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -5,6 +5,8 @@
"description": "Simple express file upload middleware that wraps around Busboy",
"main": "./lib/index",
"scripts": {
"pretest": "node ./test/pretests.js",
"posttest": "node ./test/posttests.js",
"test": "nyc --reporter=html --reporter=text mocha -- -R spec",
"lint": "eslint ./",
"lint:fix": "eslint --fix ./",
@ -36,6 +38,7 @@
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"supertest": "^4.0.2"
"rnd-file": "^0.0.1",
"supertest": "^6.1.5"
}
}

@ -22,7 +22,7 @@ const mockFileOpts = {
tempFilePath: mockFile
};
describe('Test of the fileFactory factory', function() {
describe('fileFactory: Test of the fileFactory factory', function() {
beforeEach(() => server.clearUploadsDir());
it('return a file object', () => assert.ok(fileFactory(mockFileOpts)));

@ -7,7 +7,7 @@ const server = require('./server');
const clearUploadsDir = server.clearUploadsDir;
const fileDir = server.fileDir;
describe('Test Single File Upload With File Size Limit', function() {
describe('fileLimitUloads: Test Single File Upload With File Size Limit', function() {
let app, limitHandlerRun;
beforeEach(function() {
@ -39,7 +39,10 @@ describe('Test Single File Upload With File Size Limit', function() {
.post('/upload/single/truncated')
.attach('testFile', filePath)
.expect(413)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
});
@ -63,8 +66,9 @@ describe('Test Single File Upload With File Size Limit', function() {
.post('/upload/single/truncated')
.attach('testFile', filePath)
.expect(500, {response: 'Limit reached!'})
.end(function(err){
if (err) return done(err);
.end(function(err) {
// err.code === 'ECONNRESET' that means upload has been aborted.
if (err && err.code !== 'ECONNRESET') return done(err);
if (!limitHandlerRun) return done('handler did not run');
done();
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 KiB

@ -17,7 +17,7 @@ let mockCars = [
'integra'
];
describe('Test Multipart Form Single Field Submissions', function() {
describe('multipartFields: Test Multipart Form Single Field Submissions', function() {
it('submit multipart user data with POST', function(done) {
request(app)
.post('/fields/user')
@ -62,7 +62,7 @@ describe('Test Multipart Form Single Field Submissions', function() {
});
});
describe('Test Multipart Form Array Field Submissions', function() {
describe('multipartFields: Test Multipart Form Array Field Submissions', function() {
it('submit array of data with POST', function(done) {
let req = request(app).post('/fields/array');

@ -38,7 +38,7 @@ const genUploadResult = (fileName, filePath) => {
};
};
describe('Test Directory Cleaning Method', function() {
describe('multipartUploads: Test Directory Cleaning Method', function() {
it('emptied "uploads" directory', function(done) {
clearUploadsDir();
const filesFound = fs.readdirSync(uploadDir).length;
@ -46,7 +46,7 @@ describe('Test Directory Cleaning Method', function() {
});
});
describe('Test Single File Upload', function() {
describe('multipartUploads: Test Single File Upload', function() {
const app = server.setup();
mockFiles.forEach((fileName) => {
@ -70,7 +70,7 @@ describe('Test Single File Upload', function() {
.attach('testFile', filePath)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
it('fail when no files were attached', function(done) {
@ -85,7 +85,10 @@ describe('Test Single File Upload', function() {
.get('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
it('fail when using HEAD', function(done) {
@ -93,11 +96,14 @@ describe('Test Single File Upload', function() {
.head('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
});
describe('Test Single File Upload w/ .mv()', function() {
describe('multipartUploads: Test Single File Upload w/ .mv()', function() {
const app = server.setup();
mockFiles.forEach((fileName) => {
@ -125,14 +131,14 @@ describe('Test Single File Upload w/ .mv()', function() {
});
});
describe('Test Single File Upload with useTempFiles option.', function() {
describe('multipartUploads: Test Single File Upload w/ useTempFiles option.', function() {
const app = server.setup({ useTempFiles: true, tempFileDir: tempDir });
mockFiles.forEach((fileName) => {
const filePath = path.join(fileDir, fileName);
const uploadedFilePath = path.join(uploadDir, fileName);
const result = genUploadResult(fileName, filePath);
it(`upload ${fileName} with POST`, function(done) {
clearUploadsDir();
request(app)
@ -149,7 +155,7 @@ describe('Test Single File Upload with useTempFiles option.', function() {
.attach('testFile', filePath)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
it('fail when no files were attached', function(done) {
@ -164,7 +170,10 @@ describe('Test Single File Upload with useTempFiles option.', function() {
.get('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
it('fail when using HEAD', function(done) {
@ -172,11 +181,14 @@ describe('Test Single File Upload with useTempFiles option.', function() {
.head('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
});
describe('Test Single File Upload with useTempFiles option and empty tempFileDir.', function() {
describe('multipartUploads: Single File Upload w/ useTempFiles & empty tempFileDir.', function() {
const app = server.setup({ useTempFiles: true, tempFileDir: '' });
mockFiles.forEach((fileName) => {
@ -191,18 +203,18 @@ describe('Test Single File Upload with useTempFiles option and empty tempFileDir
.attach('testFile', filePath)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
});
describe('Test Single File Upload w/ .mv() Promise', function() {
describe('multipartUploads: Test Single File Upload w/ .mv() Promise', function() {
const app = server.setup();
mockFiles.forEach((fileName) => {
const filePath = path.join(fileDir, fileName);
const uploadedFilePath = path.join(uploadDir, fileName);
const result = genUploadResult(fileName, filePath);
it(`upload ${fileName} with POST w/ .mv() Promise`, function(done) {
clearUploadsDir();
request(app)
@ -219,7 +231,7 @@ describe('Test Single File Upload w/ .mv() Promise', function() {
.attach('testFile', filePath)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
it('fail when no files were attached', function(done) {
@ -234,7 +246,10 @@ describe('Test Single File Upload w/ .mv() Promise', function() {
.get('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
it('fail when using HEAD', function(done) {
@ -242,18 +257,21 @@ describe('Test Single File Upload w/ .mv() Promise', function() {
.head('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
});
describe('Test Single File Upload w/ .mv() Promise and useTempFiles set to true', function() {
describe('multipartUploads: Test Single File Upload w/ .mv() Promise & useTempFiles', function() {
const app = server.setup({ useTempFiles: true, tempFileDir: tempDir });
mockFiles.forEach((fileName) => {
const filePath = path.join(fileDir, fileName);
const uploadedFilePath = path.join(uploadDir, fileName);
const result = genUploadResult(fileName, filePath);
it(`upload ${fileName} with POST w/ .mv() Promise`, function(done) {
clearUploadsDir();
request(app)
@ -270,7 +288,7 @@ describe('Test Single File Upload w/ .mv() Promise and useTempFiles set to true'
.attach('testFile', filePath)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
it('fail when no files were attached', (done) => {
@ -285,7 +303,10 @@ describe('Test Single File Upload w/ .mv() Promise and useTempFiles set to true'
.get('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
it('fail when using HEAD', (done) => {
@ -293,11 +314,14 @@ describe('Test Single File Upload w/ .mv() Promise and useTempFiles set to true'
.head('/upload/single')
.attach('testFile', path.join(fileDir, mockFiles[0]))
.expect(400)
.end(done);
.end((err) => {
// err.code === 'ECONNRESET' that means upload has been aborted.
done(err && err.code !== 'ECONNRESET' ? err : null);
});
});
});
describe('Test Multi-File Upload', function() {
describe('multipartUploads: Test Multi-File Upload', function() {
const app = server.setup();
it('upload multiple files with POST', (done) => {
@ -336,7 +360,7 @@ describe('Test Multi-File Upload', function() {
});
});
describe('Test File Array Upload', function() {
describe('multipartUploads: Test File Array Upload', function() {
const app = server.setup();
it('upload array of files with POST', (done) => {
@ -372,7 +396,7 @@ describe('Test File Array Upload', function() {
});
});
describe('Test Upload With Fields', function() {
describe('multipartUploads: Test Upload With Fields', function() {
const app = server.setup();
mockFiles.forEach((fileName) => {
const filePath = path.join(fileDir, fileName);
@ -405,11 +429,11 @@ describe('Test Upload With Fields', function() {
.field('email', mockUser.email)
.expect(resetBodyUploadData)
.expect(200, result, err => (err ? done(err) : fs.stat(uploadedFilePath, done)));
});
});
});
});
describe('Test Aborting/Canceling during upload', function() {
describe('multipartUploads: Test Aborting/Canceling during upload', function() {
this.timeout(4000); // Set timeout for async tests.
const uploadTimeout = 1000;

@ -6,7 +6,7 @@ const clearUploadsDir = server.clearUploadsDir;
const fileDir = server.fileDir;
const uploadDir = server.uploadDir;
describe('File Upload Options Tests', function() {
describe('options: File Upload Options Tests', function() {
afterEach(function(done) {
clearUploadsDir();
done();

@ -0,0 +1,5 @@
const { clearFileDir } = require('./server');
console.log('clearing test files...');
clearFileDir();
console.log('done');

@ -0,0 +1,5 @@
const { createTestFiles } = require('./server');
console.log('creating test files...');
createTestFiles()
.then(() => console.log('done'));

@ -3,7 +3,7 @@
const assert = require('assert');
const processNested = require('../lib/processNested');
describe('Test Convert Flatten object to Nested object', function() {
describe('processNested: Test Convert Flatten object to Nested object', function() {
it('With no nested data', () => {
const data = {
'firstname': 'John',

@ -3,11 +3,21 @@
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const randomFile = require('rnd-file');
const fileDir = path.join(__dirname, 'files');
const tempDir = path.join(__dirname, 'temp');
const uploadDir = path.join(__dirname, 'uploads');
const mockFiles = [
{ name: 'emptyfile.txt', size: 0 },
{ name: 'basket.ball.bp', size: 151 * 1024 },
{ name: 'basketball.png', size: 151 * 1024 },
{ name: 'car.png', size: 263 * 1024 },
{ name: 'my$Invalid#fileName.png123', size: 263 * 1024 },
{ name: 'tree.png', size: 266 * 1024 }
];
const clearDir = (dir) => {
try {
if (fs.existsSync(dir)) rimraf.sync(dir);
@ -17,8 +27,9 @@ const clearDir = (dir) => {
}
};
const clearUploadsDir = () => clearDir(uploadDir);
const clearTempDir = () => clearDir(tempDir);
const createTestFiles = () => Promise.all(mockFiles.map((file) => {
return randomFile({ filePath: fileDir, fileName: file.name, fileSize: file.size });
}));
const getUploadedFileData = (file) => ({
md5: file.md5,
@ -79,7 +90,7 @@ const setup = (fileUploadOptions) => {
if (!req.body) {
return res.status(400).send('No request body found');
}
const fields = ['firstName', 'lastName', 'email'];
for (let i = 0; i < fields.length; i += 1) {
if (!req.body[fields[i]] || !req.body[fields[i]].trim()) {
@ -116,14 +127,14 @@ const setup = (fileUploadOptions) => {
}
const fileNames = ['testFile1', 'testFile2', 'testFile3'];
const testFiles = fileNames.map(file => req.files[file]);
for (let i = 0; i < testFiles.length; i += 1) {
if (!testFiles[i]) {
return res.status(400).send(`${fileNames[i]} was not uploaded!`);
}
}
const filesData = testFiles.map(file => getUploadedFileData(file));
testFiles[0].mv(filesData[0].uploadPath, (err) => {
@ -270,6 +281,8 @@ module.exports = {
fileDir,
tempDir,
uploadDir,
clearTempDir,
clearUploadsDir
clearFileDir: () => clearDir(fileDir),
clearTempDir: () => clearDir(tempDir),
clearUploadsDir: () => clearDir(uploadDir),
createTestFiles
};

@ -3,13 +3,12 @@ const md5 = require('md5');
const path = require('path');
const request = require('supertest');
const server = require('./server');
const clearUploadsDir =
server.clearUploadsDir;
const fileDir =
server.fileDir;
const uploadDir =
server.uploadDir;
describe('File Upload Options Tests', function() {
const clearUploadsDir = server.clearUploadsDir;
const fileDir = server.fileDir;
const uploadDir = server.uploadDir;
describe('tempFile: Test fileupload w/ useTempFiles.', function() {
afterEach(function(done) {
clearUploadsDir();
done();
@ -54,21 +53,18 @@ describe('File Upload Options Tests', function() {
if (err) {
return done(err);
}
fs.stat(uploadedFilePath, done);
});
}
describe('Testing [safeFileNames with useTempFiles] option to ensure:', function() {
describe('Testing [safeFileNames w/ useTempFiles] option to ensure:', function() {
it('Does nothing to your filename when disabled.', function(done) {
const fileUploadOptions = {
safeFileNames: false,
useTempFiles: true,
tempFileDir: '/tmp/'
};
const actualFileName =
'my$Invalid#fileName.png123';
const expectedFileName =
'my$Invalid#fileName.png123';
const actualFileName = 'my$Invalid#fileName.png123';
const expectedFileName = 'my$Invalid#fileName.png123';
executeFileUploadTestWalk(
fileUploadOptions,
actualFileName,
@ -81,10 +77,8 @@ describe('File Upload Options Tests', function() {
useTempFiles: true,
tempFileDir: '/tmp/'
};
const actualFileName =
'my$Invalid#fileName.png123';
const expectedFileName =
'my$Invalid#fileName.png123';
const actualFileName = 'my$Invalid#fileName.png123';
const expectedFileName = 'my$Invalid#fileName.png123';
executeFileUploadTestWalk(
fileUploadOptions,
actualFileName,

@ -3,7 +3,7 @@
const assert = require('assert');
const UploadTimer = require('../lib/uploadtimer');
describe('Test UploadTimer class', () => {
describe('uploadTimer: Test UploadTimer class', () => {
it('It runs a callback function after specified timeout.', (done) => {
const uploadTimer = new UploadTimer(1000, done);

@ -28,7 +28,7 @@ const mockBuffer = fs.readFileSync(path.join(fileDir, mockFile));
const mockHash = md5(mockBuffer);
describe('Test of the utilities functions', function() {
describe('utilities: Test of the utilities functions', function() {
beforeEach(function() {
server.clearUploadsDir();
});
@ -207,7 +207,7 @@ describe('Test of the utilities functions', function() {
});
//buildFields tests
describe('Test buildOptions function', () => {
describe('Test buildFields function', () => {
it('buildFields does nothing if null value has been passed', () => {
let fields = null;

Loading…
Cancel
Save