From 51ac139ad7447ca610f85d2eecdbd93577b37995 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 5 Jan 2020 01:29:14 +0100 Subject: [PATCH] proper fix for shadowed names --- src/templates/entity.mst | 2 +- test/integration/runTestsFromPath.test.ts | 29 ++++++---- .../modelCustomization.test.ts | 58 +++++++++---------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/templates/entity.mst b/src/templates/entity.mst index 12382ad..c9b57e8 100644 --- a/src/templates/entity.mst +++ b/src/templates/entity.mst @@ -13,7 +13,7 @@ import {{localImport (toEntityName .)}} from './{{toFileName .}}' { name: "{{name}}", referencedColumnName: "{{toPropertyName referencedColumnName}}" }, {{/inline}} {{#*inline "Relation"}} -@{{relationType}}(()=>{{toEntityName relatedTable}},{{toEntityName relatedTable}}_=>{{toEntityName relatedTable}}_.{{toPropertyName relatedField}}{{#if relationOptions}},{ {{json relationOptions}} }{{/if}}) +@{{relationType}}(()=>{{toEntityName relatedTable}},{{toPropertyName relatedTable}}=>{{toPropertyName relatedTable}}.{{toPropertyName relatedField}}{{#if relationOptions}},{ {{json relationOptions}} }{{/if}}) {{#if joinColumnOptions}}@JoinColumn([{{#joinColumnOptions}}{{> JoinColumnOptions}}{{/joinColumnOptions}}]){{/if}} {{#joinTableOptions}}@JoinTable({ name:"{{name}}", joinColumns:[{{#joinColumns}}{{> JoinColumnOptions}}{{/joinColumns}}],inverseJoinColumns:[{{#inverseJoinColumns}}{{> JoinColumnOptions}}{{/inverseJoinColumns}}],{{#database}}database:"{{.}}",{{/database}}{{#schema}}schema:"{{.}}"{{/schema}} }){{/joinTableOptions}} {{printPropertyVisibility}}{{toPropertyName fieldName}}{{strictMode}}:{{toRelation (toEntityName relatedTable) relationType}}; diff --git a/test/integration/runTestsFromPath.test.ts b/test/integration/runTestsFromPath.test.ts index 10981de..9b52340 100644 --- a/test/integration/runTestsFromPath.test.ts +++ b/test/integration/runTestsFromPath.test.ts @@ -24,7 +24,7 @@ const { expect } = chai; it("Column default values", async () => { const testPartialPath = "test/integration/defaultValues"; await runTestsFromPath(testPartialPath, true); -}) +}); it("Platform specific types", async () => { const testPartialPath = "test/integration/entityTypes"; await runTestsFromPath(testPartialPath, true); @@ -249,7 +249,11 @@ function compareGeneratedFiles(filesOrgPathTS: string, filesGenPath: string) { // TODO: Move(?) // eslint-disable-next-line import/prefer-default-export -export function compileGeneratedModel(filesGenPath: string, drivers: string[]) { +export function compileGeneratedModel( + filesGenPath: string, + drivers: string[], + lintGeneratedFiles = true +) { const currentDirectoryFiles: string[] = []; drivers.forEach(driver => { const entitiesPath = path.resolve(filesGenPath, driver, "entities"); @@ -279,14 +283,19 @@ export function compileGeneratedModel(filesGenPath: string, drivers: string[]) { "Errors detected while compiling generated model" ).to.equal(true); - - const cli = new CLIEngine({ configFile: "test/configs/.eslintrc.js" }); - const lintReport = cli.executeOnFiles(currentDirectoryFiles) - lintReport.results.forEach(result => result.messages.forEach(message => { - console.error(`${result.filePath}:${message.line} - ${message.message}`) - })) - expect(lintReport.errorCount).to.equal(0) - expect(lintReport.warningCount).to.equal(0) + if (lintGeneratedFiles) { + const cli = new CLIEngine({ configFile: "test/configs/.eslintrc.js" }); + const lintReport = cli.executeOnFiles(currentDirectoryFiles); + lintReport.results.forEach(result => + result.messages.forEach(message => { + console.error( + `${result.filePath}:${message.line} - ${message.message}` + ); + }) + ); + expect(lintReport.errorCount).to.equal(0); + expect(lintReport.warningCount).to.equal(0); + } } async function prepareTestRuns( diff --git a/test/modelCustomization/modelCustomization.test.ts b/test/modelCustomization/modelCustomization.test.ts index 1f6cd47..8082c48 100644 --- a/test/modelCustomization/modelCustomization.test.ts +++ b/test/modelCustomization/modelCustomization.test.ts @@ -4,13 +4,9 @@ import * as chai from "chai"; import * as chaiSubset from "chai-subset"; import { Entity } from "../../src/models/Entity"; import modelCustomizationPhase from "../../src/ModelCustomization"; -import { - getDefaultGenerationOptions -} from "../../src/IGenerationOptions"; +import { getDefaultGenerationOptions } from "../../src/IGenerationOptions"; import modelGenerationPhase from "../../src/ModelGeneration"; -import { - getDefaultConnectionOptions -} from "../../src/IConnectionOptions"; +import { getDefaultConnectionOptions } from "../../src/IConnectionOptions"; import { compileGeneratedModel } from "../integration/runTestsFromPath.test"; chai.use(chaiSubset); @@ -226,7 +222,7 @@ describe("Model customization phase", async () => { expect(postContent).to.contain("class post {"); expect(postAuthorContent).to.contain("class postAuthor {"); - compileGeneratedModel(generationOptions.resultsPath, [""]); + compileGeneratedModel(generationOptions.resultsPath, [""], false); }); }); describe("case-property", async () => { @@ -256,7 +252,7 @@ describe("Model customization phase", async () => { expect(postContent).to.contain("Title: string;"); expect(postAuthorContent).to.contain("Posts: Post[];"); - compileGeneratedModel(generationOptions.resultsPath, [""]); + compileGeneratedModel(generationOptions.resultsPath, [""], false); }); it("camelCase", () => { const data = generateSampleData(); @@ -575,9 +571,9 @@ describe("Model customization phase", async () => { const data = generateSampleData(); const generationOptions = generateGenerationOptions(); clearGenerationDir(); - generationOptions.convertCaseEntity = "none" - generationOptions.convertCaseFile = "none" - generationOptions.convertCaseProperty = "none" + generationOptions.convertCaseEntity = "none"; + generationOptions.convertCaseFile = "none"; + generationOptions.convertCaseProperty = "none"; generationOptions.customNamingStrategyPath = "test/modelCustomization/testNamingStrategy.ts"; // TODO: relationId @@ -613,11 +609,10 @@ describe("Model customization phase", async () => { `import { Post_B } from "./Post_B";` ); - compileGeneratedModel(generationOptions.resultsPath, [""]); + compileGeneratedModel(generationOptions.resultsPath, [""], false); }); describe("pluralization", () => { it("enabled", async () => { - const data = generateSampleData(); const generationOptions = generateGenerationOptions(); generationOptions.pluralizeNames = true; @@ -639,9 +634,8 @@ describe("Model customization phase", async () => { .toString(); expect(postAuthorContent).to.contain("posts: Post[];"); compileGeneratedModel(generationOptions.resultsPath, [""]); - }) + }); it("disabled", async () => { - const data = generateSampleData(); const generationOptions = generateGenerationOptions(); generationOptions.pluralizeNames = false; @@ -663,11 +657,10 @@ describe("Model customization phase", async () => { .toString(); expect(postAuthorContent).to.contain("post: Post[];"); compileGeneratedModel(generationOptions.resultsPath, [""]); - }) - }) + }); + }); describe("index file generation", () => { it("named export", async () => { - const data = generateSampleData(); const generationOptions = generateGenerationOptions(); generationOptions.indexFile = true; @@ -687,17 +680,18 @@ describe("Model customization phase", async () => { const indexFileContent = fs .readFileSync(path.resolve(filesGenPath, "Index.ts")) .toString(); - expect(indexFileContent).to.contain('import { PostAuthor } from "./PostAuthor'); + expect(indexFileContent).to.contain( + 'import { PostAuthor } from "./PostAuthor' + ); expect(indexFileContent).to.contain('import { Post } from "./Post'); - expect(indexFileContent).to.contain('export { PostAuthor, Post }'); + expect(indexFileContent).to.contain("export { PostAuthor, Post }"); compileGeneratedModel(generationOptions.resultsPath, [""]); - }) + }); it("default export", async () => { - const data = generateSampleData(); const generationOptions = generateGenerationOptions(); generationOptions.indexFile = true; - generationOptions.exportType = "default" + generationOptions.exportType = "default"; clearGenerationDir(); const customizedModel = modelCustomizationPhase( @@ -714,13 +708,14 @@ describe("Model customization phase", async () => { const indexFileContent = fs .readFileSync(path.resolve(filesGenPath, "Index.ts")) .toString(); - expect(indexFileContent).to.contain('import PostAuthor from "./PostAuthor'); + expect(indexFileContent).to.contain( + 'import PostAuthor from "./PostAuthor' + ); expect(indexFileContent).to.contain('import Post from "./Post'); - expect(indexFileContent).to.contain('export { PostAuthor, Post }'); + expect(indexFileContent).to.contain("export { PostAuthor, Post }"); compileGeneratedModel(generationOptions.resultsPath, [""]); - }) + }); it("disabled", async () => { - const data = generateSampleData(); const generationOptions = generateGenerationOptions(); generationOptions.pluralizeNames = false; @@ -737,9 +732,10 @@ describe("Model customization phase", async () => { customizedModel ); const filesGenPath = path.resolve(resultsPath, "entities"); - expect(fs.existsSync(path.resolve(filesGenPath, "Index.ts"))).to.equal(false); + expect( + fs.existsSync(path.resolve(filesGenPath, "Index.ts")) + ).to.equal(false); compileGeneratedModel(generationOptions.resultsPath, [""]); - }) - }) - + }); + }); });