Skip to content

Commit 838db39

Browse files
committed
fix: fix tests #5
Signed-off-by: seven <zilisheng1996@gmail.com>
1 parent b0a8e38 commit 838db39

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ module.exports = {
44
testEnvironment: 'node',
55
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
66
};
7+
8+
process.env.ROS_REGION_ID = 'cn-hangzhou';
9+
process.env.ALIYUN_ACCESS_KEY_ID = 'access key id';
10+
process.env.ALIYUN_ACCESS_KEY_SECRET = 'access key secret';
11+
process.env.ALIYUN_SECURITY_TOKEN = 'account id';

tests/commands/deploy.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { deploy } from '../../src/commands/deploy';
2+
import { defaultContext } from '../fixtures/deployFixture';
23

34
const mockedDeployStack = jest.fn();
45
jest.mock('../../src/stack', () => ({
@@ -9,18 +10,10 @@ jest.mock('../../src/stack', () => ({
910
describe('unit test for deploy command', () => {
1011
it('should construct valid context and deploy the stack when deploy with valid iac', async () => {
1112
const stackName = 'my-demo-stack';
13+
1214
await deploy(stackName, { location: 'tests/fixtures/serverless-insight.yml', parameters: {} });
15+
1316
expect(mockedDeployStack).toHaveBeenCalledTimes(1);
14-
expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), {
15-
accessKeyId: undefined,
16-
accessKeySecret: undefined,
17-
iacLocation:
18-
'/Users/blank/Documents/dev/geekfun/serverlessinsight/tests/fixtures/serverless-insight.yml',
19-
parameters: [],
20-
region: 'cn-hangzhou',
21-
securityToken: undefined,
22-
stackName: 'my-demo-stack',
23-
stage: 'default',
24-
});
17+
expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), defaultContext);
2518
});
2619
});

tests/fixtures/deployFixture.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ export const oneFcRos = {
213213
},
214214
},
215215
};
216+
217+
export const defaultContext = {
218+
accessKeyId: 'access key id',
219+
accessKeySecret: 'access key secret',
220+
iacLocation: expect.stringContaining('tests/fixtures/serverless-insight.yml'),
221+
parameters: [],
222+
region: 'cn-hangzhou',
223+
securityToken: 'account id',
224+
stackName: 'my-demo-stack',
225+
stage: 'default',
226+
};

0 commit comments

Comments
 (0)