Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try tests again #763

Merged
merged 4 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"eslint-plugin-prettier": "3.1.3",
"express": "4.17.1",
"husky": "4.2.5",
"jest": "^26.6.3",
"jest": "27.2.4",
"koa": "2.11.0",
"lint-staged": "10.2.7",
"make-dir-cli": "2.0.0",
"nyc": "15.0.1",
"nyc": "15.1.0",
"prettier": "2.0.5",
"prettier-plugin-pkgjson": "0.2.8",
"request": "2.88.2",
"supertest": "4.0.2"
"supertest": "6.1.6"
},
"jest": {
"verbose": true
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/http/no-filename/filename-name.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Content-Length: 1000
Content-Disposition: form-data; filename="plain.txt"; name="upload"
Content-Type: text/plain

I am a plain text file
I am a plain text file

------WebKitFormBoundarytyE4wkKlZ5CQJVTG--

4 changes: 2 additions & 2 deletions test/fixture/js/no-filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const generic_http = [
type: 'file',
name: 'upload',
originalFilename: '',
fixture: 'plain.txt',
fixture: 'generic',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872',
},
];
Expand All @@ -18,7 +18,7 @@ const filename_name_http = [
type: 'file',
name: 'upload',
originalFilename: 'plain.txt',
fixture: 'plain.txt',
fixture: 'filename-name',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872',
},
];
4 changes: 2 additions & 2 deletions test/fixture/js/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const crlf_http = [
type: 'file',
name: 'upload',
originalFilename: 'plain.txt',
fixture: 'plain.txt',
fixture: 'crlf',
sha1: 'b31d07bac24ac32734de88b3687dddb10e976872',
},
];
Expand All @@ -18,7 +18,7 @@ const preamble_http = [
type: 'file',
name: 'upload',
originalFilename: 'plain.txt',
fixture: 'plain.txt',
fixture: 'preamble',
sha1: 'a47f7a8a7959f36c3f151ba8b0bd28f2d6b606e2',
},
];
39 changes: 24 additions & 15 deletions test/fixture/js/special-chars-in-filename.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
const properFilename = 'funkyfilename.txt';

function expect(originalFilename) {
function expect(originalFilename, fixtureName) {
return [
{ type: 'field', name: 'title', value: 'Weird originalFilename' },
{
type: 'field',
name: 'title',
originalFilename: properFilename,
fixture: fixtureName,
},
{
type: 'file',
name: 'upload',
originalFilename,
fixture: properFilename,
originalFilename: originalFilename,
fixture: fixtureName,
},
];
}

const webkit = expect(' ? % * | " < > . ? ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt');
const ffOrIe = expect(' ? % * | " < > . ☃ ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt');
const lineSeparator = expect(null);
const osx_chrome_13_http = expect(' ? % * | " < > . ? ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt', 'osx-chrome-13');
const osx_firefox_3_6_http = expect(' ? % * | " < > . ? ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt', 'osx-firefox-3.6');

const xp_ie_7_http = expect(' ? % * | " < > . ☃ ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt', 'xp-ie-7');
const xp_ie_8_http = expect(' ? % * | " < > . ☃ ; \' @ # $ ^ & ( ) - _ = + { } [ ] ` ~.txt', 'xp-ie-8');
const lineSeparator = expect(null, 'line-separator');

export {
webkit as osx_chrome_13_http,
webkit as osx_firefox_3_6_http,
webkit as osx_safari_5_http,
webkit as xp_chrome_12_http,
webkit as xp_safari_5_http,
osx_chrome_13_http,
osx_firefox_3_6_http,
// webkit as osx_firefox_3_6_http,
// webkit as osx_safari_5_http,
// webkit as xp_chrome_12_http,
// webkit as xp_safari_5_http,

ffOrIe as xp_ie_7_http,
ffOrIe as xp_ie_8_http,
lineSeparator as line_separator_http,
// xp_ie_7_http,
// xp_ie_8_http,
// lineSeparator,
};
4 changes: 2 additions & 2 deletions test/fixture/js/workarounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const missing_hyphens1_http = [
type: 'file',
name: 'upload',
originalFilename: 'plain.txt',
fixture: 'plain.txt',
fixture: 'missing-hyphens1',
sha1: '8c26b82ec9107e99b3486844644e92558efe0c73',
},
];
Expand All @@ -18,7 +18,7 @@ const missing_hyphens2_http = [
type: 'file',
name: 'upload',
originalFilename: 'second-plaintext.txt',
fixture: 'second-plaintext.txt',
fixture: 'missing-hyphens2',
sha1: '798e39a4a1034232ed26e0aadd67f5d1ff10b966',
},
];
56 changes: 30 additions & 26 deletions test/integration/fixtures.test.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */

import { readdirSync, createReadStream } from 'fs';
import { createReadStream } from 'fs';
import { createConnection } from 'net';
import { join, basename } from 'path';
import { join } from 'path';
import { createServer } from 'http';
import { strictEqual } from 'assert';

import formidable from '../../src/index.js';

const PORT = 13534;
const CWD = process.cwd();
const FIXTURES_PATH = join(CWD, 'test', 'fixture', 'js');
const FIXTURES_HTTP = join(CWD, 'test', 'fixture', 'http');
const UPLOAD_DIR = join(CWD, 'test', 'tmp');
import * as encoding from "../fixture/js/encoding.js";
import * as misc from "../fixture/js/misc.js";
import * as noFilename from "../fixture/js/no-filename.js";
import * as preamble from "../fixture/js/preamble.js";
import * as workarounds from "../fixture/js/workarounds.js";
import * as specialCharsInFilename from "../fixture/js/special-chars-in-filename.js";

const fixtures= {
encoding,
misc,
[`no-filename`]: noFilename,
preamble,
[`special-chars-in-filename`]: specialCharsInFilename,
workarounds,
};

test('fixtures', (done) => {
const server = createServer();
server.listen(PORT, findFixtures);

function findFixtures() {
const results = readdirSync(FIXTURES_PATH)
// .filter((x) => /workarounds/.test(x))
.filter((x) => /\.js$/.test(x))
.reduce((acc, fp) => {
const group = basename(fp, '.js');
const filepath = join(FIXTURES_PATH, fp);
const mod = require(filepath);

Object.keys(mod).forEach((k) => {
Object.keys(mod[k]).forEach((_fixture) => {
acc.push({
fixture: mod[k],
name: join(group, k),
});
const results = Object.entries(fixtures).map(([fixtureGroup, fixture]) => {
return Object.entries(fixture).map(([k, v]) => {
return v.map(details => {
return {
fixture: v,
name: `${fixtureGroup}/${details.fixture}.http`
};
});
});

return acc;
}, []);

testNext(results);
}).flat(Infinity);
testNext(results);
}

function testNext(results) {
let fixture = results.shift();
if (!fixture) {
const fixtureWithName = results.shift();
if (!fixtureWithName) {
server.close();
done();
return;
}
const fixtureName = fixture.name;
fixture = fixture.fixture;
const fixtureName = fixtureWithName.name;
const fixture = fixtureWithName.fixture;

uploadFixture(fixtureName, (err, parts) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/standalone/keep-alive-error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('keep alive error', (done) => {
'Connection: keep-alive\r\n' +
'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
'Content-Length: 10011\r\n\r\n' +
'------aaa\n\r',
'------XXX\n\r',
);

setTimeout(() => {
Expand Down
Loading