@empiricalrun/test-run 0.1.1 → 0.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @empiricalrun/test-run
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 177ad09: fix: test-run fails due to a syntax error
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAW5C;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,EAC5B,IAAI,EACJ,GAAG,EACH,SAAS,GACV,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC7B,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC,CAmDD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAW5C;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,EAC5B,IAAI,EACJ,GAAG,EACH,SAAS,GACV,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC7B,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC,CAoDD"}
package/dist/index.js CHANGED
@@ -27,19 +27,24 @@ async function runTest({ name, dir, pwOptions, }) {
27
27
  const message = `No test block found for the given test name: ${name}`;
28
28
  throw Error(message);
29
29
  }
30
- const testNode = await (0, utils_1.getTestCaseNode)({
30
+ const { testCaseNode, sourceFile } = await (0, utils_1.getTestCaseNode)({
31
31
  filePath: matchingFilePath,
32
32
  scenarioName: name,
33
33
  });
34
- const parentDescribe = (0, utils_1.findFirstSerialDescribeBlock)(testNode);
34
+ const parentDescribe = (0, utils_1.findFirstSerialDescribeBlock)(testCaseNode);
35
35
  const isFileMarkedSerial = await (0, utils_1.hasTopLevelDescribeConfigureWithSerialMode)(matchingFilePath);
36
- console.log("Identified test block:", !!testNode);
36
+ console.log("Identified test block:", !!testCaseNode);
37
37
  console.log("Is parent describe block marked serial:", !!parentDescribe);
38
38
  console.log("Is file marked serial:", isFileMarkedSerial);
39
39
  const currentFileContent = await fs_extra_1.default.readFile(matchingFilePath, "utf-8");
40
40
  // if the file is not marked serial, we need to mark the test or describe block as only
41
- if (!isFileMarkedSerial) {
42
- await (0, utils_1.markTestAsOnly)(matchingFilePath, testNode.getText(), parentDescribe?.getText() || "");
41
+ if (!isFileMarkedSerial && testCaseNode) {
42
+ await (0, utils_1.markTestAsOnly)({
43
+ sourceFile,
44
+ parentDescribeNode: parentDescribe,
45
+ testCaseNode: testCaseNode,
46
+ filePath: matchingFilePath,
47
+ });
43
48
  }
44
49
  let hasTestPassed = true;
45
50
  try {
@@ -1,4 +1,4 @@
1
- import { Node } from "ts-morph";
1
+ import { Node, SourceFile } from "ts-morph";
2
2
  export declare function cmd(command: string[], options: {
3
3
  env?: Record<string, string>;
4
4
  }): Promise<number>;
@@ -12,12 +12,20 @@ export declare function getAllFilePaths(directoryPath?: string): Promise<string[
12
12
  export declare function getTestCaseNode({ filePath, scenarioName, }: {
13
13
  filePath: string;
14
14
  scenarioName: string;
15
- }): Promise<Node | undefined>;
15
+ }): Promise<{
16
+ testCaseNode: Node | undefined;
17
+ sourceFile: SourceFile;
18
+ }>;
16
19
  export declare function hasTestBlock({ filePath, scenarioName, }: {
17
20
  filePath: string;
18
21
  scenarioName: string;
19
22
  }): Promise<boolean>;
20
23
  export declare function findFirstSerialDescribeBlock(node: Node | undefined): Node | undefined;
21
24
  export declare function hasTopLevelDescribeConfigureWithSerialMode(filePath: string): Promise<boolean>;
22
- export declare function markTestAsOnly(filePath: string, testBlock: string, parentDescribeBlock?: string): Promise<void>;
25
+ export declare function markTestAsOnly({ sourceFile, parentDescribeNode, testCaseNode, filePath, }: {
26
+ sourceFile: SourceFile;
27
+ parentDescribeNode?: Node | undefined;
28
+ testCaseNode: Node;
29
+ filePath: string;
30
+ }): Promise<void>;
23
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAuB,MAAM,UAAU,CAAC;AAErD,wBAAgB,GAAG,CACjB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,aAAa,GAAE,MAAW,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBnB;AAED,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAc5B;AAED,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,OAAO,CAAC,CAMnB;AAED,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA2BlB;AAED,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,mBAAmB,CAAC,EAAE,MAAM,iBAkB7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAW,UAAU,EAAc,MAAM,UAAU,CAAC;AAEjE,wBAAgB,GAAG,CACjB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,aAAa,GAAE,MAAW,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBnB;AAED,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,IAAI,GAAG,SAAS,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAatE;AAED,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,OAAO,CAAC,CAMnB;AAED,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA2BlB;AAED,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED,wBAAsB,cAAc,CAAC,EACnC,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,QAAQ,GACT,EAAE;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,kBAAkB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IACtC,YAAY,EAAE,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,iBAgBA"}
@@ -72,19 +72,18 @@ async function getTestCaseNode({ filePath, scenarioName, }) {
72
72
  const project = new ts_morph_1.Project();
73
73
  const content = await fs_extra_1.default.readFile(filePath, "utf-8");
74
74
  const sourceFile = project.createSourceFile("test.ts", content);
75
- sourceFile.getDescendants;
76
- const testFunctionNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.CallExpression) &&
75
+ const testCaseNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.CallExpression) &&
77
76
  node.getExpression().getText() === "test" &&
78
77
  node.getArguments()[0]?.getText().includes(scenarioName)));
