Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarkelov committed Mar 1, 2020
1 parent 7ae3376 commit 33e4d00
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/bin/testProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
readConfig,
readPackage,
} from '../utils'
import { checkCommand, getLogMessage } from './utils'
import { checkCommand, getExitCode, getLogMessage } from './utils'
import { BrowserType, CORE, PARALLEL, PLAYWRIGHT } from '../constants'

const getSpawnOptions = (
Expand Down Expand Up @@ -57,6 +57,7 @@ const exec = ({

const runner = async (sequence: string, params: string[]): Promise<void> => {
const { browsers = [], devices = [] } = await readConfig()
let exitCodes: (number | null)[] = []
checkCommand(browsers, devices)
if (!browsers.length && devices.length) {
let browserType: BrowserType
Expand All @@ -68,19 +69,29 @@ const runner = async (sequence: string, params: string[]): Promise<void> => {
} else {
browserType = browser
}
devices.forEach(device =>
exec({ sequence, browser: browserType, device, params }),
exitCodes = await Promise.all(
devices.map(device =>
exec({ sequence, browser: browserType, device, params }),
),
)
}
if (browsers.length) {
if (devices.length) {
browsers.forEach(browser =>
devices.forEach(device => exec({ sequence, browser, device, params })),
const multipleCodes = await Promise.all(
browsers.map(browser =>
Promise.all(
devices.map(device => exec({ sequence, browser, device, params })),
),
),
)
exitCodes = multipleCodes.reduce((acc, val) => acc.concat(val), [])
} else {
browsers.forEach(browser => exec({ sequence, browser, params }))
exitCodes = await Promise.all(
browsers.map(browser => exec({ sequence, browser, params })),
)
}
}
getExitCode(exitCodes)
}

export default runner
23 changes: 22 additions & 1 deletion src/bin/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { checkCommand, getResultByStatus, getLogMessage } from './utils'
import {
checkCommand,
getResultByStatus,
getLogMessage,
getExitCode,
} from './utils'
import { BrowserType } from '../constants'

describe('checkCommand', () => {
Expand Down Expand Up @@ -40,3 +45,19 @@ describe('getLogMessage', () => {
)
})
})

describe('getExitCode', () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
return undefined as never
})

it('should exit with code 1 for some failed tests', () => {
getExitCode([0, 0, 1, null])
expect(mockExit).toHaveBeenCalledWith(1)
})

it('should exit with code 0 for passed tests', () => {
getExitCode([0, 0, 0, 0])
expect(mockExit).toHaveBeenCalledWith(0)
})
})
9 changes: 9 additions & 0 deletions src/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ export const getLogMessage = (
device ? `and device: ${device}` : ''
}\n\n`
}

export const getExitCode = (exitCodes: (number | null)[]): void => {
if (exitCodes.every(code => code === 0)) {
process.exit(0)
} else {
console.log('One of the test has not passed successfully')
process.exit(1)
}
}

0 comments on commit 33e4d00

Please sign in to comment.