-
Notifications
You must be signed in to change notification settings - Fork 18
Feature postSetup ut #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4b1b3e5
fd0700a
716ac5a
a9e9a15
1215798
2968aff
d5598be
6268bdc
6f4038e
fb8285e
119221d
1a64071
ad17492
789b2ff
ba16a86
a3bf5bb
a8c7564
2d42286
fc5e72b
40d8cfd
fbeb618
5d9514b
43d0419
dabcf8c
14605eb
dde73ec
68c1217
8a757e6
8692104
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| module.exports = { | ||
| selectorLabel: 'class', | ||
| params: { | ||
| projects: { | ||
| '${projectName}': { | ||
| type: 'uri', | ||
| location: 'https://cn.bing.com/', | ||
| } | ||
| } | ||
| }, | ||
| lookupConfig({ | ||
| config, | ||
| tag | ||
| }) { | ||
| return config.params.projects[tag.project]; | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,309 @@ | ||
| const { | ||
| caseParams, | ||
| caseParamsSkipped, | ||
| query, | ||
| instance, | ||
| caseTitle, | ||
| contextParamExpected, | ||
| context, | ||
| argFn, | ||
| execCaseParamExpected | ||
| } = require('./postSetupTestData.js'); | ||
| const { setup, testPrepare } = require('../../../src/lifecycle/setup.js'); | ||
| const { | ||
| beforeEachStart, | ||
| afterEachEnd, | ||
| getExecCaseParams, | ||
| execCase, | ||
| testCase, | ||
| testOnly, | ||
| } = require('../../../src/lifecycle/postSetup'); | ||
|
|
||
|
|
||
| describe('postSetup unit test : beforeEachStart', () => { | ||
|
|
||
| it('beforeEachStart, before hook for each case should be called', async () => { | ||
| const mockFn = jest.fn(); | ||
|
|
||
| const result = await getExecCaseParams(context); | ||
| await beforeEachStart(result.context, mockFn); | ||
|
|
||
| expect(mockFn).toBeCalled(); | ||
| expect(JSON.stringify(mockFn.mock.calls[0][0])).toBe(JSON.stringify(contextParamExpected)); | ||
|
|
||
| }); | ||
| }), | ||
|
|
||
| describe('postSetup unit test : afterEachEnd', () => { | ||
| const hook1 = jest.fn(); | ||
| const hook2 = jest.fn(); | ||
| const close = jest.fn(); | ||
| const afterEachParam = { | ||
| driver: { | ||
| afterHooks: [ | ||
| hook1, | ||
| hook2 | ||
| ], | ||
| close | ||
| }, | ||
| options: { | ||
| isSandbox: true | ||
| }, | ||
| } | ||
| const afterEachFn = jest.fn(); | ||
|
|
||
| it('afterEachEnd, after hook for each case should be called and afterEachParam.driver.afterHooks should be called', async () => { | ||
|
|
||
| await afterEachEnd(afterEachParam, afterEachFn); | ||
|
|
||
| expect(afterEachFn).toBeCalled(); | ||
| expect(hook1).toBeCalled(); | ||
| expect(hook2).toBeCalled(); | ||
| }); | ||
|
|
||
| it('afterEachEnd, after hook for each case should be called and afterEachParam.driver.afterHooks should be called', async () => { | ||
| afterEachParam.options.isSandbox = true; | ||
|
|
||
| await afterEachEnd(afterEachParam, afterEachFn); | ||
| expect(close).toBeCalled(); | ||
| }); | ||
|
|
||
| it('afterEachEnd, when afterHooks arg is null', async () => { | ||
| afterEachParam.driver.afterHooks = null; | ||
|
|
||
| await afterEachEnd(afterEachParam, afterEachFn).catch(e => expect(String(e)).toMatch('TypeError: driver.afterHooks is not iterable')); | ||
|
|
||
| }); | ||
|
|
||
| }), | ||
|
|
||
| describe('postSetup unit test : getExecCaseParams', () => { | ||
|
|
||
| it(`getExecCaseParams, should return result`, async () => { | ||
|
lenaChenv marked this conversation as resolved.
|
||
|
|
||
| const result = await getExecCaseParams(context); | ||
|
|
||
| expect(result.caseTitle).toEqual(caseTitle); | ||
| expect(JSON.stringify(result.instance.query)).toEqual(JSON.stringify(query)); | ||
| expect(JSON.stringify(result.context)).toEqual(JSON.stringify(contextParamExpected)); | ||
| }); | ||
|
|
||
| it(`getExecCaseParams, when case tags don't include loginAccount`, async () => { | ||
| context.option = { loginAccount: 'loginAccount' }; | ||
| const caseTitleNoLoginAccount = `execute case => (google in levels-p3 & brands-rc & tags-salesforce & options-accounts & loginAccount-loginAccount on puppeteer)`; | ||
| contextParamExpected.options.option = context.option; | ||
|
|
||
| const result = await getExecCaseParams(context); | ||
|
|
||
| expect(result.caseTitle).toEqual(caseTitleNoLoginAccount); | ||
| expect(result.context.options.option).toEqual(context.option); | ||
| }); | ||
|
|
||
| it(`getExecCaseParams, when case tags don't include account`, async () => { | ||
| context.option = { accounts: ['account'] }; | ||
| const caseTitleNoAccounts = `execute case => (google in levels-p3 & brands-rc & tags-salesforce & options-accounts & accounts-account on puppeteer)`; | ||
|
|
||
| const result = await getExecCaseParams(context); | ||
|
|
||
| expect(result.caseTitle).toEqual(caseTitleNoAccounts); | ||
| expect(result.context.options.option).toEqual(context.option); | ||
| }); | ||
| }), | ||
|
|
||
| describe('postSetup unit test : execCase', () => { | ||
|
|
||
| it('execCase, verify the params of global and global.beforeEachStart should be called', async () => { | ||
|
|
||
| let result = await getExecCaseParams(context); | ||
|
|
||
| global.getExecCaseParams = jest.fn().mockReturnValue(result); | ||
|
|
||
| global.beforeEachStart = jest.fn(); | ||
|
|
||
| result.context.driver.run = jest.fn(); | ||
| result.context.driver.newPage = jest.fn(); | ||
| result.context.driver.goto = jest.fn(); | ||
|
|
||
| await execCase(context); | ||
|
|
||
| expect(JSON.stringify(global.$)).toEqual(JSON.stringify(result.instance.query)); | ||
| expect(global.__context__).toEqual(result.context); | ||
| expect(global.__beforeEachCase__).toEqual(result.beforeEachCase); | ||
| expect(global.__afterEachCase__).toEqual(result.afterEachCase); | ||
|
|
||
| expect(global.beforeEachStart).toBeCalled(); | ||
| expect(global.beforeEachStart).toHaveBeenCalledWith(result.context, result.beforeEachCase); | ||
|
|
||
| expect(result.context.driver.run).toBeCalled(); | ||
|
|
||
| }); | ||
|
|
||
| it('execCase, if test only should assign the params of global', async () => { | ||
|
|
||
| context.isOnly = true; | ||
|
|
||
| result = await getExecCaseParams(context); | ||
| global.getExecCaseParams = jest.fn().mockReturnValue(result); | ||
|
|
||
| global.beforeEachStart = jest.fn(); | ||
|
|
||
| result.context.driver.run = jest.fn(); | ||
| result.context.driver.newPage = jest.fn(); | ||
| result.context.driver.goto = jest.fn(); | ||
|
|
||
| await execCase(context); | ||
|
|
||
| expect(result.context.driver.run).toBeCalled(); | ||
| }); | ||
|
|
||
| it('execCase, if isUT is true context.driver.run should not be called', async () => { | ||
|
|
||
| context.driver = "ut"; | ||
|
|
||
| result = await getExecCaseParams(context); | ||
|
|
||
| global.getExecCaseParams = jest.fn().mockReturnValue(result); | ||
|
|
||
| global.beforeEachStart = jest.fn(); | ||
|
|
||
| result.context.driver.run = jest.fn(); | ||
| result.context.driver.newPage = jest.fn(); | ||
| result.context.driver.goto = jest.fn(); | ||
|
|
||
| await execCase(context); | ||
|
|
||
| expect(result.context.driver.run).not.toBeCalled(); | ||
|
|
||
| context.driver = "puppeteer"; | ||
|
|
||
| }); | ||
|
|
||
| it('execCase, verify the params of global and global.beforeEachStart should be called', async () => { | ||
|
|
||
| context.isHeadless = true; | ||
| context.isDebugger = true; | ||
| context.isVerbose = true; | ||
|
|
||
| result = await getExecCaseParams(context); | ||
|
|
||
| global.getExecCaseParams = jest.fn().mockReturnValue(result); | ||
|
|
||
| global.beforeEachStart = jest.fn(); | ||
|
|
||
| result.context.driver.run = jest.fn(); | ||
| result.context.driver.newPage = jest.fn(); | ||
| result.context.driver.goto = jest.fn(); | ||
|
|
||
| await execCase(context); | ||
|
|
||
| expect(result.context.driver.run).toBeCalled(); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
| it('execCase, if isSandbox is false context.driver.run should not be called', async () => { | ||
|
|
||
| context.isSandbox = false; | ||
|
|
||
| const result = await getExecCaseParams(context); | ||
|
|
||
| global.getExecCaseParams = jest.fn().mockReturnValue(result); | ||
|
|
||
| global.beforeEachStart = jest.fn(); | ||
|
|
||
| result.context.driver.run = jest.fn(); | ||
| result.context.driver.newPage = jest.fn(); | ||
| result.context.driver.goto = jest.fn(); | ||
|
|
||
| await execCase(context); | ||
|
|
||
| expect(result.context.driver.run).not.toBeCalled(); | ||
|
|
||
| }); | ||
|
|
||
| }), | ||
|
|
||
| describe('postSetup unit test : testCase', () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need test global.execDrivers include several drivers(puppeteer,chrome...),then check the number of calls to execCase. |
||
|
|
||
| it(`testCase, global.execCase should be called and the param is equal to ${execCaseParamExpected}`, async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are several global parameters(global.X) in the method that need to be overridden. |
||
|
|
||
| global.execCase = jest.fn(); | ||
| await testCase(caseParams, argFn); | ||
|
lenaChenv marked this conversation as resolved.
lenaChenv marked this conversation as resolved.
|
||
|
|
||
| expect(global.execCase).toBeCalled(); | ||
| expect(global.execCase).toHaveBeenCalledWith(execCaseParamExpected); | ||
| expect(global.execCase.mock.instances.length).toBe(6); | ||
| }); | ||
|
|
||
| it(`testCase, the param isOnly is true and global.execCase should be called `, async () => { | ||
|
|
||
| global.execCase = jest.fn(); | ||
| await testCase(caseParams, argFn, true); | ||
|
|
||
| expect(global.execCase).toBeCalled(); | ||
| expect(global.execCase.mock.calls[0][0].isOnly).toEqual(true); | ||
|
|
||
| }); | ||
|
|
||
| it(`testCase, when modes is not null and global.execCase should be called`, async () => { | ||
|
|
||
| global.execCase = jest.fn(); | ||
| caseParams.modes = ['headless']; | ||
|
|
||
| await testCase(caseParams, argFn); | ||
|
|
||
| expect(global.execCase).toBeCalled(); | ||
| expect(global.execCase.mock.calls[0][0].modes).toEqual([...caseParams.modes, ...global.execModes]); | ||
|
|
||
| }); | ||
|
|
||
| it(`testCase, when tags is [] and global.execCase should be called`, async () => { | ||
|
|
||
| global.execCase = jest.fn(); | ||
| caseParams.tags = []; | ||
|
|
||
| await testCase(caseParams, argFn); | ||
|
|
||
| expect(global.execCase).not.toBeCalled(); | ||
| }); | ||
|
|
||
| it(`testCase, when options is [{}] and global.execCase should be called`, async () => { | ||
|
|
||
| global.execCase = jest.fn(); | ||
| caseParams.options = [{}]; | ||
|
|
||
| await testCase(caseParams, argFn); | ||
|
|
||
| expect(global.execCase).not.toBeCalled(); | ||
| }); | ||
|
|
||
| it(`testCase, isSkiped is true and global.execCase should not be called`, async () => { | ||
|
|
||
| global.execCase = jest.fn(); | ||
| await testCase(caseParamsSkipped, argFn); | ||
|
|
||
| expect(global.execCase).not.toBeCalled(); | ||
|
|
||
| }); | ||
|
|
||
| }), | ||
|
|
||
| describe('postSetup unit test : testOnly', () => { | ||
|
|
||
| it(`testOnly, return global.testCase `, async () => { | ||
|
|
||
| const fn = jest.fn(); | ||
| global.test = jest.fn(); | ||
|
|
||
| const result = await testOnly(caseParams, fn); | ||
|
|
||
| expect(global.test).toBeCalled(); | ||
| expect(global.test.mock.calls[0][0]).toBe(caseParams); | ||
| expect(global.test.mock.calls[0][1]).toBe(fn); | ||
| expect(global.test.mock.calls[0][2]).toBe(true); | ||
| expect(result).toBe(global.test(caseParams, fn, true)); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.