proper fix for shadowed names

This commit is contained in:
Kononnable 2020-01-05 01:29:14 +01:00
parent b34555a1f1
commit 51ac139ad7
3 changed files with 47 additions and 42 deletions

View File

@ -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}};

View File

@ -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(

View File

@ -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, [""]);
})
})
});
});
});