Skip to content

Commit

Permalink
fix: make functional tests pass with deno (#7)
Browse files Browse the repository at this point in the history
* Ported functional tests (`test/functional/**/*.ts`) to deno
* Some problems still remain.
  * #13 
  * #14
* Some test codes related to `CockroachDriver` and `PostgresDriver` are temporarily commented out.
  • Loading branch information
uki00a authored Feb 16, 2020
1 parent 6ed1729 commit 7f3c048
Show file tree
Hide file tree
Showing 818 changed files with 7,655 additions and 6,006 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- name: Run tests
run: |
cp ./ormconfig.gh-actions.json ./ormconfig.json
deno run --allow-read --allow-write --config ./tsconfig.json ./test.ts
deno run --allow-read --allow-write --allow-env --config ./tsconfig.json ./test.ts
4 changes: 2 additions & 2 deletions ormconfig.gh-actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"skip": false,
"name": "sqlite",
"type": "sqlite",
"database": "temp/sqlitedb.db",
"logging": true
"database": ":memory:",
"logging": false
}
]
16 changes: 10 additions & 6 deletions src/connection/ConnectionOptionsReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export class ConnectionOptionsReader {
connectionOptions = new ConnectionOptionsEnvReader().read();

} else if (foundFileFormat === "js") {
connectionOptions = await PlatformTools.load(configFile);
const mod = await import(configFile);
connectionOptions = await mod.default;

} else if (foundFileFormat === "ts") {
connectionOptions = await PlatformTools.load(configFile);
const mod = await import(configFile);
connectionOptions = await mod.default;

} else if (foundFileFormat === "json") {
connectionOptions = PlatformTools.load(configFile);
Expand Down Expand Up @@ -197,10 +199,12 @@ export class ConnectionOptionsReader {
* Gets directory where configuration file should be located.
*/
protected get baseDirectory(): string {
if (this.options && this.options.root)
return this.options.root;

return PlatformTools.load("app-root-path").path;
const baseDirectory = this.options && this.options.root
? this.options.root
: PlatformTools.load("app-root-path").path;
return baseDirectory.endsWith('/')
? baseDirectory.slice(0, -1)
: baseDirectory;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/driver/sqlite/SqliteQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class SqliteQueryRunner extends AbstractSqliteQueryRunner {
await this.saveDatabaseToFileIfNeeded(databaseConnection, query);
return result;
} catch (err) {
console.error(err)
connection.logger.logQueryError(err, query, parameters, this);
throw new QueryFailedError(query, parameters, err);
}
Expand Down
3 changes: 2 additions & 1 deletion src/driver/types/ColumnTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ export type ColumnType = WithPrecisionColumnType
|BooleanConstructor
|DateConstructor
|NumberConstructor
|StringConstructor;
|StringConstructor
|Uint8ArrayConstructor; // TODO(uki001) This type is not fully tested yet.
8 changes: 8 additions & 0 deletions src/platform/PlatformTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export class PlatformTools {
return Deno.env()[name];
}

static encodeToBase64(string: string): string {
return window.btoa(string);
}

static decodeFromBase64(base64: string): string {
return window.atob(base64);
}

// TODO(uki00a) implement this method.
/**
* Highlights sql string to be print in the console.
Expand Down
252 changes: 252 additions & 0 deletions test.ts

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions test/deps/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import "https://unpkg.com/[email protected]/mocha.js";
mocha.setup({ ui: 'bdd', reporter: 'spec' });

export function runTests(): void {
mocha.run();
mocha.run(onCompleted);
}

export function runIfMain(meta: ImportMeta): void {
if (meta.main) {
mocha.run();
mocha.run(onCompleted);
}
}

mocha.timeout(60000);

function onCompleted(failures: number): void {
if (failures > 0) {
Deno.exit(1);
} else {
Deno.exit(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import "reflect-metadata";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {PostDetails} from "./entity/PostDetails";
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 {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: [__dirname + "/entity/*{.js,.ts}"],
entities: [join(__dirname, "/entity/*.ts")]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand All @@ -35,7 +38,7 @@ describe("cascades > should insert by cascades from both sides (#57)", () => {
}
});

posts.should.be.eql([{
expect(posts).to.eql([{
key: post1.key,
title: post1.title,
details: {
Expand All @@ -46,3 +49,5 @@ describe("cascades > should insert by cascades from both sides (#57)", () => {
})));

});

runIfMain(import.meta);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Entity} from "../../../../../src/decorator/entity/Entity";
import {Column} from "../../../../../src/decorator/columns/Column";
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn";
import {PostDetails} from "./PostDetails";
import {OneToOne} from "../../../../../src/decorator/relations/OneToOne";
import {JoinColumn} from "../../../../../src/decorator/relations/JoinColumn";
import {Entity} from "../../../../../src/decorator/entity/Entity.ts";
import {Column} from "../../../../../src/decorator/columns/Column.ts";
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";
import {PostDetails} from "./PostDetails.ts";
import {OneToOne} from "../../../../../src/decorator/relations/OneToOne.ts";
import {JoinColumn} from "../../../../../src/decorator/relations/JoinColumn.ts";

@Entity()
export class Post {
Expand All @@ -17,7 +17,7 @@ export class Post {
@JoinColumn()
details: PostDetails;

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

}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Entity} from "../../../../../src/decorator/entity/Entity";
import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn";
import {Post} from "./Post";
import {OneToOne} from "../../../../../src/decorator/relations/OneToOne";
import {Entity} from "../../../../../src/decorator/entity/Entity.ts";
import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn.ts";
import {Post} from "./Post.ts";
import {OneToOne} from "../../../../../src/decorator/relations/OneToOne.ts";

@Entity()
export class PostDetails {

@PrimaryColumn()
@PrimaryColumn({ type: String })
keyword: string;

@OneToOne(type => Post, post => post.details, {
cascade: ["insert"]
})
post: Post;

}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../../../src/connection/Connection";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {SimplePost} from "./entity/SimplePost";
import {SimpleCounters} from "./entity/SimpleCounters";
import {Information} from "./entity/Information";
import {Post} from "./entity/Post";
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 {SimplePost} from "./entity/SimplePost.ts";
import {SimpleCounters} from "./entity/SimpleCounters.ts";
import {Information} from "./entity/Information.ts";
import {Post} from "./entity/Post.ts";

describe("columns > embedded columns", () => {

let connections: Connection[];
const __dirname = getDirnameOfCurrentModule(import.meta);
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
entities: [joinPaths(__dirname, "/entity/*.ts")],
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand Down Expand Up @@ -132,3 +134,5 @@ describe("columns > embedded columns", () => {
]);
})));
});

runIfMain(import.meta);
10 changes: 5 additions & 5 deletions test/functional/columns/embedded-columns/entity/Counters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Column } from "../../../../../src/decorator/columns/Column";
import { Information } from "./Information";
import { Column } from "../../../../../src/decorator/columns/Column.ts";
import { Information } from "./Information.ts";

export class Counters {
@Column()
@Column({ type: Number })
likes: number;

@Column()
@Column({ type: Number })
comments: number;

@Column()
@Column({ type: Number })
favorites: number;

@Column(type => Information, { prefix: "info" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column } from "../../../../../src/decorator/columns/Column";
import { Column } from "../../../../../src/decorator/columns/Column.ts";

export class Information {

@Column({ name: "descr" })
@Column({ name: "descr", type: String })
description: string;
}
12 changes: 6 additions & 6 deletions test/functional/columns/embedded-columns/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Entity } from "../../../../../src/decorator/entity/Entity";
import { Column } from "../../../../../src/decorator/columns/Column";
import { PrimaryGeneratedColumn } from "../../../../../src/decorator/columns/PrimaryGeneratedColumn";
import { Counters } from "./Counters";
import { Entity } from "../../../../../src/decorator/entity/Entity.ts";
import { Column } from "../../../../../src/decorator/columns/Column.ts";
import { PrimaryGeneratedColumn } from "../../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";
import { Counters } from "./Counters.ts";

@Entity()
export class Post {

@PrimaryGeneratedColumn()
id: number;

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

@Column()
@Column({ type: String })
text: string;

@Column(type => Counters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Column } from "../../../../../src/decorator/columns/Column";
import { Information } from "./Information";
import { Column } from "../../../../../src/decorator/columns/Column.ts";
import { Information } from "./Information.ts";

export class SimpleCounters {

@Column()
@Column({ type: Number })
likes: number;

@Column()
@Column({ type: Number })
comments: number;

@Column()
@Column({ type: Number })
favorites: number;

@Column(type => Information, { prefix: "info" })
Expand Down
12 changes: 6 additions & 6 deletions test/functional/columns/embedded-columns/entity/SimplePost.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Entity } from "../../../../../src/decorator/entity/Entity";
import { Column } from "../../../../../src/decorator/columns/Column";
import { PrimaryGeneratedColumn } from "../../../../../src/decorator/columns/PrimaryGeneratedColumn";
import { SimpleCounters } from "./SimpleCounters";
import { Entity } from "../../../../../src/decorator/entity/Entity.ts";
import { Column } from "../../../../../src/decorator/columns/Column.ts";
import { PrimaryGeneratedColumn } from "../../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";
import { SimpleCounters } from "./SimpleCounters.ts";

@Entity()
export class SimplePost {

@PrimaryGeneratedColumn()
id: number;

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

@Column()
@Column({ type: String })
text: string;

@Column(type => SimpleCounters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "reflect-metadata";
import {expect} from "chai";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {runIfMain} from "../../../deps/mocha.ts";
import {expect} from "../../../deps/chai.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {Connection} from "../../../../src/connection/Connection.ts";
import {Post} from "./entity/Post.ts";

describe("columns > getters and setters", () => {

Expand Down Expand Up @@ -34,3 +34,5 @@ describe("columns > getters and setters", () => {


});

runIfMain(import.meta);
10 changes: 5 additions & 5 deletions test/functional/columns/getters-setters/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Entity} from "../../../../../src/decorator/entity/Entity";
import {Column} from "../../../../../src/decorator/columns/Column";
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn";
import {Entity} from "../../../../../src/decorator/entity/Entity.ts";
import {Column} from "../../../../../src/decorator/columns/Column.ts";
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn.ts";

@Entity()
export class Post {
Expand All @@ -19,9 +19,9 @@ export class Post {
}
}

@Column()
@Column({ type: String })
get title(): string {
return this._title;
}

}
}
12 changes: 7 additions & 5 deletions test/functional/columns/no-select/columns-no-select.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "reflect-metadata";
import {expect} from "chai";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {runIfMain} from "../../../deps/mocha.ts";
import {expect} from "../../../deps/chai.ts";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils.ts";
import {Connection} from "../../../../src/connection/Connection.ts";
import {Post} from "./entity/Post.ts";

describe("columns > no-selection functionality", () => {

Expand Down Expand Up @@ -72,3 +72,5 @@ describe("columns > no-selection functionality", () => {
})));

});

runIfMain(import.meta);
Loading

0 comments on commit 7f3c048

Please sign in to comment.