harmonyc 0.6.0-7 → 0.6.0-9

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/compiler.js CHANGED
@@ -5,16 +5,22 @@ export async function compileFiles(pattern) {
5
5
  const fns = await glob(pattern);
6
6
  if (!fns.length)
7
7
  throw new Error(`No files found for pattern: ${String(pattern)}`);
8
- const outFns = await Promise.all(fns.map((fn) => compileFile(fn)));
8
+ const features = await Promise.all(fns.map((fn) => compileFile(fn)));
9
9
  console.log(`Compiled ${fns.length} file${fns.length === 1 ? '' : 's'}.`);
10
- return { fns, outFns };
10
+ const generated = features.filter((f) => f.stepsFileAction === 'generated');
11
+ if (generated.length) {
12
+ console.log(`Generated ${generated.length} steps file${generated.length === 1 ? '' : 's'}.`);
13
+ }
14
+ return { fns, outFns: features.map((f) => f.outFile.name) };
11
15
  }
12
16
  export async function compileFile(fn) {
13
17
  const src = readFileSync(fn, 'utf8').toString();
14
18
  const { outFile, stepsFile } = compileFeature(fn, src);
15
19
  writeFileSync(outFile.name, outFile.value);
20
+ let stepsFileAction = 'ignored';
16
21
  if (!existsSync(stepsFile.name)) {
22
+ stepsFileAction = 'generated';
17
23
  writeFileSync(stepsFile.name, stepsFile.value);
18
24
  }
19
- return outFile.name;
25
+ return { stepsFileAction, outFile, stepsFile };
20
26
  }
@@ -7,10 +7,11 @@ export function testFileName(fn) {
7
7
  return base(fn) + '.test.mjs';
8
8
  }
9
9
  export function stepsFileName(fn) {
10
- const pattern = convertPathToPattern(base(fn) + '.steps.*');
11
- const existing = globSync(pattern);
10
+ const baseFn = base(fn);
11
+ const pattern = convertPathToPattern(baseFn);
12
+ const existing = globSync(`${pattern}.steps.*`);
12
13
  if (existing.length) {
13
14
  return existing.sort()[0];
14
15
  }
15
- return base(fn) + '.steps.ts';
16
+ return `${baseFn}.steps.ts`;
16
17
  }
