From 5f145ada444ce88601859db6d5335e557b084a56 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Wed, 18 Sep 2024 20:35:16 +0800 Subject: [PATCH] fix: test --- packages/busboy/test/clean.test.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/busboy/test/clean.test.ts b/packages/busboy/test/clean.test.ts index 402439b49acf..236bb9de952d 100644 --- a/packages/busboy/test/clean.test.ts +++ b/packages/busboy/test/clean.test.ts @@ -1,11 +1,10 @@ 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'); @@ -13,20 +12,21 @@ describe('test/clan.test.ts', function () { const app = await createFunctionApp(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); }); });