From 0f06e001fb9bbb955d37cb3e0ebfc35976b0125f Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 2 Jun 2024 22:35:08 +0800 Subject: [PATCH] test: add chips test case (#19) https://github.com/eggjs/egg-cookies/pull/42 ## 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. --- .autod.conf.js | 21 ---------------- .github/ISSUE_TEMPLATE.md | 21 ---------------- .github/PULL_REQUEST_TEMPLATE.md | 24 ------------------ .github/workflows/node.yml | 17 +++++++++++++ .github/workflows/release.yml | 13 ++++++++++ .gitignore | 1 + .travis.yml | 16 ------------ README.md | 13 ++-------- package.json | 26 +++++++------------- test/app/middleware/session.test.js | 24 ++++++++++++++++++ test/fixtures/chips/app/controller/home.js | 10 ++++++++ test/fixtures/chips/app/router.js | 6 +++++ test/fixtures/chips/config/config.default.js | 9 +++++++ test/fixtures/chips/package.json | 3 +++ 14 files changed, 94 insertions(+), 110 deletions(-) delete mode 100644 .autod.conf.js delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/node.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml create mode 100644 test/fixtures/chips/app/controller/home.js create mode 100644 test/fixtures/chips/app/router.js create mode 100644 test/fixtures/chips/config/config.default.js create mode 100644 test/fixtures/chips/package.json diff --git a/.autod.conf.js b/.autod.conf.js deleted file mode 100644 index 07768d8..0000000 --- a/.autod.conf.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -module.exports = { - write: true, - prefix: '^', - test: [ - 'test', - 'benchmark', - ], - devdep: [ - 'egg-ci', - 'egg-bin', - 'autod', - 'eslint', - 'eslint-config-egg', - 'supertest', - ], - exclude: [ - './test/fixtures', - ], -} diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index b021f10..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,21 +0,0 @@ - - -* **Node Version**: -* **Egg Version**: -* **Plugin Name**: -* **Plugin Version**: -* **Platform**: - - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 48f9944..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,24 +0,0 @@ - - -##### Checklist - - -- [ ] `npm test` passes -- [ ] tests and/or benchmarks are included -- [ ] documentation is changed or added -- [ ] commit message follows commit guidelines - -##### Affected core subsystem(s) - - - -##### Description of change - diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml new file mode 100644 index 0000000..73ca141 --- /dev/null +++ b/.github/workflows/node.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a2bf04a --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 18fe46c..60753d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ coverage/ test/fixtures/**/run dump.rdb +package-lock.json diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 11cf92c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ - -language: node_js -node_js: - - '8' - - '10' - - '12' -before_install: - - npm i npminstall -g -install: - - npminstall -script: - - npm run ci -after_script: - - npminstall codecov && codecov -services: - - redis-server diff --git a/README.md b/README.md index bee5196..5e4f0d5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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. ``` diff --git a/package.json b/package.json index a30b7c5..19fcdf9 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } diff --git a/test/app/middleware/session.test.js b/test/app/middleware/session.test.js index 39042c7..18fb60b 100644 --- a/test/app/middleware/session.test.js +++ b/test/app/middleware/session.test.js @@ -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' }); diff --git a/test/fixtures/chips/app/controller/home.js b/test/fixtures/chips/app/controller/home.js new file mode 100644 index 0000000..8841cfc --- /dev/null +++ b/test/fixtures/chips/app/controller/home.js @@ -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; +}; diff --git a/test/fixtures/chips/app/router.js b/test/fixtures/chips/app/router.js new file mode 100644 index 0000000..7b32aa3 --- /dev/null +++ b/test/fixtures/chips/app/router.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = app => { + app.get('/get', 'home.get'); + app.get('/set', 'home.set'); +}; diff --git a/test/fixtures/chips/config/config.default.js b/test/fixtures/chips/config/config.default.js new file mode 100644 index 0000000..536d676 --- /dev/null +++ b/test/fixtures/chips/config/config.default.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.keys = 'keys'; +exports.session = { + partitioned: true, + removeUnpartitioned: true, +}; + +exports.proxy = true; diff --git a/test/fixtures/chips/package.json b/test/fixtures/chips/package.json new file mode 100644 index 0000000..da32cf7 --- /dev/null +++ b/test/fixtures/chips/package.json @@ -0,0 +1,3 @@ +{ + "name": "chips-session" +}