harmonyc 0.16.2 → 0.16.4
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
|
@@ -95,6 +95,14 @@ They are not included in the test case, but the test case name is generated from
|
|
|
95
95
|
|
|
96
96
|
Lines starting with `#` or `//` are comments and are ignored.
|
|
97
97
|
|
|
98
|
+
### Switches
|
|
99
|
+
|
|
100
|
+
You can generate multiple test cases by adding a `{ A / B / C }` syntax into action(s) and possibly response(s).
|
|
101
|
+
|
|
102
|
+
```harmony
|
|
103
|
+
+ password is { "A" / "asdf" / "password123" } => !! "password is too weak"
|
|
104
|
+
```
|
|
105
|
+
|
|
98
106
|
### Error matching
|
|
99
107
|
|
|
100
108
|
You can use `!!` to denote an error response. This will verify that the action throws an error. You can specify the error message after the `!!`.
|
|
@@ -128,7 +136,6 @@ test('T2 - store result in variable', (context) => {
|
|
|
128
136
|
})
|
|
129
137
|
```
|
|
130
138
|
|
|
131
|
-
## Running the tests
|
|
132
139
|
|
|
133
140
|
## License
|
|
134
141
|
|
|
@@ -3,7 +3,7 @@ import { OutFile } from './outFile.ts';
|
|
|
3
3
|
export declare class VitestGenerator implements CodeGenerator {
|
|
4
4
|
private tf;
|
|
5
5
|
private sf;
|
|
6
|
-
static error(message: string): string;
|
|
6
|
+
static error(message: string, stack: string): string;
|
|
7
7
|
framework: string;
|
|
8
8
|
phraseFns: Map<string, Phrase>;
|
|
9
9
|
currentFeatureName: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { basename } from 'path';
|
|
2
2
|
import { Arg, Response, Word, } from "../model/model.js";
|
|
3
3
|
export class VitestGenerator {
|
|
4
|
-
static error(message) {
|
|
5
|
-
return `const e = new SyntaxError(${str(message)});
|
|
6
|
-
e.stack = undefined;
|
|
7
|
-
throw e
|
|
4
|
+
static error(message, stack) {
|
|
5
|
+
return `const e = new SyntaxError(${str(message)});
|
|
6
|
+
e.stack = undefined;
|
|
7
|
+
throw e;
|
|
8
|
+
${stack ? `/* ${stack} */` : ''}`;
|
|
8
9
|
}
|
|
9
10
|
constructor(tf, sf) {
|
|
10
11
|
this.tf = tf;
|
|
@@ -71,10 +72,10 @@ export class VitestGenerator {
|
|
|
71
72
|
}
|
|
72
73
|
errorStep(action, errorResponse) {
|
|
73
74
|
this.declareFeatureVariables([action]);
|
|
74
|
-
this.tf.print(`context.task.meta.phrases.push(${str(errorResponse.toSingleLineString())});`);
|
|
75
75
|
this.tf.print(`await expect(async () => {`);
|
|
76
76
|
this.tf.indent(() => {
|
|
77
77
|
action.toCode(this);
|
|
78
|
+
this.tf.print(`context.task.meta.phrases.push(${str(errorResponse.toSingleLineString())});`);
|
|
78
79
|
});
|
|
79
80
|
this.tf.print(`}).rejects.toThrow(${(errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.message) !== undefined
|
|
80
81
|
? str(errorResponse.message.text)
|
package/compiler/compiler.js
CHANGED
|
@@ -42,7 +42,7 @@ export async function compileFile(fn) {
|
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
44
44
|
const outFileName = testFileName(fn);
|
|
45
|
-
writeFileSync(outFileName, VitestGenerator.error((_a = e.message) !== null && _a !== void 0 ? _a : `${e}
|
|
45
|
+
writeFileSync(outFileName, VitestGenerator.error((_a = e.message) !== null && _a !== void 0 ? _a : `${e}`, e.stack));
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
48
|
}
|
package/model/model.js
CHANGED
|
@@ -288,7 +288,7 @@ export class Phrase {
|
|
|
288
288
|
return this.parts.map((p) => p.toSingleLineString()).join(' ');
|
|
289
289
|
}
|
|
290
290
|
switch(i) {
|
|
291
|
-
return new this.constructor(this.parts.map((p) => (p instanceof Switch ? p.choices[i] : p)));
|
|
291
|
+
return new this.constructor(this.parts.map((p) => (p instanceof Switch ? p.choices[i] : p))).setFeature(this.feature);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
export class Action extends Phrase {
|