@empiricalrun/test-gen 0.22.10 → 0.22.12

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,17 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.22.12
4
+
5
+ ### Patch Changes
6
+
7
+ - bfd6724: fix: avoid duplicate fixture imports
8
+
9
+ ## 0.22.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 6771494: fix: handle dollar sign in generated code
14
+
3
15
  ## 0.22.10
4
16
 
5
17
  ### Patch Changes
@@ -10,4 +10,5 @@ export declare function formatCode(filePath: string): Promise<void>;
10
10
  export declare function addNewImport(contents: string, modules: string[], pkg: string): string;
11
11
  export declare function removeTestOnly(filePath: string): Promise<void>;
12
12
  export declare function getFixtureImportPath(filePath: string): string;
13
+ export declare function replaceCreateTestWithNewCode(filePath: string, contents: string, generatedCode: string): string;
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;EAwB3E;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAwD7D;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,mCAUjB;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAShD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAMpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,UAcpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;EAwB3E;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAwD7D;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,mCAUjB;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAShD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAMpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,UAcpD;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,UA0CtB"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.getTypescriptTestBlock = void 0;
6
+ exports.replaceCreateTestWithNewCode = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.getTypescriptTestBlock = void 0;
7
7
  const eslint_1 = require("eslint");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
@@ -138,3 +138,32 @@ function getFixtureImportPath(filePath) {
138
138
  return fixturesPath;
139
139
  }
140
140
  exports.getFixtureImportPath = getFixtureImportPath;
141
+ function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
142
+ const project = new ts_morph_1.Project();
143
+ const sourceFile = project.createSourceFile("test.ts", contents);
144
+ const createTestNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.CallExpression) &&
145
+ node.getExpression().getText() === "createTest"));
146
+ const createTestWithAwait = `await ${createTestNode?.getText()}`;
147
+ let updatedTestFile = contents.replace(createTestWithAwait, function () {
148
+ // str.replace treats characters like $ differently
149
+ // Using a function helps us avoid special handling
150
+ // https://stackoverflow.com/a/28103073
151
+ return "\n" + generatedCode;
152
+ });
153
+ const fixtureImportNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.ImportDeclaration) &&
154
+ node.getText().includes("fixtures")));
155
+ if (!fixtureImportNode) {
156
+ throw new Error("No import from fixtures found.");
157
+ }
158
+ const importClause = fixtureImportNode.getImportClause();
159
+ const namedImports = importClause
160
+ .getNamedImports()
161
+ .map((imp) => imp.getName());
162
+ const isComplete = namedImports.includes("test") && namedImports.includes("expect");
163
+ if (!isComplete) {
164
+ const expectedImports = `import { test, expect } from "${getFixtureImportPath(filePath)}";`;
165
+ updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
166
+ }
167
+ return updatedTestFile;
168
+ }
169
+ exports.replaceCreateTestWithNewCode = replaceCreateTestWithNewCode;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/file/server.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,IAAI,CAAa;gBACb,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAGtC,WAAW,CAAC,QAAQ,EAAE,MAAM;IAGtB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CAkC1C;AAED,wBAAsB,gBAAgB,kBAAK"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/file/server.ts"],"names":[],"mappings":"AASA,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,IAAI,CAAa;gBACb,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAGtC,WAAW,CAAC,QAAQ,EAAE,MAAM;IAGtB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CA8B1C;AAED,wBAAsB,gBAAgB,kBAAK"}
@@ -26,9 +26,8 @@ class FileService {
26
26
  const testFilePath = path_1.default.resolve(process.cwd(), this.filePath);
27
27
  if (testFilePath) {
28
28
  const testFile = fs_1.default.readFileSync(testFilePath, "utf-8");
29
- const updatedTestFile = testFile.replace(/await createTest\([\s\S]*?\);\n/, "\n" + generatedCode);
30
- const importStatement = `import { test, expect } from "${(0, web_1.getFixtureImportPath)(testFilePath)}";`;
31
- fs_1.default.writeFileSync(testFilePath, importStatement + "\n" + updatedTestFile, "utf-8");
29
+ const newContents = (0, web_1.replaceCreateTestWithNewCode)(testFilePath, testFile, generatedCode);
30
+ fs_1.default.writeFileSync(testFilePath, newContents, "utf-8");
32
31
  await (0, web_1.lintErrors)(testFilePath);
33
32
  return res.send({ success: true });
34
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.22.10",
3
+ "version": "0.22.12",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"