Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
� Conflicts:
�	package.json
  • Loading branch information
mmarkelov committed Feb 29, 2020
2 parents 275c262 + 9c3fa21 commit 160d7e0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-playwright-preset",
"version": "0.0.11",
"version": "0.0.12",
"main": "index.js",
"description": "Running tests using Jest & Playwright.",
"license": "MIT",
Expand All @@ -17,6 +17,7 @@
"bin": {
"jest-playwright": "./lib/bin/index.js"
},
"types": "./types/global.d.ts",
"repository": {
"url": "https://github.com/mmarkelov/jest-playwright.git",
"type": "git"
Expand Down
19 changes: 15 additions & 4 deletions src/bin/testProcess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn, spawnSync, SpawnSyncOptions } from 'child_process'
import { readConfig } from '../utils'
import { checkBrowsers } from './utils'
import { checkBrowsers, getResultByStatus } from './utils'
import { PARALLEL, BrowserType } from '../constants'

const getSpawnOptions = (browser: BrowserType): SpawnSyncOptions => ({
Expand All @@ -21,12 +21,23 @@ const exec = ({
browser: BrowserType
params: string[]
}): void => {
// TODO Add messages for browser process
const options = getSpawnOptions(browser)
if (sequence === PARALLEL) {
spawn('node', [`node_modules/.bin/jest ${params}`], options)
const process = spawn(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
process.on('close', status => {
console.log(`${getResultByStatus(status)} tests for ${browser}\n\n`)
})
} else {
spawnSync('node', [`node_modules/.bin/jest ${params}`], options)
const { status } = spawnSync(
'node',
[`node_modules/jest/bin/jest.js ${params}`],
options,
)
console.log(`${getResultByStatus(status)} tests for ${browser}`)
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/bin/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkBrowsers } from './utils'
import { checkBrowsers, getResultByStatus } from './utils'
import { BrowserType } from '../constants'

describe('checkBrowsers', () => {
Expand All @@ -18,3 +18,17 @@ describe('checkBrowsers', () => {
).toThrow()
})
})

describe('getResultByStatus', () => {
it('should return "Failed" if passed null', () => {
expect(getResultByStatus(null)).toBe('Failed')
})

it('should return "Failed" if passed code 1', () => {
expect(getResultByStatus(1)).toBe('Failed')
})

it('should return "Passed" if passed code 0', () => {
expect(getResultByStatus(0)).toBe('Passed')
})
})
4 changes: 4 additions & 0 deletions src/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export const checkBrowsers = (browsers?: BrowserType[]): void => {
}
browsers.forEach(checkBrowserEnv)
}

export const getResultByStatus = (status: number | null): string => {
return status !== 0 ? 'Failed' : 'Passed'
}
10 changes: 7 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
"forceConsistentCasingInFileNames": true
},
"files": [
"types/global.d.ts",
"types/global.d.ts"
],
"include": [
"src/**/*",
"src/**/*"
],
}
"exclude": [
"node_modules",
"**/*.test.ts"
]
}

0 comments on commit 160d7e0

Please sign in to comment.