Skip to content

Commit 785bc6b

Browse files
committedApr 4, 2022
fix: package.json
1 parent a4019a5 commit 785bc6b

File tree

4 files changed

+110
-8
lines changed

4 files changed

+110
-8
lines changed
 

‎README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# TypeORM Codebase Sync
22
Automatically update your codebase to add migrations, entities and subscribers to your `data-source.ts` file
33

4-
[![codecov](https://badgen.net/codecov/c/github/giladgd/typeorm-codebase-sync)](https://codecov.io/gh/giladgd/typeorm-codebase-sync)
4+
[![codecov](https://codecov.io/gh/giladgd/typeorm-codebase-sync/branch/master/graph/badge.svg)](https://codecov.io/gh/giladgd/typeorm-codebase-sync)
55
[![Test](https://github.com/giladgd/typeorm-codebase-sync/actions/workflows/test.yml/badge.svg)](https://github.com/giladgd/typeorm-codebase-sync/actions/workflows/test.yml)
6-
[![Downloads](https://badgen.net/npm/dt/typeorm-codebase-sync)](https://www.npmjs.com/package/typeorm-codebase-sync)
7-
[![License](https://badgen.net/npm/license/typeorm-codebase-sync)](https://www.npmjs.com/package/typeorm-codebase-sync)
86
[![Version](https://badgen.net/npm/v/typeorm-codebase-sync)](https://www.npmjs.com/package/typeorm-codebase-sync)
7+
[![License](https://badgen.net/npm/license/typeorm-codebase-sync)](https://www.npmjs.com/package/typeorm-codebase-sync)
98

109

1110
## Installation

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typeorm-codebase-sync",
3-
"version": "0.3.0",
3+
"version": "1.0.0",
44
"description": "Automatically update your codebase to add migrations, entities and subscribers to your `data-source.ts` file",
55
"main": "dist/index.js",
66
"type": "module",
@@ -23,7 +23,7 @@
2323
"test:mocha": "mocha --bail",
2424
"test:typescript": "tsc --build tsconfig.json --dry --force",
2525
"test:eslint": "eslint --ext .js --ext .ts .",
26-
"test:coverage": "c8 mocha",
26+
"coverage": "c8 mocha",
2727
"format": "npm run test:eslint -- --fix",
2828
"clean": "rm -rf ./node_modules ./dist ./tsconfig.tsbuildinfo"
2929
},

‎test/commands/AddReferencesCommand.test.ts

+104-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
7575
7676
expect(dataSourceResult).to.haveOwnProperty("AppDataSource");
7777
expect(dataSourceResult.AppDataSource).to.haveOwnProperty("options");
78-
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
7978
8079
${testCode}
8180
`);
@@ -125,6 +124,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
125124
`
126125
}],
127126
testCode: `
127+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
128+
128129
const entities: any = dataSourceResult.AppDataSource.options.entities;
129130
expect(entities).to.be.an("array");
130131
expect(entities.length).to.be.gt(0);
@@ -181,6 +182,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
181182
`
182183
}],
183184
testCode: `
185+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
186+
184187
const entities: any = dataSourceResult.AppDataSource.options.entities;
185188
expect(entities).to.be.an("array");
186189
expect(entities.length).to.be.gt(0);
@@ -229,6 +232,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
229232
`
230233
}],
231234
testCode: `
235+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
236+
232237
const entities: any = dataSourceResult.AppDataSource.options.entities;
233238
expect(entities).to.be.an("array");
234239
expect(entities.length).to.be.gt(0);
@@ -277,6 +282,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
277282
`
278283
}],
279284
testCode: `
285+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
286+
280287
const entities: any = dataSourceResult.AppDataSource.options.entities;
281288
expect(entities).to.be.an("array");
282289
expect(entities.length).to.be.gt(0);
@@ -286,4 +293,100 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
286293
`
287294
});
288295
});
296+
297+
it("should add migration from folder", async () => {
298+
await testDataSourceFile({
299+
dataSourceCode: `
300+
import { migrations } from "./migrations.js"
301+
302+
export const AppDataSource = new DataSource({
303+
type: "sqlite",
304+
database: "database.db",
305+
migrations: migrations
306+
});
307+
`,
308+
commandParams: {
309+
dataSource: "data-source.ts",
310+
migrations: ["migrations"]
311+
},
312+
files: [{
313+
path: "migrations.ts",
314+
content: `
315+
import { SomeMigration } from "./migrations/SomeMigration.js";
316+
317+
export const migrations = [
318+
SomeMigration
319+
];
320+
`
321+
}, {
322+
path: "migrations/SomeMigration.ts",
323+
content: `
324+
export class SomeMigration {}
325+
`
326+
}, {
327+
path: "migrations/Migration2.ts",
328+
content: `
329+
export class Migration2 {}
330+
`
331+
}],
332+
testCode: `
333+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("migrations");
334+
335+
const migrations: any = dataSourceResult.AppDataSource.options.migrations;
336+
expect(migrations).to.be.an("array");
337+
expect(migrations.length).to.be.gt(0);
338+
const migrationNames = migrations.map((migration: any) => migration.name);
339+
expect(migrationNames).to.include("Migration2");
340+
expect(migrationNames).to.include("SomeMigration");
341+
`
342+
});
343+
});
344+
345+
it("should add subscriber from folder", async () => {
346+
await testDataSourceFile({
347+
dataSourceCode: `
348+
import { subscribers } from "./subscribers.js"
349+
350+
export const AppDataSource = new DataSource({
351+
type: "sqlite",
352+
database: "database.db",
353+
subscribers: subscribers
354+
});
355+
`,
356+
commandParams: {
357+
dataSource: "data-source.ts",
358+
subscribers: ["subscribers"]
359+
},
360+
files: [{
361+
path: "subscribers.ts",
362+
content: `
363+
import { SomeSubscriber } from "./subscribers/SomeSubscriber.js";
364+
365+
export const subscribers = [
366+
SomeSubscriber
367+
];
368+
`
369+
}, {
370+
path: "subscribers/SomeSubscriber.ts",
371+
content: `
372+
export class SomeSubscriber {}
373+
`
374+
}, {
375+
path: "subscribers/Subscriber2.ts",
376+
content: `
377+
export class Subscriber2 {}
378+
`
379+
}],
380+
testCode: `
381+
expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("subscribers");
382+
383+
const subscribers: any = dataSourceResult.AppDataSource.options.subscribers;
384+
expect(subscribers).to.be.an("array");
385+
expect(subscribers.length).to.be.gt(0);
386+
const subscriberNames = subscribers.map((subscriber: any) => subscriber.name);
387+
expect(subscriberNames).to.include("Subscriber2");
388+
expect(subscriberNames).to.include("SomeSubscriber");
389+
`
390+
});
391+
});
289392
});

0 commit comments

Comments
 (0)
Please sign in to comment.