From 5a19783df50847f7fd008ec1b9a7a667a95f2d2d Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 4 Jan 2024 18:16:12 +0800 Subject: [PATCH] test: fix test case fail on Node.js 20 --- .github/workflows/codeql-analysis.yml | 2 - .github/workflows/nodejs.yml | 4 +- .github/workflows/release.yml | 6 +-- .../app/controller/home.js | 2 +- test/method_not_allow.test.js | 42 ++++--------------- 5 files changed, 10 insertions(+), 46 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e86d779..723cad6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,8 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ master ] - schedule: - - cron: '27 12 * * 1' jobs: analyze: diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 3687113..4b0c095 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -7,12 +7,10 @@ on: pull_request: branches: [ master ] - workflow_dispatch: {} - jobs: Job: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-test.yml@v1 + uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest, macos-latest, windows-latest' version: '14, 16, 18, 20' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1612587..a2bf04a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,14 +4,10 @@ on: push: branches: [ master ] - workflow_dispatch: {} - jobs: release: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-release.yml@v1 + uses: eggjs/github-actions/.github/workflows/node-release.yml@master secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - with: - checkTest: false diff --git a/test/fixtures/apps/csrf-cookieOptions-signed/app/controller/home.js b/test/fixtures/apps/csrf-cookieOptions-signed/app/controller/home.js index 37685ab..974a0a6 100644 --- a/test/fixtures/apps/csrf-cookieOptions-signed/app/controller/home.js +++ b/test/fixtures/apps/csrf-cookieOptions-signed/app/controller/home.js @@ -2,7 +2,7 @@ module.exports = app => { return class Home extends app.Controller { - * index() { + async index() { this.ctx.body = 'hello csrfToken cookieOptions signed'; } }; diff --git a/test/method_not_allow.test.js b/test/method_not_allow.test.js index d6140ff..f308570 100644 --- a/test/method_not_allow.test.js +++ b/test/method_not_allow.test.js @@ -1,6 +1,5 @@ 'use strict'; -const methods = require('methods'); const mm = require('egg-mock'); describe('test/method_not_allow.test.js', () => { @@ -17,40 +16,13 @@ describe('test/method_not_allow.test.js', () => { after(() => app.close()); - it('should allow', done => { - let count = 0, - exCount = 0, - keepgoing = true; - const exclude = [ 'trace', 'track' ]; - - const ms = methods.filter(m => { - return app[m]; - }); - - ms.forEach(method => { - if (!keepgoing) { - return; - } - if (exclude.indexOf(method) !== -1) { - ++exCount; - return; - } - - app.httpRequest()[method]('/') - .expect(200) - .end(err => { - if (err) { - keepgoing = false; - return done(err); - } - - ++count; - - if (count === ms.length - exCount) { - return done(); - } - }); - }); + it('should allow', async () => { + const methods = [ 'get', 'post', 'head', 'put', 'delete' ]; + for (const method of methods) { + console.log(method); + await app.httpRequest()[method]('/') + .expect(200); + } }); it('should not allow trace method', () => {