|
| 1 | +const { generateId, getServerlessSdk } = require('./utils') |
| 2 | +const execSync = require('child_process').execSync |
| 3 | +const path = require('path') |
| 4 | +const axios = require('axios') |
| 5 | + |
| 6 | +// set enough timeout for deployment to finish |
| 7 | +jest.setTimeout(300000) |
| 8 | + |
| 9 | +// the yaml file we're testing against |
| 10 | +const instanceYaml = { |
| 11 | + org: 'orgDemo', |
| 12 | + app: 'appDemo', |
| 13 | + component: 'koa@dev', |
| 14 | + name: `koa-integration-tests-${generateId()}`, |
| 15 | + stage: 'dev', |
| 16 | + inputs: { |
| 17 | + region: 'ap-guangzhou', |
| 18 | + runtime: 'Nodejs8.9', |
| 19 | + apigatewayConf: { environment: 'test' } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// get credentials from process.env but need to init empty credentials object |
| 24 | +const credentials = { |
| 25 | + tencent: {} |
| 26 | +} |
| 27 | + |
| 28 | +// get serverless construct sdk |
| 29 | +const sdk = getServerlessSdk(instanceYaml.org) |
| 30 | + |
| 31 | +it('should successfully deploy koa app', async () => { |
| 32 | + const instance = await sdk.deploy(instanceYaml, { tencent: {} }) |
| 33 | + expect(instance).toBeDefined() |
| 34 | + expect(instance.instanceName).toEqual(instanceYaml.name) |
| 35 | + // get src from template by default |
| 36 | + expect(instance.outputs.templateUrl).toBeDefined() |
| 37 | + expect(instance.outputs.region).toEqual(instanceYaml.inputs.region) |
| 38 | + expect(instance.outputs.scf).toBeDefined() |
| 39 | + expect(instance.outputs.scf.runtime).toEqual(instanceYaml.inputs.runtime) |
| 40 | + expect(instance.outputs.apigw).toBeDefined() |
| 41 | + expect(instance.outputs.apigw.environment).toEqual(instanceYaml.inputs.apigatewayConf.environment) |
| 42 | +}) |
| 43 | + |
| 44 | +it('should successfully update source code', async () => { |
| 45 | + // change source to own source './src' and need to install packages before deploy |
| 46 | + const srcPath = path.join(__dirname, 'src') |
| 47 | + execSync('npm install', { cwd: srcPath }) |
| 48 | + instanceYaml.inputs.src = srcPath |
| 49 | + |
| 50 | + const instance = await sdk.deploy(instanceYaml, credentials) |
| 51 | + const response = await axios.get(instance.outputs.apigw.url) |
| 52 | + |
| 53 | + expect(response.data).toEqual('Hello World') |
| 54 | + expect(instance.outputs.templateUrl).not.toBeDefined() |
| 55 | +}) |
| 56 | + |
| 57 | +it('should successfully remove koa app', async () => { |
| 58 | + await sdk.remove(instanceYaml, credentials) |
| 59 | + result = await sdk.getInstance(instanceYaml.org, instanceYaml.stage, instanceYaml.app, instanceYaml.name) |
| 60 | + |
| 61 | + expect(result.instance.instanceStatus).toEqual('inactive') |
| 62 | +}) |
0 commit comments