|
| 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(600000) |
| 8 | + |
| 9 | +// the yaml file we're testing against |
| 10 | +const instanceYaml = { |
| 11 | + org: 'orgDemo', |
| 12 | + app: 'appDemo', |
| 13 | + component: 'nuxtjs', |
| 14 | + name: `nuxtjs-integration-tests-${generateId()}`, |
| 15 | + stage: 'dev', |
| 16 | + inputs: { |
| 17 | + region: 'ap-guangzhou', |
| 18 | + runtime: 'Nodejs10.15', |
| 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 nuxtjs app', async () => { |
| 32 | + const instance = await sdk.deploy(instanceYaml, { tencent: {} }) |
| 33 | + |
| 34 | + expect(instance).toBeDefined() |
| 35 | + expect(instance.instanceName).toEqual(instanceYaml.name) |
| 36 | + expect(instance.outputs).toBeDefined() |
| 37 | + // get src from template by default |
| 38 | + expect(instance.outputs.templateUrl).toBeDefined() |
| 39 | + expect(instance.outputs.region).toEqual(instanceYaml.inputs.region) |
| 40 | + expect(instance.outputs.scf).toBeDefined() |
| 41 | + expect(instance.outputs.scf.runtime).toEqual(instanceYaml.inputs.runtime) |
| 42 | + expect(instance.outputs.apigw).toBeDefined() |
| 43 | + expect(instance.outputs.apigw.environment).toEqual(instanceYaml.inputs.apigatewayConf.environment) |
| 44 | + |
| 45 | + const response = await axios.get(instance.outputs.apigw.url) |
| 46 | + expect(response.data.includes('Nuxt.js')).toBeTruthy() |
| 47 | +}) |
| 48 | + |
| 49 | +it('should successfully remove nuxtjs app', async () => { |
| 50 | + await sdk.remove(instanceYaml, credentials) |
| 51 | + result = await sdk.getInstance(instanceYaml.org, instanceYaml.stage, instanceYaml.app, instanceYaml.name) |
| 52 | + |
| 53 | + expect(result.instance.instanceStatus).toEqual('inactive') |
| 54 | +}) |
0 commit comments