package/js_api/js_api.js CHANGED
@@ -18,7 +18,7 @@ class FeatureContext {
18
18
  _FeatureContext_responses.set(this, []);
19
19
  _FeatureContext_parameterTypeRegistry.set(this, new ParameterTypeRegistry());
20
20
  this.Action = ((s, fn) => {
21
- if (fn) {
21
+ if (typeof fn === 'function') {
22
22
  const expr = new CucumberExpression(s, __classPrivateFieldGet(this, _FeatureContext_parameterTypeRegistry, "f"));
23
23
  const def = new Definition(expr, fn);
24
24
  __classPrivateFieldGet(this, _FeatureContext_actions, "f").push(def);
@@ -37,10 +37,11 @@ class FeatureContext {
37
37
  }
38
38
  const match = matches[matching[0]];
39
39
  const def = __classPrivateFieldGet(this, _FeatureContext_actions, "f")[matching[0]];
40
- return Promise.resolve(def.fn(...match.map((m) => m.getValue(undefined))));
40
+ const docstring = fn;
41
+ return Promise.resolve(def.fn(...match.map((m) => m.getValue(undefined)), docstring));
41
42
  });
42
43
  this.Response = ((s, fn) => {
43
- if (fn) {
44
+ if (typeof fn === 'function') {
44
45
  const expr = new CucumberExpression(s, __classPrivateFieldGet(this, _FeatureContext_parameterTypeRegistry, "f"));
45
46
  const def = new Definition(expr, fn);
46
47
  __classPrivateFieldGet(this, _FeatureContext_responses, "f").push(def);
@@ -59,7 +60,8 @@ class FeatureContext {
59
60
  }
60
61
  const match = matches[matching[0]];
61
62
  const def = __classPrivateFieldGet(this, _FeatureContext_responses, "f")[matching[0]];
62
- return Promise.resolve(def.fn(...match.map((m) => m.getValue(undefined))));
63
+ const docstring = fn;
64
+ return Promise.resolve(def.fn(...match.map((m) => m.getValue(undefined)), docstring));
63
65
  });
64
66
  }
65
67
  }
@@ -51,13 +51,17 @@ export class NodeTest {
51
51
  f = toId(feature, this.featureVars);
52
52
  this.tf.print(`const ${f} = Feature(${str(feature)})`);
53
53
  }
54
- this.tf.print(`await ${f}.${capitalize(p.kind)}(${str(p.text)})`);
54
+ const docstring = p.docstring ? ', \n' + templateStr(p.docstring) : '';
55
+ this.tf.print(`await ${f}.${capitalize(p.kind)}(${str(p.text)}${docstring})`);
55
56
  }
56
57
  }
57
58
  function str(s) {
58
59
  let r = JSON.stringify(s);
59
60
  return r;
60
61
  }
62
+ function templateStr(s) {
63
+ return '`' + s.replace(/([`$])/g, '\\$1') + '`';
64
+ }
61
65
  function capitalize(s) {
62
66
  return s.charAt(0).toUpperCase() + s.slice(1);
63
67
  }
package/model.js CHANGED
@@ -117,7 +117,9 @@ export class Phrase {
117
117
  return this.kind === 'action' ? 'When' : 'Then';
118
118
  }
119
119
  toCode(cg) {
120
- return cg.phrase(this);
120
+ if (!this.text)
121
+ return;
122
+ cg.phrase(this);
121
123
  }
122
124
  definition() {
123
125
  const key = this.kind === 'action' ? this.text : `=> ${this.text}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "harmonyc",
3
3
  "description": "Harmony Code - model-driven BDD for Vitest",
4
- "version": "0.6.0-7",
4
+ "version": "0.6.0-9",
5
5
  "author": "Bernát Kalló",
6
6
  "type": "module",
7
7
  "bin": {
package/run.js CHANGED
@@ -1,4 +1,4 @@
1
- import { exec } from 'child_process';
1
+ import { exec, spawn } from 'child_process';
2
2
  function runCommand(patterns) {
3
3
  return `npx vitest run ${args(patterns)}`;
4
4
  }
@@ -9,18 +9,13 @@ function args(patterns) {
9
9
  return patterns.map((s) => JSON.stringify(s)).join(' ');
10
10
  }
11
11
  export function run(patterns) {
12
- var _a, _b, _c;
12
+ var _a, _b;
13
13
  const cmd = runCommand(patterns);
14
14
  const p = exec(cmd, { cwd: process.cwd() });
15
- (_a = p.stdin) === null || _a === void 0 ? void 0 : _a.pipe(process.stdin);
16
- (_b = p.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
17
- (_c = p.stderr) === null || _c === void 0 ? void 0 : _c.pipe(process.stderr);
15
+ (_a = p.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
16
+ (_b = p.stderr) === null || _b === void 0 ? void 0 : _b.pipe(process.stderr);
18
17
  }
19
18
  export function runWatch(patterns) {
20
- var _a, _b, _c;
21
19
  const cmd = runWatchCommand(patterns);
22
- const p = exec(cmd, { cwd: process.cwd() });
23
- (_a = p.stdin) === null || _a === void 0 ? void 0 : _a.pipe(process.stdin);
24
- (_b = p.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
25
- (_c = p.stderr) === null || _c === void 0 ? void 0 : _c.pipe(process.stderr);
20
+ spawn(cmd, { cwd: process.cwd(), stdio: 'inherit', shell: true });
26
21
  }
package/syntax.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import remarkParse from 'remark-parse';
2
2
  import { unified } from 'unified';
3
3
  import { Feature, Section, Step } from './model.js';
4
- import { definitions } from './definitions.js';
5
4
  export function parse({ fileName, src, }) {
6
5
  const tree = unified().use(remarkParse).parse(src);
7
6
  const rootNodes = tree.children;
@@ -36,23 +35,12 @@ export function parse({ fileName, src, }) {
36
35
  return [];
37
36
  if (node.type == 'list')
38
37
  return list(node);
39
- if (node.type === 'code')
40
- return code(node);
41
38
  return [];
42
39
  }
43
40
  function list(node) {
44
41
  const isFork = node.ordered === false;
45
42
  return node.children.map((item) => listItem(item, isFork));
46
43
  }
47
- function code(node) {
48
- var _a;
49
- if (!((_a = node.meta) === null || _a === void 0 ? void 0 : _a.match(/harmony/)))
50
- return [];
51
- const code = node.value;
52
- const marker = '///';
53
- definitions({ marker, code, feature });
54
- return [];
55
- }
56
44
  function listItem(node, isFork) {
57
45
  const first = node.children[0];
58
46
  const text = textContent(first);
package/definitions.js DELETED
@@ -1,22 +0,0 @@
1
- import { CucumberExpression, ParameterTypeRegistry, } from '@cucumber/cucumber-expressions';
2
- const registry = new ParameterTypeRegistry();
3
- export function definitions({ marker, code, feature, }) {
4
- var _a, _b;
5
- const re = new RegExp(`^\s*${q(marker)}(.*?)$`, 'gm');
6
- let match = re.exec(code);
7
- const start = (_a = match === null || match === void 0 ? void 0 : match.index) !== null && _a !== void 0 ? _a : code.length;
8
- feature.prelude += code.slice(0, start);
9
- while (match) {
10
- const bodyStart = match.index + match[0].length;
11
- const head = match[1].trim();
12
- match = re.exec(code);
13
- const end = (_b = match === null || match === void 0 ? void 0 : match.index) !== null && _b !== void 0 ? _b : code.length;
14
- const body = code.slice(bodyStart, end).trim();
15
- if (body) {
16
- feature.definitions.set(new CucumberExpression(head, registry), body);
17
- }
18
- }
19
- }
20
- function q(pattern) {
21
- return pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
22
- }