Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
Expand Down
15 changes: 4 additions & 11 deletions tests/integration.test.js → __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
require('dotenv').config()
const { generateId, getServerlessSdk } = require('./utils')
const { generateId, getServerlessSdk } = require('./lib/utils')
const execSync = require('child_process').execSync
const path = require('path')
const axios = require('axios')

// set enough timeout for deployment to finish
jest.setTimeout(300000)

// the yaml file we're testing against
const instanceYaml = {
org: 'orgDemo',
app: 'appDemo',
component: 'koa',
component: 'koa@dev',
name: `koa-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {
Expand All @@ -21,7 +16,6 @@ const instanceYaml = {
}
}

// get credentials from process.env
const credentials = {
tencent: {
SecretId: process.env.TENCENT_SECRET_ID,
Expand All @@ -46,15 +40,14 @@ it('should successfully deploy koa app', async () => {
})

it('should successfully update source code', async () => {
// change source to own source './src' and need to install packages before deploy
const srcPath = path.join(__dirname, 'src')
const srcPath = path.join(__dirname, '..', 'example')
execSync('npm install', { cwd: srcPath })
instanceYaml.inputs.src = srcPath

const instance = await sdk.deploy(instanceYaml, credentials)
const response = await axios.get(instance.outputs.apigw.url)

expect(response.data).toEqual('Hello World')
expect(response.data).toContain('Serverless Framework')
expect(instance.outputs.templateUrl).not.toBeDefined()
})

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inputs:
| functionName | 否 | | 云函数名称 |
| serviceName | 否 | | API 网关服务名称, 默认创建一个新的服务名称 |
| serviceId | 否 | | API 网关服务 ID,如果存在将使用这个 API 网关服务 |
| entryFile | | `sls.js` | 自定义 server 的入口文件名 |
| entryFile | | `sls.js` | 自定义 server 的入口文件名 |
| src | 否 | `process.cwd()` | 默认为当前目录, 如果是对象, 配置参数参考 [执行目录](#执行目录) |
| layers | 否 | | 云函数绑定的 layer, 配置参数参考 [层配置](#层配置) |
| [functionConf](#函数配置) | 否 | | 函数配置 |
Expand Down
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"access": "public"
},
"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 .",
Expand Down
2 changes: 1 addition & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: koa
version: 0.2.0
version: 0.2.1
author: 'Tencent Cloud, Inc.'
org: 'Tencent Cloud, Inc.'
description: Deploy a serverless Koa.js application onto Tencent SCF and API Gateway.
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"download": "^8.0.0",
"tencent-component-toolkit": "^1.16.8",
"tencent-component-toolkit": "^1.19.8",
"type": "^2.1.0"
}
}
27 changes: 18 additions & 9 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,33 @@ class ServerlessComponent extends Component {
outputs.templateUrl = CONFIGS.templateUrl
}

const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
let apigwOutputs
const functionOutputs = await this.deployFunction(
credentials,
functionConf,
regionList,
outputs
)
// support apigatewayConf.isDisabled
if (apigatewayConf.isDisabled !== true) {
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
apigwOutputs = await this.deployApigateway(credentials, apigatewayConf, regionList, outputs)
} else {
this.state.apigwDisabled = true
}
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)

// optimize outputs for one region
if (regionList.length === 1) {
const [oneRegion] = regionList
outputs.region = oneRegion
outputs['apigw'] = apigwOutputs[oneRegion]
outputs['scf'] = functionOutputs[oneRegion]
if (apigwOutputs) {
outputs['apigw'] = apigwOutputs[oneRegion]
}
} else {
outputs['apigw'] = apigwOutputs
outputs['scf'] = functionOutputs
if (apigwOutputs) {
outputs['apigw'] = apigwOutputs
}
}

this.state.region = regionList[0]
Expand All @@ -226,10 +235,6 @@ class ServerlessComponent 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({
Expand All @@ -240,6 +245,10 @@ class ServerlessComponent extends Component {
customDomains: curState.customDomains
})
}
await scf.remove({
functionName: curState.functionName,
namespace: curState.namespace
})
}
removeHandlers.push(handler())
}
Expand Down
14 changes: 0 additions & 14 deletions tests/src/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions tests/src/sls.js

This file was deleted.