Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chaijs/chai-http
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 799f668c1d38b82671f7c95cd9b32e5373b8ddb6
Choose a base ref
...
head repository: chaijs/chai-http
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a3715c4ec8cc5ec8b44af27b132d551050b53b1c
Choose a head ref

Commits on May 28, 2019

  1. Copy the full SHA
    da01dba View commit details
  2. Copy the full SHA
    cfd84e3 View commit details

Commits on May 31, 2019

  1. Merge pull request #250 from chaijs/ci/fix-tokens

    ci: add secure variables to release stage
    vieiralucas authored May 31, 2019
    Copy the full SHA
    9a99ed4 View commit details

Commits on Aug 19, 2019

  1. Copy the full SHA
    7f9a8a5 View commit details

Commits on Aug 20, 2019

  1. Copy the full SHA
    7f5f260 View commit details

Commits on Aug 23, 2019

  1. feat: add charset assertion (#253)

    kierans authored and keithamus committed Aug 23, 2019
    Copy the full SHA
    50d9db4 View commit details

Commits on Oct 25, 2019

  1. Build: Use GitHub Actions for CI/CD (#255)

    * build: Use GitHub Actions for CI/CD
    
    * build: add github token to publish step
    
    Co-Authored-By: Austin Cawley-Edwards <austin.cawley@gmail.com>
    
    * build: drop travis
    keithamus authored Oct 25, 2019
    1
    Copy the full SHA
    601854f View commit details

Commits on Feb 24, 2021

  1. feat(deps): update superagent to ^6.1.0 (#281)

    Bump `superagent` to ^6.1.0 to fix security vulnerabilities.
    
    BREAKING CHANGE: upgrades superagent to a new major version, closes #265
    Exotrom authored Feb 24, 2021
    Copy the full SHA
    4a196eb View commit details
  2. ci: correctly template github event in if condition for release (#283)

    * ci: correctly template github event in if condition for release
    * add comment for NPM token name
    
    Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
    austince and keithamus authored Feb 24, 2021
    Copy the full SHA
    c34b299 View commit details
  3. Copy the full SHA
    55c0e80 View commit details
  4. Copy the full SHA
    56e15ff View commit details
  5. Copy the full SHA
    edb5bca View commit details

Commits on Feb 25, 2021

  1. Copy the full SHA
    04ebb3d View commit details

Commits on Feb 26, 2021

  1. feat: drop support for node < 10

    BREAKING CHANGE: drop support for Node < 10
    austince committed Feb 26, 2021
    Copy the full SHA
    233118b View commit details
  2. Copy the full SHA
    ee4952e View commit details
  3. Copy the full SHA
    0e78cee View commit details
  4. Copy the full SHA
    be1d005 View commit details
  5. docs: add badges to the README

    kiki1607 authored and austince committed Feb 26, 2021
    Copy the full SHA
    0c2c350 View commit details

Commits on Feb 27, 2021

  1. ci: update npm token (#289)

    austince authored Feb 27, 2021
    Copy the full SHA
    dbba17c View commit details

Commits on Jun 9, 2023

  1. Dependency updates to fix security vulnerabilities (#306)

    * build(deps): Updated superagent,cookiejar,qs to the latest version
    
    Update superagent to latest version for fixing security vulnerabilities
    
    * build(deps): Locking superagent types to 4.1.13 due to failing build
    
    * extend cookie expiry dates
    
    * use a more reliable site for network tests
    
    * use webooks.site for echo tests
    
    * ditch console log
    
    * increase timeout on tests that hit webook.site
    
    ---------
    
    Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
    Trickfilm400 and keithamus authored Jun 9, 2023
    Copy the full SHA
    ce9866f View commit details
  2. build

    keithamus committed Jun 9, 2023
    Copy the full SHA
    83f4f9e View commit details
  3. 4.4.0

    keithamus committed Jun 9, 2023
    Copy the full SHA
    a3715c4 View commit details
Showing with 28,510 additions and 4,307 deletions.
  1. +48 −0 .github/workflows/ci.yml
  2. +14 −0 .releaserc.json
  3. +0 −20 .travis.yml
  4. +70 −22 README.md
  5. +3,003 −1,015 dist/chai-http.js
  6. +45 −21 dist/chai-http.js.map
  7. +7 −7 dist/chai-http.min.js
  8. +548 −164 dist/chai-http.min.js.map
  9. +35 −0 lib/http.js
  10. +24,627 −2,959 package-lock.json
  11. +16 −9 package.json
  12. +0 −53 support/readme.js
  13. +32 −3 test/http.js
  14. +63 −34 test/request.js
  15. +2 −0 types/index.d.ts
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Chai HTTP

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
name: Test on node ${{ matrix.node_version }}
runs-on: ubuntu-latest
strategy:
matrix:
node_version:
- 10 # to be removed 2021-05
- 12 # to be removed 2022-05
- 14 # to be removed 2023-05
- x.x.x # safety net; don't remove
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- run: npm ci
- run: npm test
- uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}


publish-npm:
if: ${{ github.event_name == 'push' }}
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run release
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}} # ff9b......76c4
GITHUB_TOKEN: ${{secrets.GH_RELEASE_TOKEN}}
14 changes: 14 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
["@semantic-release/git", {
"assets": ["dist/*", "package.json", "CHANGELOG.md", "package-lock.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}]
],
"tagFormat": "${version}"
}
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

92 changes: 70 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chai HTTP [![Build Status](https://travis-ci.org/chaijs/chai-http.svg?branch=master)](https://travis-ci.org/chaijs/chai-http)
# Chai HTTP [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![NPM version](https://img.shields.io/npm/v/chai-http.svg)](https://img.shields.io/npm/v/chai-http.svg) [![Dependency Status](https://img.shields.io/david/chaijs/chai-http.svg)](https://img.shields.io/david/chaijs/chai-http.svg) [![devDependencies](https://david-dm.org/chaijs/chai-http/dev-status.svg)](https://david-dm.org/chaijs/chai-http/dev-status.svg)

> HTTP integration testing with Chai assertions.
@@ -11,7 +11,7 @@

#### Installation

This is a addon plugin for the [Chai Assertion Library](http://chaijs.com). Install via [npm](http://npmjs.org).
This is an addon plugin for the [Chai Assertion Library](http://chaijs.com). Install via [npm](http://npmjs.org).

npm install chai-http

@@ -20,8 +20,8 @@ This is a addon plugin for the [Chai Assertion Library](http://chaijs.com). Inst
Use this plugin as you would all other Chai plugins.

```js
var chai = require('chai')
, chaiHttp = require('chai-http');
const chai = require('chai');
const chaiHttp = require('chai-http');

chai.use(chaiHttp);
```
@@ -68,13 +68,13 @@ keep the server open, perhaps if you're making multiple requests, you must call
`.keepOpen()` after `.request()`, and manually close the server down:

```js
var requester = chai.request(app).keepOpen()
const requester = chai.request(app).keepOpen()

Promise.all([
requester.get('/a'),
requester.get('/b'),
])
.then(responses => ....)
.then(responses => { /* ... */ })
.then(() => requester.close())
```

@@ -90,17 +90,37 @@ chai.request('http://localhost:8080')

#### Setting up requests

Once a request is created with a given VERB, it can have headers, form data,
json, or even file attachments added to it, all with a simple API:
Once a request is created with a given VERB (get, post, etc), you chain on these additional methods to create your request:

| Method | Purpose |
|---|---|
| `.set(key, value)` | Set request headers |
| `.send(data)` | Set request data (default type is JSON) |
| `.type(dataType)` | Change the type of the data sent from the `.send()` method (xml, form, etc) |
| `.attach(field, file, attachment)` | Attach a file |
| `.auth(username, password)` | Add auth headers for Basic Authentication |
| `.query(parmasObject)` | Chain on some GET parameters |

Examples:

`.set()`
```js
// Set a request header
chai.request(app)
.put('/user/me')
.set('Content-Type', 'application/json')
.send({ password: '123', confirmPassword: '123' })
```

`.send()`
```js
// Send some JSON
chai.request(app)
.put('/user/me')
.set('X-API-Key', 'foobar')
.send({ password: '123', confirmPassword: '123' })
```

`.type()`
```js
// Send some Form Data
chai.request(app)
@@ -113,20 +133,29 @@ chai.request(app)
})
```

`.attach()`
```js
// Attach a file
chai.request(app)
.post('/user/avatar')
.attach('imageField', fs.readFileSync('avatar.png'), 'avatar.png')
```

`.auth()`
```js
// Authenticate with Basic authentication
chai.request(app)
.get('/protected')
.auth('user', 'pass')

// Authenticate with Bearer Token
chai.request(app)
.get('/protected')
.auth(accessToken, { type: 'bearer' })

```

`.query()`
```js
// Chain some GET query parameters
chai.request(app)
@@ -139,7 +168,7 @@ chai.request(app)
In the following examples we use Chai's Expect assertion library:

```js
var expect = chai.expect;
const { expect } = chai;
```

To make the request and assert on its response, the `end` method can be used:
@@ -148,7 +177,7 @@ To make the request and assert on its response, the `end` method can be used:
chai.request(app)
.put('/user/me')
.send({ password: '123', confirmPassword: '123' })
.end(function (err, res) {
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(200);
});
@@ -170,16 +199,16 @@ callback has completed, and the assertions can be verified:
it('fails, as expected', function(done) { // <= Pass in done callback
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
.end((err, res) => {
expect(res).to.have.status(123);
done(); // <= Call done to signal callback end
});
});

it('succeeds silently!', function() { // <= No done callback
it('succeeds silently!', () => { // <= No done callback
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
.end((err, res) => {
expect(res).to.have.status(123); // <= Test completes before this runs
});
});
@@ -198,16 +227,15 @@ and chaining of `then`s becomes possible:
chai.request(app)
.put('/user/me')
.send({ password: '123', confirmPassword: '123' })
.then(function (res) {
.then((res) => {
expect(res).to.have.status(200);
})
.catch(function (err) {
.catch((err) => {
throw err;
});
```

__Note:__ Node.js version 0.10.x and some older web browsers do not have
native promise support. You can use any spec compliant library, such as:
__Note:__ Some older web browsers do not have native promise support. You can use any spec compliant library, such as:
- [kriskowal/q](https://github.com/kriskowal/q)
- [stefanpenner/es6-promise](https://github.com/stefanpenner/es6-promise)
- [petkaantonov/bluebird](https://github.com/petkaantonov/bluebird)
@@ -220,7 +248,7 @@ requiring in chai-http. For example:
if (!global.Promise) {
global.Promise = require('q');
}
var chai = require('chai');
const chai = require('chai');
chai.use(require('chai-http'));
```

@@ -231,16 +259,16 @@ next (for example, when you want to login with the first request, then access an

```js
// Log in
var agent = chai.request.agent(app)
const agent = chai.request.agent(app)
agent
.post('/session')
.send({ username: 'me', password: '123' })
.then(function (res) {
.then((res) => {
expect(res).to.have.cookie('sessionid');
// The `agent` now has the sessionid cookie saved, and will send it
// back to the server in the next request:
return agent.get('/user/me')
.then(function (res) {
.then((res) => {
expect(res).to.have.status(200);
});
});
@@ -320,6 +348,16 @@ expect(req).to.be.html;
expect(req).to.be.text;
```

### .charset



Assert that a `Response` or `Request` object has a given charset.

```js
expect(req).to.have.charset('utf-8');
```

### .redirect


@@ -372,6 +410,16 @@ expect(res).to.have.cookie('session_id', '1234');
expect(res).to.not.have.cookie('PHPSESSID');
```

## Releasing

`chai-http` is released with [`semantic-release`](https://github.com/semantic-release/semantic-release) using the plugins:
- [`commit-analyzer`](https://github.com/semantic-release/commit-analyzer) to determine the next version from commit messages.
- [`release-notes-generator`](https://github.com/semantic-release/release-notes-generator) to summarize release in
- [`changelog`](https://github.com/semantic-release/changelog) to update the CHANGELOG.md file.
- [`github`](https://github.com/semantic-release/github) to publish a [GitHub release](https://github.com/chaijs/chai-http/releases).
- [`git`](https://github.com/semantic-release/git) to commit release assets.
- [`npm`](https://github.com/semantic-release/npm) to publish to [npm](https://www.npmjs.com/package/chai-http).

## License

(The MIT License)
Loading