From a34360709ee03c35027a349956a7ed59b56464ed Mon Sep 17 00:00:00 2001 From: Yuga Sun Date: Mon, 21 Dec 2020 10:41:52 +0800 Subject: [PATCH] fix: update remove flow (#18) * fix: update remove flow * ci: update config * fix: update deps * test: update --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 2 +- .../integration.test.js => __tests__/index.test.js | 14 ++------------ {tests => __tests__/lib}/utils.js | 0 jest.config.js | 14 ++++++++++++++ package.json | 2 +- serverless.component.yml | 2 +- src/package.json | 2 +- src/serverless.js | 8 ++++---- 9 files changed, 26 insertions(+), 22 deletions(-) rename tests/integration.test.js => __tests__/index.test.js (79%) rename {tests => __tests__/lib}/utils.js (100%) create mode 100644 jest.config.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c476a4..11c8ac8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} GIT_AUTHOR_NAME: slsplus - GIT_AUTHOR_EMAIL: yuga.sun.bj@gmail.com + GIT_AUTHOR_EMAIL: slsplus.sz@gmail.com GIT_COMMITTER_NAME: slsplus - GIT_COMMITTER_EMAIL: yuga.sun.bj@gmail.com + GIT_COMMITTER_EMAIL: slsplus.sz@gmail.com diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26cf7e2..c966e94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: run: | npm update --no-save npm update --save-dev --no-save - - name: Running integration tests + - name: Running tests run: npm run test env: SERVERLESS_PLATFORM_VENDOR: tencent diff --git a/tests/integration.test.js b/__tests__/index.test.js similarity index 79% rename from tests/integration.test.js rename to __tests__/index.test.js index 7e2c18c..1028de8 100644 --- a/tests/integration.test.js +++ b/__tests__/index.test.js @@ -1,18 +1,10 @@ -const path = require('path') -require('dotenv').config({ - path: path.join(__dirname, '..', '.env.test') -}) -const { generateId, getServerlessSdk } = require('./utils') +const { generateId, getServerlessSdk } = require('./lib/utils') const axios = require('axios') -// set enough timeout for deployment to finish -jest.setTimeout(600000) - -// the yaml file we're testing against const instanceYaml = { org: 'orgDemo', app: 'appDemo', - component: 'nextjs', + component: 'nextjs@dev', name: `nextjs-integration-tests-${generateId()}`, stage: 'dev', inputs: { @@ -22,7 +14,6 @@ const instanceYaml = { } } -// get credentials from process.env but need to init empty credentials object const credentials = { tencent: { SecretId: process.env.TENCENT_SECRET_ID, @@ -30,7 +21,6 @@ const credentials = { } } -// get serverless construct sdk const sdk = getServerlessSdk(instanceYaml.org) it('should successfully deploy nextjs app', async () => { diff --git a/tests/utils.js b/__tests__/lib/utils.js similarity index 100% rename from tests/utils.js rename to __tests__/lib/utils.js diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..a70dd57 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,14 @@ +const { join } = require('path') +require('dotenv').config({ path: join(__dirname, '.env.test') }) + +const config = { + verbose: true, + silent: false, + testTimeout: 600000, + testEnvironment: 'node', + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$', + testPathIgnorePatterns: ['/node_modules/', '/__tests__/lib/'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] +} + +module.exports = config diff --git a/package.json b/package.json index 90a1bb7..63efc80 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "description": "Tencent Cloud Next.js Serverless Component", "scripts": { - "test": "jest ./tests/integration.test.js --testEnvironment node", + "test": "jest", "commitlint": "commitlint -f HEAD@{15}", "lint": "eslint --ext .js,.ts,.tsx .", "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", diff --git a/serverless.component.yml b/serverless.component.yml index d38fee0..6266112 100644 --- a/serverless.component.yml +++ b/serverless.component.yml @@ -1,5 +1,5 @@ name: nextjs -version: 0.1.9 +version: 0.1.10 author: 'Tencent Cloud, Inc.' org: 'Tencent Cloud, Inc.' description: Deploy a serverless Next.js application onto Tencent SCF and API Gateway. diff --git a/src/package.json b/src/package.json index d0f8567..068b570 100644 --- a/src/package.json +++ b/src/package.json @@ -2,7 +2,7 @@ "dependencies": { "adm-zip": "^0.4.16", "download": "^8.0.0", - "tencent-component-toolkit": "^1.19.8", + "tencent-component-toolkit": "^1.20.5", "type": "^2.1.0" } } diff --git a/src/serverless.js b/src/serverless.js index b9ba1ab..9378242 100644 --- a/src/serverless.js +++ b/src/serverless.js @@ -358,10 +358,6 @@ class ServerlessComopnent extends Component { const scf = new Scf(credentials, curRegion) const apigw = new Apigw(credentials, curRegion) const handler = async () => { - await scf.remove({ - functionName: curState.functionName, - namespace: curState.namespace - }) // if disable apigw, no need to remove if (state.apigwDisabled !== true) { await apigw.remove({ @@ -372,6 +368,10 @@ class ServerlessComopnent extends Component { customDomains: curState.customDomains }) } + await scf.remove({ + functionName: curState.functionName, + namespace: curState.namespace + }) } removeHandlers.push(handler()) }