Skip to content

Commit

Permalink
test: stop dynamic importing of entities using the glob pattern (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Jun 18, 2020
1 parent e8ee237 commit 9a9de70
Show file tree
Hide file tree
Showing 396 changed files with 1,180 additions and 1,540 deletions.
3 changes: 3 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,7 @@ import "./test/other-issues/preventing-injection/preventing-injection.ts";
import "./test/other-issues/take-multiple-pk/take-multiple-pk.ts";
import "./test/other-issues/update-relational-column-on-relation-change/update-relational-column-on-relation-change.ts";

// Tests for denolib issues
import "./test/denolib-issues/70/issue-70.ts";

runTests();
20 changes: 20 additions & 0 deletions test/denolib-issues/70/entity/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Entity} from "../../../../src/decorator/entity/Entity.ts";
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";
import {Column} from "../../../../src/decorator/columns/Column.ts";
import {Post} from "./Post.ts";
import {OneToMany} from "../../../../src/decorator/relations/OneToMany.ts";

@Entity()
export class Category {

@PrimaryGeneratedColumn()
id!: number;

@Column({ type: String })
name!: string;

@OneToMany(() => Post, post => post.category, { lazy: true })
posts!: Promise<Post[]>;

}

23 changes: 23 additions & 0 deletions test/denolib-issues/70/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Entity} from "../../../../src/decorator/entity/Entity.ts";
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";
import {Column} from "../../../../src/decorator/columns/Column.ts";
import {Category} from "./Category.ts";
import {ManyToOne} from "../../../../src/decorator/relations/ManyToOne.ts";

@Entity()
export class Post {

@PrimaryGeneratedColumn()
id!: number;

@Column({ type: String })
title!: string;

@ManyToOne(() => Category, category => category.posts, {
cascade: ["insert"],
lazy: true
})
category!: Promise<Category>;

}

26 changes: 26 additions & 0 deletions test/denolib-issues/70/issue-70.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {join as joinPaths} from "../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../deps/mocha.ts";
import {expect} from "../../deps/chai.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils.ts";
import {Connection} from "../../../src/connection/Connection.ts";
import {Post} from "./entity/Post.ts";
import {Category} from "./entity/Category.ts";

describe("denolib issues > #70 dynamic imports of entities using the glob pattern", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should import entities that match the glob pattern", () => connections.map(connection => {
expect(connection.entityMetadatas).to.have.lengthOf(2);
expect(connection.entityMetadatas.find(x => x.target === Post)).not.to.be.undefined;
expect(connection.entityMetadatas.find(x => x.target === Category)).not.to.be.undefined;
}));
});

runIfMain(import.meta);
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {runIfMain} from "../../../deps/mocha.ts";
import {expect} from "../../../deps/chai.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {Connection} from "../../../../src/connection/Connection.ts";
import {Post} from "./entity/Post.ts";
import {PostDetails} from "./entity/PostDetails.ts";
import {join} from "../../../../vendor/https/deno.land/std/path/mod.ts"

