Skip to content

Commit

Permalink
test: add chips test case (#19)
Browse files Browse the repository at this point in the history
eggjs/egg-cookies#42

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
  - Introduced CI workflow for Node.js projects.
  - Added GitHub Actions workflow for releasing Node.js applications.

- **Documentation**
- Updated README: Removed build status, dependencies, and
vulnerabilities badges. Improved installation command and added syntax
highlighting for code snippets.

- **Chores**
  - Added `package-lock.json` to `.gitignore`.
  - Updated devDependencies and scripts in `package.json`.

- **Tests**
  - Added new test case for "chips" functionality.
- Added new files and configurations for session handling in test
fixtures.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Jun 2, 2024
1 parent 374f6e2 commit 0f06e00
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 110 deletions.
21 changes: 0 additions & 21 deletions .autod.conf.js

This file was deleted.

21 changes: 0 additions & 21 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test-mysql.yml@master
with:
os: 'ubuntu-latest'
version: '14, 16, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
coverage/
test/fixtures/**/run
dump.rdb
package-lock.json
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# egg-session

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-session.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-session
[travis-image]: https://img.shields.io/travis/eggjs/egg-session.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-session
[codecov-image]: https://codecov.io/github/eggjs/egg-session/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-session?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-session.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-session
[snyk-image]: https://snyk.io/test/npm/egg-session/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-session
[download-image]: https://img.shields.io/npm/dm/egg-session.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-session

Expand All @@ -25,7 +16,7 @@ Session plugin for egg, based on [koa-session](https://github.com/koajs/session)
## Install

```bash
$ npm i egg-session --save
npm i egg-session --save
```

## Usage
Expand Down Expand Up @@ -115,7 +106,7 @@ Support all configurations in [koa-session](https://github.com/koajs/session).

* logValue

```
```bash
Support not to print the session value when session event trigger log. Default to be true.
```

Expand Down
26 changes: 9 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
"koa-session": "^6.0.0"
},
"devDependencies": {
"autod": "^2.10.1",
"egg": "next",
"egg-bin": "^4.3.5",
"egg-ci": "^1.8.0",
"egg-mock": "^3.13.1",
"egg": "^3.17.5",
"egg-bin": "6",
"egg-mock": "5",
"egg-redis": "^1.0.1",
"eslint": "^4.10.0",
"eslint-config-egg": "^5.1.1",
"eslint": "8",
"eslint-config-egg": "12",
"mz-modules": "^2.0.0",
"supertest": "^3.0.0"
},
Expand All @@ -41,16 +39,10 @@
},
"scripts": {
"lint": "eslint .",
"test": "npm run lint -- --fix && egg-bin test",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "8, 10, 12",
"services": "redis-server",
"type": "travis"
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test --ts false",
"cov": "egg-bin cov --ts false",
"ci": "npm run lint && npm run cov"
},
"author": "dead_horse"
}
24 changes: 24 additions & 0 deletions test/app/middleware/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ describe('test/app/middlewares/session.test.js', () => {
});
});

describe('chips', () => {
before(() => {
app = mm.app({ baseDir: 'chips' });
return app.ready();
});
beforeEach(() => {
agent = request.agent(app.callback());
});
after(() => app.close());

it('should work with chips', async () => {
await agent
.get('/set?foo=bar')
.set('user-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.4044.138 Safari/537.36')
.set('x-forwarded-proto', 'https')
.expect(200)
.expect({ foo: 'bar' })
.expect(res => {
const cookies = res.headers['set-cookie'];
console.log(cookies);
});
});
});

describe('logValue', () => {
before(() => {
app = mm.app({ baseDir: 'logValue-false-session' });
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/chips/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

exports.get = async ctx => {
ctx.body = ctx.session;
};

exports.set = async ctx => {
ctx.session = ctx.query;
ctx.body = ctx.session;
};
6 changes: 6 additions & 0 deletions test/fixtures/chips/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = app => {
app.get('/get', 'home.get');
app.get('/set', 'home.set');
};
9 changes: 9 additions & 0 deletions test/fixtures/chips/config/config.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

exports.keys = 'keys';
exports.session = {
partitioned: true,
removeUnpartitioned: true,
};

exports.proxy = true;
3 changes: 3 additions & 0 deletions test/fixtures/chips/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "chips-session"
}

0 comments on commit 0f06e00

Please sign in to comment.