79
- return testFunctionNode;
78
+ return { testCaseNode, sourceFile };
80
79
  }
81
80
  exports.getTestCaseNode = getTestCaseNode;
82
81
  async function hasTestBlock({ filePath, scenarioName, }) {
83
- const testNode = await getTestCaseNode({
82
+ const { testCaseNode } = await getTestCaseNode({
84
83
  filePath,
85
84
  scenarioName,
86
85
  });
87
- return !!testNode;
86
+ return !!testCaseNode;
88
87
  }
89
88
  exports.hasTestBlock = hasTestBlock;
90
89
  function findFirstSerialDescribeBlock(node) {
@@ -139,17 +138,22 @@ async function hasTopLevelDescribeConfigureWithSerialMode(filePath) {
139
138
  return false;
140
139
  }
141
140
  exports.hasTopLevelDescribeConfigureWithSerialMode = hasTopLevelDescribeConfigureWithSerialMode;
142
- async function markTestAsOnly(filePath, testBlock, parentDescribeBlock) {
143
- const fileContent = await fs_extra_1.default.readFile(filePath, "utf-8");
144
- let updatedTestFileContent = fileContent;
145
- if (!parentDescribeBlock) {
146
- const updatedTestBlock = testBlock.replace("test(", "test.only(");
147
- updatedTestFileContent = fileContent.replace(testBlock, updatedTestBlock);
141
+ async function markTestAsOnly({ sourceFile, parentDescribeNode, testCaseNode, filePath, }) {
142
+ let updatedTestFileContent = sourceFile.getFullText();
143
+ if (!parentDescribeNode) {
144
+ const updatedTestBlock = testCaseNode
145
+ .getText()
146
+ .replace("test(", "test.only(");
147
+ testCaseNode?.replaceWithText(updatedTestBlock);
148
+ updatedTestFileContent = sourceFile.getFullText();
148
149
  }
149
150
  else {
150
- const describeMarkedAsOnly = parentDescribeBlock.replace("test.describe(", "test.describe.only(");
151
- updatedTestFileContent = fileContent.replace(parentDescribeBlock, describeMarkedAsOnly);
151
+ const describeMarkedAsOnly = parentDescribeNode
152
+ .getText()
153
+ .replace("test.describe(", "test.describe.only(");
154
+ parentDescribeNode.replaceWithText(describeMarkedAsOnly);
155
+ updatedTestFileContent = sourceFile.getFullText();
152
156
  }
153
- await fs_extra_1.default.writeFile(filePath, updatedTestFileContent);
157
+ await fs_extra_1.default.writeFile(filePath, updatedTestFileContent, "utf-8");
154
158
  }
155
159
  exports.markTestAsOnly = markTestAsOnly;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-run",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"