-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
245 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,6 +1,9 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Middleware } from 'koa'; | ||
import { Options as ServeStaticOptions } from 'koa-static'; | ||
|
||
export interface NestKoaApplication extends INestApplication { | ||
use(...middleware: Middleware[]): this; | ||
|
||
useStaticAssets(path: string, options?: ServeStaticOptions): this; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { KoaAdapter, NestKoaApplication } from '../src'; | ||
import { Test } from '@nestjs/testing'; | ||
import { HelloWorldController } from './utils/HelloWorldController'; | ||
import { join } from 'path'; | ||
import fs from 'fs'; | ||
import { promisify } from 'util'; | ||
import supertest from 'supertest'; | ||
import assert from 'assert'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
describe.only('Static assets', () => { | ||
let app: NestKoaApplication; | ||
let file: Buffer; | ||
|
||
before(async () => { | ||
file = await readFile(join(__dirname, 'sample-data/static/image.png')); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
controllers: [HelloWorldController], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(new KoaAdapter()); | ||
app.useStaticAssets(join(__dirname, 'sample-data/static/')); | ||
|
||
await app.init(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('should serve static assets from defined folder', async () => { | ||
return supertest(app.getHttpServer()) | ||
.get('/image.png') | ||
.expect(200) | ||
.expect(res => { | ||
assert(file.equals(res.body)); | ||
}); | ||
}); | ||
|
||
it('should still serve data from endpoints', async () => { | ||
return supertest(app.getHttpServer()) | ||
.get('/hello/world/sync') | ||
.expect(200) | ||
.expect({ | ||
hello: 'world-sync', | ||
}); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.