Skip to content

Commit e11bbcb

Browse files
committed
Added vitest test context to world object as world.context
1 parent c92919c commit e11bbcb

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

.changeset/fresh-dragons-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"quickpickle": patch
3+
---
4+
5+
Added vitest test context to playwright as world.context.

packages/main/gherkin-example/example.feature.js

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/main/src/render.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
} from 'quickpickle';
4242
${imports}
4343
let World = getWorldConstructor()
44-
const worldConfig = {}
4544
4645
const common = {};
4746
@@ -70,9 +69,9 @@ export function renderFeature(feature:Feature, config:QuickPickleConfig) {
7069

7170
// Render the initScenario function, which will be called at the beginning of each scenario
7271
return`
73-
const initScenario = async(scenario, tags) => {
74-
let state = new World(worldConfig);
75-
await state.init(worldConfig);
72+
const initScenario = async(context, scenario, tags) => {
73+
let state = new World(context);
74+
await state.init();
7675
state.common = common;
7776
state.info.feature = '${q(feature.keyword)}: ${q(feature.name)}';
7877
state.info.scenario = scenario;
@@ -123,8 +122,8 @@ function renderRule(child:FeatureChild, config:QuickPickleConfig, tags:string[],
123122
return `
124123
${sp}describe('${q(child.rule!.keyword)}: ${q(child.rule!.name)}', () => {
125124
126-
${sp} const initRuleScenario = async (scenario, tags) => {
127-
${sp} let state = await initScenario(scenario, tags);
125+
${sp} const initRuleScenario = async (context, scenario, tags) => {
126+
${sp} let state = await initScenario(context, scenario, tags);
128127
${sp} state.info.rule = '${q(child.rule!.name)}';
129128
${backgroundSteps}
130129
${sp} return state;
@@ -168,8 +167,8 @@ function renderScenario(child:FeatureChild, config:QuickPickleConfig, tags:strin
168167
return `
169168
${sp}test${attrs}.for(${JSON.stringify(paramValues)})(
170169
${sp} '${q(child.scenario?.keyword || '')}: ${describe}',
171-
${sp} async ({ ${paramNames?.join(', ')} }) => {
172-
${sp} let state = await ${initFn}(\`${name}\`, ['${tags.join("', '") || ''}']);
170+
${sp} async ({ ${paramNames?.join(', ')} }, context) => {
171+
${sp} let state = await ${initFn}(context, \`${name}\`, ['${tags.join("', '") || ''}']);
173172
${child.scenario?.steps.map((step,i) => {
174173
let text = step.text.replace(/`/g, '\\`')
175174
text = replaceParamNames(text,true)
@@ -183,8 +182,8 @@ ${sp});
183182
}
184183

185184
return `
186-
${sp}test${attrs}('${q(child.scenario!.keyword)}: ${q(child.scenario!.name)}', async () => {
187-
${sp} let state = await ${initFn}('${q(child.scenario!.name)}', ['${tags.join("', '") || ''}']);
185+
${sp}test${attrs}('${q(child.scenario!.keyword)}: ${q(child.scenario!.name)}', async (context) => {
186+
${sp} let state = await ${initFn}(context, '${q(child.scenario!.name)}', ['${tags.join("', '") || ''}']);
188187
${renderSteps(child.scenario!.steps as Step[], config, sp + ' ')}
189188
${sp} await afterScenario(state);
190189
${sp}});

packages/main/src/world.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { TestContext } from 'vitest'
12
export interface QuickPickleWorldInterface {
23
info: {
34
feature: string,
@@ -7,6 +8,7 @@ export interface QuickPickleWorldInterface {
78
step?: string,
89
line?: number,
910
}
11+
context: TestContext,
1012
common: {
1113
[key: string]: any
1214
}
@@ -22,6 +24,10 @@ export class QuickPickleWorld implements QuickPickleWorldInterface {
2224
step: '',
2325
}
2426
common: QuickPickleWorldInterface['common'] = {}
27+
context: TestContext
28+
constructor(context:TestContext) {
29+
this.context = context
30+
}
2531
async init() {}
2632
}
2733

0 commit comments

Comments
 (0)