Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Sep 18, 2024
1 parent deefb53 commit 5f145ad
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/busboy/test/clean.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { createHttpRequest, close, createFunctionApp } from '@midwayjs/mock';
import { join } from 'path';
import * as assert from 'assert';
import * as ServerlessApp from '../../../packages-legacy/serverless-app/src';
import { existsSync, statSync } from 'fs';
import { sleep } from '@midwayjs/core';

describe('test/clan.test.ts', function () {
describe('test/clean.test.ts', function () {

it('upload file auto clean', async () => {
const appDir = join(__dirname, 'fixtures/clean');
const imagePath = join(__dirname, 'fixtures/1.jpg');
const app = await createFunctionApp<ServerlessApp.Framework>(appDir, {}, ServerlessApp);
const request = await createHttpRequest(app);
const stat = statSync(imagePath);
await request.post('/upload')
const response = await request.post('/upload')
.field('name', 'form')
.attach('file', imagePath)
.expect(200)
.then(async response => {
assert(response.body.files.length === 1);
assert(response.body.files[0].filename === '1.jpg');
assert(response.body.fields.name === 'form');
const file1Stat = statSync(response.body.files[0].data);
assert(file1Stat.size && file1Stat.size === stat.size);
await sleep(2000);
const exists = existsSync(response.body.files[0].data);
assert(!exists);
});
.attach('file', imagePath);

expect(response.status).toBe(200);
expect(response.body.files.length).toBe(1);
expect(response.body.files[0].filename).toBe('1.jpg');
expect(response.body.fields.name).toBe('form');
const file1Stat = statSync(response.body.files[0].data);
expect(file1Stat.size).toBe(stat.size);

await sleep(2000);

const exists = existsSync(response.body.files[0].data);
expect(exists).toBe(false);
await close(app);
});
});

0 comments on commit 5f145ad

Please sign in to comment.