@mands/nx-playwright
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "@mands/nx-playwright", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
# @mands/nx-playwright | ||
[![MIT License](https://img.shields.io/github/license/marksandspencer/nx-plugins)](https://github.com/marksandspencer/nx-plugins/blob/main/LICENSE.md) | ||
[![MIT License](https://img.shields.io/github/license/marksandspencer/nx-plugins)](https://github.com/marksandspencer/nx-plugins/blob/main/LICENSE.md) ![Build](https://github.com/marksandspencer/nx-plugins/actions/workflows/release.yml/badge.svg) [![npm version](https://badge.fury.io/js/@mands%2Fnx-playwright.svg)](https://badge.fury.io/js/@mands%2Fnx-playwright) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/marksandspencer/nx-plugins/blob/main/CONTRIBUTING.md) | ||
@@ -5,0 +5,0 @@ An [Nx plugin](https://nx.dev/packages/nx-plugin) to add support to an Nx monorepo for |
@@ -12,3 +12,7 @@ "use strict"; | ||
.then(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { stdout, stderr } = yield (0, util_1.promisify)(child_process_1.exec)(`yarn playwright test src --config ${options.e2eFolder}/playwright.config.ts`); | ||
var _a, _b; | ||
const headedOption = options.headed === true ? '--headed' : ''; | ||
const browserOption = ((_a = options.browser) === null || _a === void 0 ? void 0 : _a.length) ? `--browser=${options.browser}` : ''; | ||
const reporterOption = ((_b = options.reporter) === null || _b === void 0 ? void 0 : _b.length) ? `--reporter=${options.reporter}` : ''; | ||
const { stdout, stderr } = yield (0, util_1.promisify)(child_process_1.exec)(`yarn playwright test src --config ${options.e2eFolder}/playwright.config.ts ${headedOption} ${browserOption} ${reporterOption}`); | ||
console.info(`Playwright output ${stdout}`); | ||
@@ -15,0 +19,0 @@ if (stderr) { |
import * as utilModule from 'util'; | ||
import executor from './executor'; | ||
import * as startDevServerModule from './lib/start-dev-server'; | ||
import { PlaywrightExecutorSchema } from './schema'; | ||
@@ -17,6 +18,2 @@ const startDevServer = jest | ||
const options = { | ||
e2eFolder: 'folder', | ||
}; | ||
console.error = jest.fn().mockReturnValue(null); | ||
@@ -28,45 +25,71 @@ console.info = jest.fn().mockReturnValue(null); | ||
it('returns true when passes', async () => { | ||
promisify.mockReturnValueOnce( | ||
jest.fn().mockResolvedValueOnce({ stdout: 'passed', stderr: '' }), | ||
); | ||
describe('with cli opts', () => { | ||
const options: PlaywrightExecutorSchema = { | ||
e2eFolder: 'folder', | ||
headed: true, | ||
browser: 'firefox', | ||
reporter: 'html', | ||
}; | ||
const { success } = await executor(options, context); | ||
it('concatenates overriding options to playwright command', async () => { | ||
const execCmd = jest.fn().mockResolvedValueOnce({ stdout: 'passed', stderr: '' }); | ||
promisify.mockReturnValueOnce(execCmd); | ||
expect(success).toBe(true); | ||
await executor(options, context); | ||
expect(console.error).not.toHaveBeenCalled(); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledWith('Playwright output passed'); | ||
expect(startDevServer).toHaveBeenCalledTimes(1); | ||
expect(startDevServer).toHaveBeenCalledWith(options, context); | ||
const expected = | ||
'yarn playwright test src --config folder/playwright.config.ts --headed --browser=firefox --reporter=html'; | ||
expect(execCmd).toHaveBeenCalledWith(expected); | ||
}); | ||
}); | ||
it('logs error from output', async () => { | ||
promisify.mockReturnValueOnce( | ||
jest.fn().mockResolvedValueOnce({ stdout: 'passed', stderr: 'some error' }), | ||
); | ||
describe('playwright execution', () => { | ||
const options: PlaywrightExecutorSchema = { | ||
e2eFolder: 'folder', | ||
}; | ||
const { success } = await executor(options, context); | ||
it('returns true when passes', async () => { | ||
promisify.mockReturnValueOnce( | ||
jest.fn().mockResolvedValueOnce({ stdout: 'passed', stderr: '' }), | ||
); | ||
expect(success).toBe(true); | ||
const { success } = await executor(options, context); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledWith('Playwright errors some error'); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledWith('Playwright output passed'); | ||
}); | ||
expect(success).toBe(true); | ||
it('fails gracefully when command fails', async () => { | ||
const error = new Error('fake error'); | ||
promisify.mockReturnValueOnce(jest.fn().mockRejectedValueOnce(error)); | ||
expect(console.error).not.toHaveBeenCalled(); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledWith('Playwright output passed'); | ||
const { success } = await executor(options, context); | ||
expect(startDevServer).toHaveBeenCalledTimes(1); | ||
expect(startDevServer).toHaveBeenCalledWith(options, context); | ||
}); | ||
expect(success).toBe(false); | ||
it('logs error from output', async () => { | ||
promisify.mockReturnValueOnce( | ||
jest.fn().mockResolvedValueOnce({ stdout: 'passed', stderr: 'some error' }), | ||
); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledWith('Unexpected error', error); | ||
const { success } = await executor(options, context); | ||
expect(success).toBe(true); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledWith('Playwright errors some error'); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledWith('Playwright output passed'); | ||
}); | ||
it('fails gracefully when command fails', async () => { | ||
const error = new Error('fake error'); | ||
promisify.mockReturnValueOnce(jest.fn().mockRejectedValueOnce(error)); | ||
const { success } = await executor(options, context); | ||
expect(success).toBe(false); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledWith('Unexpected error', error); | ||
}); | ||
}); | ||
}); |
@@ -7,6 +7,7 @@ export interface PlaywrightExecutorSchema { | ||
devtools?: boolean; | ||
headless?: boolean; | ||
browsers?: ('chromium' | 'firefox' | 'webkit')[]; | ||
headed?: boolean; | ||
reporter?: string; | ||
browser?: 'chromium' | 'firefox' | 'webkit' | 'all'; | ||
timeout?: number; | ||
skipServe?: boolean; | ||
} |
@@ -7,3 +7,20 @@ { | ||
"type": "object", | ||
"properties": {} | ||
"properties": { | ||
"headed": { | ||
"type": "boolean", | ||
"description": "whether to show the browser head" | ||
}, | ||
"reporter": { | ||
"type": "string", | ||
"description": "type of output reporter" | ||
}, | ||
"browser": { | ||
"enum": ["all", "chromium", "firefox", "webkit"], | ||
"description": "run on specific browser (all for all)" | ||
}, | ||
"skipServe ": { | ||
"type": "boolean", | ||
"description": "whether to skip starting the server" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35515
651