mirror of
https://github.com/joelwmale/webhook-action.git
synced 2026-08-31 14:39:48 +08:00
add ability to call self-signed or invalid certificate clients
This commit is contained in:
+4
-4
@@ -59,12 +59,12 @@ test.only('foo'); // invalid
|
||||
/*eslint jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}]*/
|
||||
|
||||
it('foo'); // valid
|
||||
describe('foo', function() {
|
||||
describe('foo', function () {
|
||||
test('bar'); // valid
|
||||
});
|
||||
|
||||
test('foo'); // invalid
|
||||
describe('foo', function() {
|
||||
describe('foo', function () {
|
||||
it('bar'); // invalid
|
||||
});
|
||||
```
|
||||
@@ -78,12 +78,12 @@ nested within `describe` to use `it`.
|
||||
/*eslint jest/consistent-test-it: ["error"]*/
|
||||
|
||||
test('foo'); // valid
|
||||
describe('foo', function() {
|
||||
describe('foo', function () {
|
||||
it('bar'); // valid
|
||||
});
|
||||
|
||||
it('foo'); // invalid
|
||||
describe('foo', function() {
|
||||
describe('foo', function () {
|
||||
test('bar'); // invalid
|
||||
});
|
||||
```
|
||||
|
||||
+6
-13
@@ -56,9 +56,7 @@ import { expectSaga } from 'redux-saga-test-plan';
|
||||
import { addSaga } from '../src/sagas';
|
||||
|
||||
test('returns sum', () => {
|
||||
expectSaga(addSaga, 1, 1)
|
||||
.returns(2)
|
||||
.run();
|
||||
expectSaga(addSaga, 1, 1).returns(2).run();
|
||||
});
|
||||
```
|
||||
|
||||
@@ -72,13 +70,11 @@ import { expectSaga } from 'redux-saga-test-plan';
|
||||
import { addSaga } from '../src/sagas';
|
||||
|
||||
test('returns sum', () => {
|
||||
expectSaga(addSaga, 1, 1)
|
||||
.returns(2)
|
||||
.run();
|
||||
expectSaga(addSaga, 1, 1).returns(2).run();
|
||||
});
|
||||
```
|
||||
|
||||
Since the string is compiled into aa regular expression, you'll need to escape
|
||||
Since the string is compiled into a regular expression, you'll need to escape
|
||||
special characters such as `$` with a double backslash:
|
||||
|
||||
```js
|
||||
@@ -100,12 +96,9 @@ const express = require('express');
|
||||
|
||||
const app = express();
|
||||
|
||||
describe('GET /user', function() {
|
||||
it('responds with json', function(done) {
|
||||
request(app)
|
||||
.get('/user')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done);
|
||||
describe('GET /user', function () {
|
||||
it('responds with json', function (done) {
|
||||
request(app).get('/user').expect('Content-Type', /json/).expect(200, done);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
# Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)
|
||||
|
||||
When calling asynchronous code in hooks and tests, `jest` needs to know when the
|
||||
asynchronous work is complete to progress the current run.
|
||||
|
||||
Originally the most common pattern to archive this was to use callbacks:
|
||||
|
||||
```js
|
||||
test('the data is peanut butter', done => {
|
||||
function callback(data) {
|
||||
try {
|
||||
expect(data).toBe('peanut butter');
|
||||
done();
|
||||
} catch (error) {
|
||||
done(error);
|
||||
}
|
||||
}
|
||||
|
||||
fetchData(callback);
|
||||
});
|
||||
```
|
||||
|
||||
This can be very error prone however, as it requires careful understanding of
|
||||
how assertions work in tests or otherwise tests won't behave as expected.
|
||||
|
||||
For example, if the `try/catch` was left out of the above code, the test would
|
||||
timeout rather than fail. Even with the `try/catch`, forgetting to pass the
|
||||
caught error to `done` will result in `jest` believing the test has passed.
|
||||
|
||||
A more straightforward way to handle asynchronous code is to use Promises:
|
||||
|
||||
```js
|
||||
test('the data is peanut butter', () => {
|
||||
return fetchData().then(data => {
|
||||
expect(data).toBe('peanut butter');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
When a test or hook returns a promise, `jest` waits for that promise to resolve,
|
||||
as well as automatically failing should the promise reject.
|
||||
|
||||
If your environment supports `async/await`, this becomes even simpler:
|
||||
|
||||
```js
|
||||
test('the data is peanut butter', async () => {
|
||||
const data = await fetchData();
|
||||
expect(data).toBe('peanut butter');
|
||||
});
|
||||
```
|
||||
|
||||
## Rule details
|
||||
|
||||
This rule checks the function parameter of hooks & tests for use of the `done`
|
||||
argument, suggesting you return a promise instead.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```js
|
||||
beforeEach(done => {
|
||||
// ...
|
||||
});
|
||||
|
||||
test('myFunction()', done => {
|
||||
// ...
|
||||
});
|
||||
|
||||
test('myFunction()', function (done) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
The following patterns are not considered warnings:
|
||||
|
||||
```js
|
||||
beforeEach(async () => {
|
||||
await setupUsTheBomb();
|
||||
});
|
||||
|
||||
test('myFunction()', () => {
|
||||
expect(myFunction()).toBeTruthy();
|
||||
});
|
||||
|
||||
test('myFunction()', () => {
|
||||
return new Promise(done => {
|
||||
expect(myFunction()).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
```
|
||||
+1
-1
@@ -15,7 +15,7 @@ Examples of **incorrect** code for this rule:
|
||||
```js
|
||||
export function myHelper() {}
|
||||
|
||||
module.exports = function() {};
|
||||
module.exports = function () {};
|
||||
|
||||
module.exports = {
|
||||
something: 'that should be moved to a non-test file',
|
||||
|
||||
-1
@@ -172,4 +172,3 @@ safely disable this rule.
|
||||
## Further Reading
|
||||
|
||||
- [Jest docs - Setup and Teardown](https://facebook.github.io/jest/docs/en/setup-teardown.html)
|
||||
- [@jamiebuilds Twitter thread](https://twitter.com/jamiebuilds/status/954906997169664000)
|
||||
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
# Avoid using a callback in asynchronous tests (`no-test-callback`)
|
||||
|
||||
Jest allows you to pass a callback to test definitions, typically called `done`,
|
||||
that is later invoked to indicate that the asynchronous test is complete.
|
||||
|
||||
However, that means that if your test throws (e.g. because of a failing
|
||||
assertion), `done` will never be called unless you manually use `try-catch`.
|
||||
|
||||
```js
|
||||
test('some test', done => {
|
||||
expect(false).toBe(true);
|
||||
done();
|
||||
});
|
||||
```
|
||||
|
||||
The test above will time out instead of failing the assertions, since `done` is
|
||||
never called.
|
||||
|
||||
Correct way of doing the same thing is to wrap it in `try-catch`.
|
||||
|
||||
```js
|
||||
test('some test', done => {
|
||||
try {
|
||||
expect(false).toBe(true);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
However, Jest supports a second way of having asynchronous tests - using
|
||||
promises.
|
||||
|
||||
```js
|
||||
test('some test', () => {
|
||||
return new Promise(done => {
|
||||
expect(false).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Even though `done` is never called here, the Promise will still reject, and Jest
|
||||
will report the assertion error correctly.
|
||||
|
||||
## Rule details
|
||||
|
||||
This rule triggers a warning if you have a `done` callback in your test.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```js
|
||||
test('myFunction()', done => {
|
||||
// ...
|
||||
});
|
||||
|
||||
test('myFunction()', function(done) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
The following patterns are not considered warnings:
|
||||
|
||||
```js
|
||||
test('myFunction()', () => {
|
||||
expect(myFunction()).toBeTruthy();
|
||||
});
|
||||
|
||||
test('myFunction()', () => {
|
||||
return new Promise(done => {
|
||||
expect(myFunction()).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
```
|
||||
+3
-3
@@ -15,7 +15,7 @@ body.
|
||||
|
||||
// valid:
|
||||
|
||||
it('noop', function() {});
|
||||
it('noop', function () {});
|
||||
|
||||
test('noop', () => {});
|
||||
|
||||
@@ -27,7 +27,7 @@ test('one', () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
|
||||
it('one', function() {
|
||||
it('one', function () {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ test('return an expect', () => {
|
||||
return expect(1).toBe(1);
|
||||
});
|
||||
|
||||
it('returning a promise', function() {
|
||||
it('returning a promise', function () {
|
||||
return new Promise(res => setTimeout(res, 100)).then(() => expect(1).toBe(1));
|
||||
});
|
||||
```
|
||||
|
||||
+42
@@ -55,3 +55,45 @@ test('my test', () => {
|
||||
expect(someThing()).toEqual('foo');
|
||||
});
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
#### `onlyFunctionsWithAsyncKeyword`
|
||||
|
||||
When `true`, this rule will only warn for tests that use the `async` keyword.
|
||||
|
||||
```json
|
||||
{
|
||||
"rules": {
|
||||
"jest/prefer-expect-assertions": [
|
||||
"warn",
|
||||
{ "onlyFunctionsWithAsyncKeyword": true }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When `onlyFunctionsWithAsyncKeyword` option is set to `true`, the following
|
||||
pattern would be a warning:
|
||||
|
||||
```js
|
||||
test('my test', async () => {
|
||||
const result = await someAsyncFunc();
|
||||
expect(result).toBe('foo');
|
||||
});
|
||||
```
|
||||
|
||||
While the following patterns would not be considered warnings:
|
||||
|
||||
```js
|
||||
test('my test', () => {
|
||||
const result = someFunction();
|
||||
expect(result).toBe('foo');
|
||||
});
|
||||
|
||||
test('my test', async () => {
|
||||
expect.assertions(1);
|
||||
const result = await someAsyncFunc();
|
||||
expect(result).toBe('foo');
|
||||
});
|
||||
```
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ xtest('foo', () => {});
|
||||
|
||||
**titleMustBeString**
|
||||
|
||||
Titles for test blocks should always be a string literal or expression.
|
||||
Titles for test blocks should always be a string.
|
||||
|
||||
This is also applied to `describe` blocks by default, but can be turned off via
|
||||
the `ignoreTypeOfDescribeName` option:
|
||||
@@ -55,7 +55,7 @@ it(123, () => {});
|
||||
describe(String(/.+/), () => {});
|
||||
describe(myFunction, () => {});
|
||||
xdescribe(myFunction, () => {});
|
||||
describe(6, function() {});
|
||||
describe(6, function () {});
|
||||
```
|
||||
|
||||
Examples of **correct** code for this rule:
|
||||
@@ -82,7 +82,7 @@ fdescribe('is a string', () => {});
|
||||
describe(String(/.+/), () => {});
|
||||
describe(myFunction, () => {});
|
||||
xdescribe(myFunction, () => {});
|
||||
describe(6, function() {});
|
||||
describe(6, function () {});
|
||||
```
|
||||
|
||||
**duplicatePrefix**
|
||||
|
||||
Reference in New Issue
Block a user