This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
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
Showing
14 changed files
with
355 additions
and
112 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { light, Route } from '../../../../src/index'; | ||
|
||
class Index extends Route { | ||
public disableRequestLogger = true; | ||
|
||
public async handler() { | ||
return { | ||
hello: 'server', | ||
}; | ||
} | ||
} | ||
|
||
module.exports = light(Index); |
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,7 @@ | ||
import { light, Route } from '../../../../../src/index'; | ||
|
||
class Index extends Route {} | ||
|
||
module.exports = { | ||
default: light(Index), | ||
}; |
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,5 @@ | ||
import { light, Route } from '../../../../../src/index'; | ||
|
||
class Index extends Route {} | ||
|
||
export default light(Index); |
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 @@ | ||
throw new Error('error'); |
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,68 @@ | ||
import fetch from 'node-fetch'; | ||
import listen from 'test-listen'; | ||
import { join } from 'path'; | ||
|
||
import { | ||
server, | ||
light, | ||
Route, | ||
} from '../src/index'; | ||
|
||
let app: any; | ||
let url: any; | ||
|
||
beforeEach(async () => { | ||
url = await listen(app.server); | ||
}); | ||
|
||
afterEach(async () => { | ||
app.server.close(); | ||
}); | ||
|
||
describe('server', () => { | ||
describe('with functions as routes', () => { | ||
beforeAll(() => { | ||
app = server({ | ||
routes: [ | ||
{ | ||
handler: light(class Index extends Route { | ||
public disableRequestLogger = true; | ||
|
||
public async handler() { | ||
return { | ||
hello: 'server', | ||
}; | ||
} | ||
}), | ||
method: 'GET', | ||
path: '/', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('returns an object', async () => { | ||
expect.assertions(2); | ||
const req = await fetch(url); | ||
const res = await req.json(); | ||
expect(req.status).toStrictEqual(200); | ||
expect(res).toMatchObject({ hello: 'server' }); | ||
}); | ||
}); | ||
|
||
describe('with string as routes', () => { | ||
beforeAll(() => { | ||
app = server({ | ||
routes: join(__dirname, './seeds/server/routes'), | ||
}); | ||
}); | ||
|
||
it('returns an object', async () => { | ||
expect.assertions(2); | ||
const req = await fetch(url); | ||
const res = await req.json(); | ||
expect(req.status).toStrictEqual(200); | ||
expect(res).toMatchObject({ hello: 'server' }); | ||
}); | ||
}); | ||
}); |
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,20 +1,22 @@ | ||
import { light, Route } from '../../src/index'; | ||
|
||
describe('aws', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'aws'; | ||
describe('serverless', () => { | ||
describe('aws', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'aws'; | ||
|
||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
|
||
it('exports a handler', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.handler).toBeTruthy(); | ||
expect(typeof server.handler).toBe('function'); | ||
it('exports a handler', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.handler).toBeTruthy(); | ||
expect(typeof server.handler).toBe('function'); | ||
}); | ||
}); | ||
}); |
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,20 +1,22 @@ | ||
import { light, Route } from '../../src/index'; | ||
|
||
describe('netlify', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'netlify'; | ||
describe('serverless', () => { | ||
describe('netlify', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'netlify'; | ||
|
||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
|
||
it('exports a handler', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.handler).toBeTruthy(); | ||
expect(typeof server.handler).toBe('function'); | ||
it('exports a handler', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.handler).toBeTruthy(); | ||
expect(typeof server.handler).toBe('function'); | ||
}); | ||
}); | ||
}); |
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,19 +1,21 @@ | ||
import { light, Route } from '../../src/index'; | ||
|
||
describe('now', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'now'; | ||
describe('serverless', () => { | ||
describe('now', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'now'; | ||
|
||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
|
||
it('exports a function', async () => { | ||
expect.assertions(2); | ||
expect(server).toBeTruthy(); | ||
expect(typeof server).toBe('function'); | ||
it('exports a function', async () => { | ||
expect.assertions(2); | ||
expect(server).toBeTruthy(); | ||
expect(typeof server).toBe('function'); | ||
}); | ||
}); | ||
}); |
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,20 +1,22 @@ | ||
import { light, Route } from '../../src/index'; | ||
|
||
describe('runkit', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'runkit'; | ||
describe('serverless', () => { | ||
describe('runkit', () => { | ||
process.env.LIGHT_ENVIRONMENT = 'runkit'; | ||
|
||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
const server: any = light(class Index extends Route { | ||
public async handler() { | ||
return { | ||
hello: 'world', | ||
}; | ||
} | ||
}); | ||
|
||
it('exports a function', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.endpoint).toBeTruthy(); | ||
expect(typeof server.endpoint).toBe('function'); | ||
it('exports a function', async () => { | ||
expect.assertions(3); | ||
expect(server).toBeTruthy(); | ||
expect(server.endpoint).toBeTruthy(); | ||
expect(typeof server.endpoint).toBe('function'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.