Skip to content

Commit

Permalink
fix(cli): print both entities and entitiesTs in debug command
Browse files Browse the repository at this point in the history
Closes #1139
  • Loading branch information
B4nan committed Nov 29, 2020
1 parent b38df3e commit 90b85e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
25 changes: 24 additions & 1 deletion packages/cli/src/commands/DebugCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,36 @@ export class DebugCommand implements CommandModule {
try {
const config = await CLIHelper.getConfiguration();
CLIHelper.dump(` - configuration ${c.green('found')}`);
const tsNode = config.get('tsNode');

if ([true, false].includes(tsNode as boolean)) {
const warning = tsNode ? ' (this value should be set to `false` when running compiled code!)' : '';
CLIHelper.dump(` - \`tsNode\` flag explicitly set to ${tsNode}, will use \`entities${tsNode ? 'Ts' : ''}\` array${warning}`);
}

const entities = config.get('entities', []);

if (entities.length > 0) {
const refs = entities.filter(p => !Utils.isString(p));
const paths = entities.filter(p => Utils.isString(p));
CLIHelper.dump(` - will use \`entities\` array (contains ${refs.length} references and ${paths.length} paths)`);
const will = !config.get('tsNode') ? 'will' : 'could';
CLIHelper.dump(` - ${will} use \`entities\` array (contains ${refs.length} references and ${paths.length} paths)`);

if (paths.length > 0) {
await DebugCommand.checkPaths(paths, 'red', config.get('baseDir'), true);
}
}

const entitiesTs = config.get('entitiesTs', []);

if (entitiesTs.length > 0) {
const refs = entitiesTs.filter(p => !Utils.isString(p));
const paths = entitiesTs.filter(p => Utils.isString(p));
/* istanbul ignore next */
const will = config.get('tsNode') ? 'will' : 'could';
CLIHelper.dump(` - ${will} use \`entitiesTs\` array (contains ${refs.length} references and ${paths.length} paths)`);

/* istanbul ignore else */
if (paths.length > 0) {
await DebugCommand.checkPaths(paths, 'red', config.get('baseDir'), true);
}
Expand Down
16 changes: 11 additions & 5 deletions tests/cli/DebugCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('DebugCommand', () => {

getSettings.mockResolvedValue({ useTsNode: true });
globbyMock.mockImplementation(async (path: string) => path.endsWith('entities-1') || path.endsWith('orm-config.ts'));
getConfiguration.mockResolvedValue(new Configuration({ type: 'mongo', entities: ['./entities-1', './entities-2'] } as any, false));
getConfiguration.mockResolvedValue(new Configuration({ type: 'mongo', tsNode: true, entities: ['./dist/entities-1', './dist/entities-2'], entitiesTs: ['./src/entities-1', './src/entities-2'] } as any, false));
dump.mock.calls.length = 0;
await expect(cmd.handler()).resolves.toBeUndefined();
expect(dumpDependencies).toBeCalledTimes(2);
Expand All @@ -47,12 +47,16 @@ describe('DebugCommand', () => {
[' - searched config paths:'],
[` - ${Utils.normalizePath(process.cwd() + '/path/orm-config.ts') } (found)`],
[' - configuration found'],
[' - will use `entities` array (contains 0 references and 2 paths)'],
[` - ${Utils.normalizePath(process.cwd() + '/entities-1') } (found)`],
[` - ${Utils.normalizePath(process.cwd() + '/entities-2') } (not found)`],
[' - `tsNode` flag explicitly set to true, will use `entitiesTs` array (this value should be set to `false` when running compiled code!)'],
[' - could use `entities` array (contains 0 references and 2 paths)'],
[` - ${Utils.normalizePath(process.cwd() + '/dist/entities-1') } (found)`],
[` - ${Utils.normalizePath(process.cwd() + '/dist/entities-2') } (not found)`],
[' - will use `entitiesTs` array (contains 0 references and 2 paths)'],
[` - ${Utils.normalizePath(process.cwd() + '/src/entities-1') } (found)`],
[` - ${Utils.normalizePath(process.cwd() + '/src/entities-2') } (not found)`],
]);

getConfiguration.mockResolvedValue(new Configuration({ type: 'mongo', entities: [FooBar, FooBaz] } as any, false));
getConfiguration.mockResolvedValue(new Configuration({ type: 'mongo', tsNode: false, entities: [FooBar, FooBaz] } as any, false));
dump.mock.calls.length = 0;
await expect(cmd.handler()).resolves.toBeUndefined();
expect(dumpDependencies).toBeCalledTimes(3);
Expand All @@ -62,6 +66,7 @@ describe('DebugCommand', () => {
[' - searched config paths:'],
[` - ${Utils.normalizePath(process.cwd() + '/path/orm-config.ts') } (found)`],
[' - configuration found'],
[' - `tsNode` flag explicitly set to false, will use `entities` array'],
[' - will use `entities` array (contains 2 references and 0 paths)'],
]);

Expand All @@ -87,6 +92,7 @@ describe('DebugCommand', () => {
[' - searched config paths:'],
[` - ${Utils.normalizePath(process.cwd() + '/path/orm-config.ts') } (not found)`],
[' - configuration found'],
[' - `tsNode` flag explicitly set to false, will use `entities` array'],
[' - will use `entities` array (contains 2 references and 0 paths)'],
]);
globbyMock.mockRestore();
Expand Down

0 comments on commit 90b85e4

Please sign in to comment.