Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add types to support typescript projects
- Loading branch information
Showing
10 changed files
with
247 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const { exec } = require('child_process'); | ||
|
||
describe('typescript project', () => { | ||
// eslint-disable-next-line jest/no-done-callback | ||
it('should successfully run jest tests of typescript project', (done) => { | ||
const cmd = 'cd integration_tests/tsProject && npx jest my.successful.test.ts'; | ||
exec(cmd, (error) => { | ||
expect(error).toBeNull(); | ||
done(); | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line jest/no-done-callback | ||
it('should let jest tests fail if tests failing', (done) => { | ||
const cmd = 'cd integration_tests/tsProject && npx jest my.failing.test.ts'; | ||
exec(cmd, (error) => { | ||
expect(error?.code).toBe(1); | ||
expect(error?.message).toStrictEqual( | ||
expect.stringContaining('expected http status code 200 to equal 500'), | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,10 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
// For real projects, use: | ||
// setupFilesAfterEnv: ['jest-matcher-http'], | ||
// Since this is a integration test project, living in the main | ||
// package, we have to import the main package with a relative path. | ||
setupFilesAfterEnv: ['../../'], | ||
}; |
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,24 @@ | ||
// For real projects, use: | ||
// import 'jest-matcher-http'; | ||
// Since this is a integration test project, living in the main | ||
// package, we have to import the main package with a relative path. | ||
import '../../'; | ||
|
||
import axios, { AxiosInstance, AxiosResponse } from 'axios'; | ||
|
||
const { runAgainstServer } = require('../localServer.int.helper'); | ||
|
||
describe('matchers', () => { | ||
let request: AxiosInstance; | ||
let response: AxiosResponse; | ||
|
||
test('should always fail', async () => { | ||
await runAgainstServer(async (url: string) => { | ||
request = axios.create({ baseURL: url }); | ||
response = await request.get('/get-json'); | ||
}); | ||
|
||
expect(response).toReturnHttpCode(500); | ||
expect(response).toReturnHttpHeader('non-existing', 'Header'); | ||
}); | ||
}); |
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,24 @@ | ||
// For real projects, use: | ||
// import 'jest-matcher-http'; | ||
// Since this is a integration test project, living in the main | ||
// package, we have to import the main package with a relative path. | ||
import '../../'; | ||
|
||
import axios, { AxiosInstance, AxiosResponse } from 'axios'; | ||
|
||
const { runAgainstServer } = require('../localServer.int.helper'); | ||
|
||
describe('matchers', () => { | ||
let request: AxiosInstance; | ||
let response: AxiosResponse; | ||
|
||
test('should be able to use http matchers', async () => { | ||
await runAgainstServer(async (url: string) => { | ||
request = axios.create({ baseURL: url }); | ||
response = await request.get('/get-json'); | ||
}); | ||
|
||
expect(response).toReturnHttpCode(200); | ||
expect(response).toReturnHttpHeader('some', 'Header'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export {}; | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toReturnHttpCode(status: number): R; | ||
toReturnHttpHeader(headerField: string, headerValue: string): R; | ||
} | ||
} | ||
} |