describe("cascades > should insert by cascades from both sides (#57)", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => connections = await createTestingConnections({
entities: [join(__dirname, "/entity/*.ts")]
entities: [Post, PostDetails]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {expect} from "../../../deps/chai.ts";
import {runIfMain} from "../../../deps/mocha.ts";
import {Connection} from "../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {join as joinPaths} from "../../../../vendor/https/deno.land/std/path/mod.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {Counters} from "./entity/Counters.ts";
import {SimplePost} from "./entity/SimplePost.ts";
import {SimpleCounters} from "./entity/SimpleCounters.ts";
import {Information} from "./entity/Information.ts";
Expand All @@ -11,9 +11,8 @@ import {Post} from "./entity/Post.ts";
describe("columns > embedded columns", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Counters, Information, Post, SimpleCounters, SimplePost],
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand Down
5 changes: 1 addition & 4 deletions test/functional/cube/postgres/cube-postgres.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { join as joinPaths } from "../../../../vendor/https/deno.land/std/path/mod.ts";
import { runIfMain } from "../../../deps/mocha.ts";
import { expect } from "../../../deps/chai.ts";
import { Connection } from "../../../../src/connection/Connection.ts";
import {
getDirnameOfCurrentModule,
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases
Expand All @@ -12,11 +10,10 @@ import { Post } from "./entity/Post.ts";

// TODO(uki00a) We implement when this deno-postgres supports cube.
describe.skip("cube-postgres", () => {
const __dirname = getDirnameOfCurrentModule(import.meta);
let connections: Connection[];
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["postgres"]
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import "../../../../deps/chai.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";

describe("database schema > column collation > cockroach", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["cockroachdb"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";

describe("database schema > column collation > mssql", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["mssql"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";

describe("database schema > column collation > mysql", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["mysql"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";

describe("database schema > column collation > postgres", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["postgres"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";

// skipped because there is no way to get column collation from SQLite table schema
describe.skip("database schema > column collation > sqlite", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["sqlite"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts"
import "../../../../deps/chai.ts"
import {Connection} from "../../../../../src/index.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {Post} from "./entity/Post.ts";
import {PostWithOptions} from "./entity/PostWithOptions.ts";
import {PostWithoutTypes} from "./entity/PostWithoutTypes.ts";

describe("database schema > column types > cockroachdb", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
const encoder = new TextEncoder();
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post, PostWithOptions, PostWithoutTypes],
enabledDrivers: ["cockroachdb"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {PostWithOptions} from "./entity/PostWithOptions.ts";
import {PostWithoutTypes} from "./entity/PostWithoutTypes.ts";
import {DateUtils} from "../../../../../src/util/DateUtils.ts";
Expand All @@ -12,11 +11,10 @@ import {FruitEnum} from "./enum/FruitEnum.ts";
describe("database schema > column types > mssql", () => { // https://github.com/tediousjs/tedious/issues/722

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
const encoder = new TextEncoder();
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post, PostWithOptions, PostWithoutTypes],
enabledDrivers: ["mssql"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {PostWithOptions} from "./entity/PostWithOptions.ts";
import {PostWithoutTypes} from "./entity/PostWithoutTypes.ts";
import {FruitEnum} from "./enum/FruitEnum.ts";

describe("database schema > column types > mysql", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
const encoder = new TextEncoder();
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post, PostWithOptions, PostWithoutTypes],
enabledDrivers: ["mysql"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {Post} from "./entity/Post.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {PostWithOptions} from "./entity/PostWithOptions.ts";
import {PostWithoutTypes} from "./entity/PostWithoutTypes.ts";
import {DateUtils} from "../../../../../src/util/DateUtils.ts";

describe("database schema > column types > oracle", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
const encoder = new TextEncoder();
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post, PostWithOptions, PostWithoutTypes],
enabledDrivers: ["oracle"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import {expect} from "../../../../deps/chai.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {Post} from "./entity/Post.ts";
import {Table, TableColumn} from "../../../../../src/index.ts";

describe("database schema > column types > postgres-enum", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post],
enabledDrivers: ["postgres"],
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {join as joinPaths} from "../../../../../vendor/https/deno.land/std/path/mod.ts";
import {runIfMain} from "../../../../deps/mocha.ts";
import "../../../../deps/chai.ts";
import {PostWithOptions} from "./entity/PostWithOptions.ts";
import {Connection} from "../../../../../src/connection/Connection.ts";
import {getDirnameOfCurrentModule, closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../../utils/test-utils.ts";
import {PostWithoutTypes} from "./entity/PostWithoutTypes.ts";
import {Post} from "./entity/Post.ts";

describe("database schema > column types > postgres", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
const encoder = new TextEncoder();
before(async () => {
connections = await createTestingConnections({
entities: [joinPaths(__dirname, "/entity/*.ts")],
entities: [Post, PostWithOptions, PostWithoutTypes],
enabledDrivers: ["postgres"],
});
});
Expand Down
Loading

0 comments on commit 9a9de70

Please sign in to comment.