-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deefb53
commit 5f145ad
Showing
1 changed file
with
15 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |