pickle-jar 2.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # pickle-jar
2
- [//]: <> (start placeholder for auto-badger)
2
+ pickle-jar is an alternative to jest-cucumber and Cucumber.js that runs on top of Jest or Vitest. `pickle-jar`
3
+ allows defining test scenarios using Gherkin language and translates them into describe/it blocks.
4
+ Compared to jest-cucumber, the output is more explicit and all steps are represented by describe blocks.
3
5
 
6
+ [//]: <> (start placeholder for auto-badger)
4
7
 
5
8
  [![version](https://img.shields.io/npm/v/pickle-jar.svg?style=flat-square)](https://npmjs.org/pickle-jar)
6
9
  [![min size](https://img.shields.io/bundlephobia/min/pickle-jar?style=flat-square)](https://bundlephobia.com/result?p=pickle-jar)
@@ -9,20 +12,14 @@
9
12
 
10
13
  [![dependancies](https://img.shields.io/librariesio/release/npm/pickle-jar?color=%23007a1f&style=flat-square)](https://libraries.io/npm/pickle-jar)
11
14
  [![downloads](https://img.shields.io/npm/dm/pickle-jar?style=flat-square&color=%23007a1f)](https://npmcharts.com/compare/pickle-jar)
12
- [![all contributors](https://img.shields.io/github/all-contributors/nseba/pickle-jar?style=flat-square)](https://github.com/nseba/pickle-jar/graphs/contributors)
13
- [![code of conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/nseba/pickle-jar/blob/master/CODE_OF_CONDUCT.md)
14
15
 
15
16
  [![stargazers](https://img.shields.io/github/stars/nseba/pickle-jar?style=social)](https://github.com/nseba/pickle-jar/stargazers)
16
17
  [![number of forks](https://img.shields.io/github/forks/nseba/pickle-jar?style=social)](https://github.com/nseba/pickle-jar/fork)
17
18
 
18
19
  [//]: <> (end placeholder for auto-badger)
19
20
 
20
- Framework for writing Gherkin features and running them using Jest
21
-
22
21
  # Overview
23
- pickle-jar is an alternative to jest-cucumber and and Cucumber.js that runs on top of jest. `pickle-jar`
24
- allows defining test scnearios using Gherkin language and translates them into define/it blocks that run using jest.
25
- Compared to jest-cucumber, the output is more explicit and all steps are reperesented by jest describe blocks.
22
+
26
23
 
27
24
  The framework allows defining steps using regular expression matchers. Match groups are automatically passed as parameters
28
25
  to the step function.
@@ -165,10 +162,10 @@ const tagFilter = (tags: string[])=> {
165
162
  ```
166
163
  There are several builtin tags which are handled differently than custom tags:
167
164
 
168
- * `@skip` - when used, the step and sub-steps are completely skipped (they are handled as Jest `describe.only` or `it.only` calls)
169
- * `@only` - when used, only the steps and sub-steps are executed (they are handled as Jest `describe.only` or `it.only` calls)
170
- * `@todo` - when used, the step is marked as a TODO and no step code is executed (they are handled as Jest `it.todo` calls)
171
- * `@fail` - when used, the step is expected to fail (thye are handled as Jest `it.failed` calls)
165
+ * `@skip` - when used, the step and sub-steps are completely skipped (maps to `describe.skip` or `it.skip`)
166
+ * `@only` - when used, only the steps and sub-steps are executed (maps to `describe.only` or `it.only`)
167
+ * `@todo` - when used, the step is marked as a TODO and no step code is executed (maps to `it.todo`)
168
+ * `@fail` - when used, the step is expected to fail (maps to `it.failing` in Jest or `it.fails` in Vitest)
172
169
 
173
170
  ## Jest configuration
174
171
  Create a `jest.config.js` file in the project root (or update the existing one) to match the `runner.ts` file:
@@ -185,4 +182,65 @@ module.exports = {
185
182
  moduleFileExtensions: ['ts', 'js', 'html'],
186
183
  coverageDirectory: '../coverage/',
187
184
  };
188
- ```
185
+ ```
186
+
187
+ ## Using with Vitest
188
+
189
+ pickle-jar supports Vitest as an alternative to Jest. To use Vitest, pass the `vitestAdapter` in the options:
190
+
191
+ ### Install dependencies
192
+ ```shell
193
+ npm install vitest --dev
194
+ ```
195
+
196
+ ### Update runner.ts for Vitest
197
+ ```ts
198
+ import {StepDefinition, testRunner, vitestAdapter} from "pickle-jar";
199
+
200
+ interface World {
201
+ password: string | undefined;
202
+ grantedAccess: boolean;
203
+ }
204
+
205
+ const stepDefinitions: StepDefinition<World>[] = [{
206
+ match: /^Given I have previously created a password$/, step: (world) => {
207
+ world.password = "my password";
208
+ }
209
+ }, {
210
+ match: /^When I enter my password correctly$/, step: (world) => {
211
+ world.grantedAccess = world.password === 'my password';
212
+ }
213
+ }, {
214
+ match: /^I should be granted access$/, step: (world) => {
215
+ expect(world.grantedAccess).toBeTruthy();
216
+ }
217
+ }];
218
+
219
+ const createWorld = () => ({
220
+ password: undefined,
221
+ grantedAccess: false
222
+ });
223
+
224
+ testRunner<World>(
225
+ `${__dirname}/features/**/*.feature`,
226
+ stepDefinitions,
227
+ createWorld,
228
+ () => true,
229
+ { adapter: vitestAdapter }
230
+ );
231
+ ```
232
+
233
+ ### Vitest configuration
234
+ Create a `vitest.config.ts` file:
235
+ ```ts
236
+ import { defineConfig } from 'vitest/config';
237
+
238
+ export default defineConfig({
239
+ test: {
240
+ include: ['test/runner.ts'],
241
+ globals: true,
242
+ },
243
+ });
244
+ ```
245
+
246
+ Note: Vitest must be configured with `globals: true` for the adapter to work correctly.
@@ -1,5 +1,4 @@
1
1
  export interface FeatureContext {
2
- file: string;
3
2
  directory: string;
4
3
  absoluteFeaturePath: string;
5
4
  relativeFeaturePath: string;
@@ -1,3 +1,9 @@
1
1
  import { StepDefinition } from "./step-definition";
2
2
  import { WorldFactory } from "./world";
3
- export declare function testRunner<TWorld>(globPattern: string, stepDefinitions: StepDefinition<TWorld>[], worldFactory: WorldFactory<TWorld>, tagFilter?: (tags: string[]) => boolean): void;
3
+ interface TestRunnerAllOptions {
4
+ workDir: string;
5
+ groupByFeaturePath: boolean;
6
+ }
7
+ export type TestRunnerOptions = Partial<TestRunnerAllOptions>;
8
+ export declare function testRunner<TWorld>(globPattern: string, stepDefinitions: StepDefinition<TWorld>[], worldFactory: WorldFactory<TWorld>, tagFilter?: (tags: string[]) => boolean, options?: TestRunnerOptions): void;
9
+ export {};
@@ -40,26 +40,25 @@ const glob_1 = require("glob");
40
40
  const os_1 = require("os");
41
41
  const path = __importStar(require("path"));
42
42
  const feature_file_visitor_1 = require("./feature-file-visitor");
43
- const get_call_sites_1 = require("./get-call-sites");
44
43
  const GherkinLexer_1 = require("./grammar/GherkinLexer");
45
44
  const GherkinParser_1 = require("./grammar/GherkinParser");
46
45
  const jest_error_listener_1 = require("./jest-error-listener");
47
- function testRunner(globPattern, stepDefinitions, worldFactory, tagFilter = () => true) {
48
- var _a;
46
+ function testRunner(globPattern, stepDefinitions, worldFactory, tagFilter = () => true, options) {
47
+ const defaultOptions = {
48
+ workDir: process.cwd(),
49
+ groupByFeaturePath: true,
50
+ };
51
+ const actualOptions = Object.assign(Object.assign({}, defaultOptions), options);
49
52
  const featureFiles = glob_1.glob.sync(globPattern);
50
53
  for (const featureFile of featureFiles) {
51
- const callSite = (0, get_call_sites_1.getCallSites)()[1];
52
- const file = (_a = callSite === null || callSite === void 0 ? void 0 : callSite.getFileName()) !== null && _a !== void 0 ? _a : "";
53
- const dir = path.dirname(file);
54
- const absoluteFeaturePath = path.resolve(dir, featureFile);
55
- const relativeFeaturePath = path.relative(dir, absoluteFeaturePath);
54
+ const absoluteFeaturePath = path.resolve(actualOptions.workDir, featureFile);
55
+ const relativeFeaturePath = path.relative(actualOptions.workDir, absoluteFeaturePath);
56
56
  const featureContext = {
57
- file: file,
58
- directory: dir,
57
+ directory: actualOptions.workDir,
59
58
  absoluteFeaturePath: absoluteFeaturePath,
60
59
  relativeFeaturePath: relativeFeaturePath,
61
60
  };
62
- describe(relativeFeaturePath, () => {
61
+ const run = () => {
63
62
  const listener = new jest_error_listener_1.JestErrorListener();
64
63
  const featureText = fs.readFileSync(absoluteFeaturePath, "utf-8") + os_1.EOL;
65
64
  const input = antlr4ts_1.CharStreams.fromString(featureText);
@@ -74,7 +73,13 @@ function testRunner(globPattern, stepDefinitions, worldFactory, tagFilter = () =
74
73
  const visitor = new feature_file_visitor_1.FeatureFileVisitor(worldFactory, stepDefinitions, tagFilter, featureContext);
75
74
  parsedFeatureFile.accept(visitor);
76
75
  listener.reportErrors();
77
- });
76
+ };
77
+ if (actualOptions.groupByFeaturePath) {
78
+ describe(relativeFeaturePath, run);
79
+ }
80
+ else {
81
+ run();
82
+ }
78
83
  }
79
84
  }
80
85
  //# sourceMappingURL=test-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-runner.js","sourceRoot":"","sources":["../../src/test-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,gCA0CC;AAzDD,uCAA0D;AAC1D,uCAAyB;AACzB,+BAA0B;AAC1B,2BAAuB;AACvB,2CAA6B;AAE7B,iEAA0D;AAC1D,qDAA8C;AAC9C,yDAAoD;AACpD,2DAA0E;AAC1E,+DAAwD;AAKxD,SAAgB,UAAU,CAAS,WAAmB,EAAE,eAAyC,EAAE,YAAkC,EAAE,YAAwC,GAAE,EAAE,CAAC,IAAI;;IAEpL,MAAM,YAAY,GAAG,WAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC5C,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,IAAA,6BAAY,GAAE,CAAC,CAAC,CAAC,CAAC;QAGnC,MAAM,IAAI,GAAG,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,EAAE,mCAAI,EAAE,CAAC;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC3D,MAAM,mBAAmB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QAEpE,MAAM,cAAc,GAAoB;YACpC,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,GAAG;YACd,mBAAmB,EAAE,mBAAmB;YACxC,mBAAmB,EAAE,mBAAmB;SAC3C,CAAA;QAGD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC/B,MAAM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MAAM,iBAAiB,GAAuB,MAAM,CAAC,WAAW,EAAE,CAAC;YACnE,MAAM,OAAO,GAAG,IAAI,yCAAkB,CAAS,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;YACzG,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAElC,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC,CAAA;QAED,IAAI,aAAa,CAAC,kBAAkB,EAAE,CAAC;YACnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACJ,GAAG,EAAE,CAAC;QACV,CAAC;IACL,CAAC;AAGL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pickle-jar",
3
- "version": "2.0.2",
3
+ "version": "4.0.0",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "devDependencies": {
19
19
  "@types/glob": "^8.1.0",
20
- "@types/jest": "^29.5.14",
20
+ "@types/jest": "^30.0.0",
21
21
  "@typescript-eslint/eslint-plugin": "^8.27.0",
22
22
  "@typescript-eslint/parser": "^8.27.0",
23
23
  "antlr4": "^4.13.2",
@@ -25,15 +25,21 @@
25
25
  "antlr4ts-cli": "^0.5.0-alpha.4",
26
26
  "eslint": "^9.22.0",
27
27
  "eslint-config-prettier": "^10.1.1",
28
- "glob": "^11.0.1",
29
- "jest": "^29.7.0",
30
- "ts-jest": "^29.2.6",
31
- "tsc-watch": "^6.2.1",
28
+ "glob": "^13.0.0",
29
+ "jest": "^30.2.0",
30
+ "ts-jest": "^29.4.6",
31
+ "tsc-watch": "^7.2.0",
32
32
  "typescript": "^5.8.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "antlr4": "^4.13.0",
36
36
  "antlr4ts": "^0.5.0-alpha.4",
37
- "glob": "^10.2.6"
37
+ "glob": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
38
+ "vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "vitest": {
42
+ "optional": true
43
+ }
38
44
  }
39
45
  }