-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added worldConfig to QuickPickleConfig, for config passed to World constructor chore: added vitest config to root for playwright workspace fix: added re-export of QuickPickleWorld and QuickPickleWorldInterface types feat: World constructor classes can now accept three params for the constructor: 1. context: the vitest test context 2. info: the gherkin info for the step 3. config: the worldConfig object of QuickPickleConfig
- Loading branch information
Showing
21 changed files
with
511 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"quickpickle": minor | ||
"@quickpickle/playwright": patch | ||
--- | ||
|
||
Release playwright extension, and many fixes to make it work. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "@quickpickle/playwright", | ||
"version": "0.9.0", | ||
"description": "Support files for running tests with Playwright using QuickPickle (Gherkin in Vitest).", | ||
"keywords": [ | ||
"BDD", | ||
"testing", | ||
"behavioral", | ||
"cucumber", | ||
"gherkin", | ||
"vitest", | ||
"playwright", | ||
"react", | ||
"svelte", | ||
"vue", | ||
"angular" | ||
], | ||
"homepage": "https://github.com/dnotes/quickpickle#readme", | ||
"bugs": { | ||
"url": "https://github.com/dnotes/quickpickle/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dnotes/quickpickle.git" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "./dist/PlaywrightWorld.cjs", | ||
"module": "./dist/PlaywrightWorld.esm.js", | ||
"types": "./dist/PlaywrightWorld.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/world.cjs", | ||
"import": "./dist/world.esm.js", | ||
"types": "./dist/world.d.ts" | ||
}, | ||
"./actions": { | ||
"require": "./dist/actions.steps.cjs", | ||
"import": "./dist/actions.steps.esm.js", | ||
"types": "./dist/actions.steps.d.ts" | ||
}, | ||
"./outcomes": { | ||
"require": "./dist/outcomes.steps.cjs", | ||
"import": "./dist/outcomes.steps.esm.js", | ||
"types": "./dist/outcomes.steps.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "rollup -c", | ||
"type-check": "tsc --noEmit", | ||
"test:watch": "vitest", | ||
"test": "vitest --run" | ||
}, | ||
"author": "David Hunt", | ||
"dependencies": { | ||
"@playwright/test": "^1.48.0", | ||
"lodash-es": "^4.17.21", | ||
"playwright": "^1.48.0", | ||
"quickpickle": "workspace:^", | ||
"vite": "^5.0.11" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-replace": "^6.0.1", | ||
"@rollup/plugin-typescript": "^12.1.0", | ||
"@types/lodash-es": "^4.17.12", | ||
"fast-glob": "^3.3.2", | ||
"rollup": "^3.20.7", | ||
"typescript": "^5.6.2", | ||
"vitest": "^2.1.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import replace from '@rollup/plugin-replace'; | ||
import glob from 'fast-glob'; | ||
import path from 'node:path'; | ||
|
||
const input = Object.fromEntries( | ||
glob.sync('src/**/*.ts').map(file => [ | ||
// This will remove `src/` from the beginning and `.ts` from the end | ||
path.relative('src', file.slice(0, -3)), | ||
file | ||
]) | ||
); | ||
|
||
export default { | ||
input, | ||
output: [ | ||
{ | ||
dir: 'dist', | ||
format: 'cjs', | ||
sourcemap: true, | ||
exports: 'named', | ||
entryFileNames: '[name].cjs' | ||
}, | ||
{ | ||
dir: 'dist', | ||
format: 'esm', | ||
sourcemap: true, | ||
exports: 'named', | ||
entryFileNames: '[name].esm.js' | ||
} | ||
], | ||
plugins: [ | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
'import.meta?.env?.MODE': JSON.stringify('production'), | ||
'process?.env?.NODE_ENV': JSON.stringify('production'), | ||
} | ||
}), | ||
typescript({ | ||
tsconfig: './tsconfig.json', | ||
declaration: true, | ||
}), | ||
], | ||
external: [ | ||
'@playwright/test', | ||
'playwright', | ||
'quickpickle', | ||
'vite', | ||
'node:path', | ||
'node:url', | ||
'lodash-es', | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { chromium, type Browser, type BrowserContext, type Page } from 'playwright'; | ||
import { normalizeTags, QuickPickleWorld, QuickPickleWorldInterface } from 'quickpickle'; | ||
import { After } from 'quickpickle'; | ||
import type { TestContext } from 'vitest'; | ||
import { defaults, intersection } from 'lodash-es' | ||
|
||
export type PlaywrightWorldConfigSetting = { | ||
nojsTags?: string|string[] | ||
headless: boolean | ||
sloMo: number | ||
} | ||
|
||
export const defaultPlaywrightWorldConfig = { | ||
nojsTags: ['@nojs', '@noscript'], | ||
headless: true, | ||
slowMo: 0, | ||
} | ||
|
||
export type PlaywrightWorldConfig = typeof defaultPlaywrightWorldConfig | ||
|
||
export class PlaywrightWorld extends QuickPickleWorld { | ||
browser!: Browser | ||
browserContext!: BrowserContext | ||
page!: Page | ||
playwrightConfig:PlaywrightWorldConfig = defaultPlaywrightWorldConfig | ||
|
||
constructor(context:TestContext, info:QuickPickleWorldInterface['info']|undefined, worldConfig?:PlaywrightWorldConfigSetting) { | ||
super(context, info) | ||
let newConfig = defaults(defaultPlaywrightWorldConfig, worldConfig || {}) | ||
newConfig.nojsTags = normalizeTags(newConfig.nojsTags) | ||
this.playwrightConfig = newConfig | ||
} | ||
|
||
async init() { | ||
this.browser = await chromium.launch() | ||
this.browserContext = await this.browser.newContext({ | ||
serviceWorkers: 'block', | ||
javaScriptEnabled: intersection(this.info.tags, this.playwrightConfig.nojsTags)?.length ? false : true, | ||
}) | ||
this.page = await this.browserContext.newPage() | ||
} | ||
|
||
async reset() { | ||
await this.page?.close() | ||
await this.browserContext?.close() | ||
this.browserContext = await this.browser.newContext({ | ||
serviceWorkers: 'block' | ||
}) | ||
this.page = await this.browserContext.newPage() | ||
} | ||
|
||
async close() { | ||
await this.browser.close() | ||
} | ||
} | ||
|
||
After(async (world:PlaywrightWorld) => { | ||
await world.browserContext.close() | ||
}) |
Oops, something went wrong.