Skip to content
Closed
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"access": "public"
},
"scripts": {
"test": "npm run lint && npm run prettier",
"int-test": "jest ./tests/integration.test.js --testEnvironment node",
"test": "npm run lint && npm run prettier && npm run int-test",
"commitlint": "commitlint -f HEAD@{15}",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
Expand Down Expand Up @@ -44,13 +45,15 @@
"@semantic-release/git": "^9.0.0",
"@semantic-release/npm": "^7.0.4",
"@semantic-release/release-notes-generator": "^9.0.1",
"@serverless/platform-client-china": "^1.0.19",
"babel-eslint": "^10.1.0",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.2.3",
"jest": "^25.0.1",
"lint-staged": "^10.0.8",
"prettier": "^1.19.1",
"semantic-release": "^17.0.4"
Expand Down
42 changes: 42 additions & 0 deletions tests/integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { generateId, getServerlessSdk } = require('./utils')

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

// the yaml file we're testing against
const instanceYaml = {
org: 'orgDemo',
app: 'appDemo',
component: 'website@dev',
name: `website-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {
src: './example',
bucketName: 'my-bucket',
region: 'ap-guangzhou'
}
}

// get credentials from process.env but need to init empty credentials object
const credentials = {
tencent: {}
}

// get serverless construct sdk
const sdk = getServerlessSdk(instanceYaml.org)

it('should successfully deploy website app', async () => {
const instance = await sdk.deploy(instanceYaml, { tencent: {} })

expect(instance).toBeDefined()
expect(instance.instanceName).toEqual(instanceYaml.name)
expect(instance.outputs.website).toBeDefined()
expect(instance.outputs.region).toEqual(instanceYaml.inputs.region)
})

it('should successfully remove website app', async () => {
await sdk.remove(instanceYaml, credentials)
result = await sdk.getInstance(instanceYaml.org, instanceYaml.stage, instanceYaml.app, instanceYaml.name)

expect(result.instance.instanceStatus).toEqual('inactive')
})
24 changes: 24 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { ServerlessSDK } = require('@serverless/platform-client-china')

/*
* Generate random id
*/
const generateId = () =>
Math.random()
.toString(36)
.substring(6)

/*
* Initializes and returns an instance of the serverless sdk
* @param ${string} orgName - the serverless org name.
*/
const getServerlessSdk = (orgName) => {
const sdk = new ServerlessSDK({
context: {
orgName
}
})
return sdk
}

module.exports = { generateId, getServerlessSdk }