Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Add support for JSON output as well as a consolidated ResultWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
Suchita Doshi committed Dec 19, 2019
1 parent 97f5c7c commit be200ba
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 39 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"p-map": "^3.0.0"
},
"devDependencies": {
"@babel/traverse": "^7.7.4",
"@babel/types": "7.6.1",
"@ember/optional-features": "^0.7.0",
"@types/babel__traverse": "^7.0.7",
Expand Down
6 changes: 3 additions & 3 deletions src/checkup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IUserInterface, IProject, ITaskConstructor, IOptions, ITaskResult } from './interfaces';
import TaskList from './task-list';
import * as DefaultTasks from './tasks';
import ResultConsoleWriter from './utils/result-console-writer';
import ResultWriter from './utils/result-writer';
import Clock from './utils/clock';

const DEFAULT_TASKS = <ITaskConstructor[]>(
Expand Down Expand Up @@ -62,9 +62,9 @@ export default class Checkup {
this.ui.stopProgress();

if (!this.options.silent) {
let writer = new ResultConsoleWriter(taskResults);
let writer = new ResultWriter(taskResults);

writer.write();
writer.toConsole();
writer.writeDuration(clock.duration);
}

Expand Down
7 changes: 2 additions & 5 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ export interface IProject {
root: string;
}

export interface IResultConsoleWriter {
write: () => void;
}

export interface ISearchTraverser<T> {
hasResults: boolean;
results: T;
Expand Down Expand Up @@ -104,7 +100,8 @@ export interface ITaskList {
}

export interface ITaskResult {
write: (writer: IConsoleWriter) => void;
toConsole: (writer: IConsoleWriter) => void;
toJson: () => {};
}

export interface ITestMetrics {
Expand Down
12 changes: 10 additions & 2 deletions src/results/dependencies-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ export default class DependenciesTaskResult implements ITaskResult {
this.emberLibraries = {};
}

write(writer: IConsoleWriter) {
writer.heading('Depedencies');
toConsole(writer: IConsoleWriter) {
writer.heading('Dependencies');
writer.table('Ember Core Libraries', this.emberLibraries);
writer.line();

writer.table('Ember Addons', this.emberAddons.dependencies);
writer.table('Ember CLI Addons', this.emberCliAddons.dependencies);
writer.line();
}

toJson() {
return {
emberLibraries: this.emberLibraries,
emberAddons: this.emberAddons,
emberCliAddons: this.emberCliAddons,
};
}
}
6 changes: 5 additions & 1 deletion src/results/project-info-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class ProjectInfoTaskResult implements ITaskResult {
name!: string;
version!: string;

write(writer: IConsoleWriter) {
toConsole(writer: IConsoleWriter) {
writer.heading('Project Information');
writer.column({
Name: this.name,
Expand All @@ -14,4 +14,8 @@ export default class ProjectInfoTaskResult implements ITaskResult {
});
writer.line();
}

toJson() {
return { name: this.name, type: this.type, version: this.version };
}
}
6 changes: 5 additions & 1 deletion src/results/tests-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ export default class TestsTaskResult implements ITaskResult {
}
}

write(writer: IConsoleWriter) {
toConsole(writer: IConsoleWriter) {
writer.heading('Implement Me!');
writer.line();
}

toJson() {
return this.basic;
}
}
6 changes: 5 additions & 1 deletion src/results/types-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import getTaskItemTotals from '../utils/get-task-item-totals';
export default class TypesTaskResult implements ITaskResult {
types!: ITaskItemData;

write(writer: IConsoleWriter) {
toConsole(writer: IConsoleWriter) {
writer.heading('Types');
writer.table(['Type', 'Total Count'], getTaskItemTotals(this.types));
writer.line();
}

toJson() {
return this.types;
}
}
6 changes: 5 additions & 1 deletion src/tests/unit/checkup-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ class FakeTaskResult implements ITaskResult {
name!: string;
version!: string;

write(writer: IConsoleWriter) {
toConsole(writer: IConsoleWriter) {
writer.line();
}

toJson() {
return { name: this.name, version: this.version };
}
}

class FakeTask extends Task implements ITask {
Expand Down
20 changes: 20 additions & 0 deletions src/tests/unit/tests-task-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ module('tests-task', function(hooks) {
assert.equal(unitData.moduleCount, 2, 'unit module count is correct');
assert.equal(unitData.skipCount, 1, 'unit skip count is correct');
assert.equal(unitData.testCount, 2, 'unit test count is correct');

// @TODO: Make this as a separate test once the test fixtures are in defined in a separate file
const expectedJsonResult = {
application: { moduleCount: 0, skipCount: 0, testCount: 0 },
container: { moduleCount: 0, skipCount: 0, testCount: 0 },
rendering: { moduleCount: 0, skipCount: 0, testCount: 0 },
unit: { moduleCount: 2, skipCount: 1, testCount: 2 },
};

assert.deepEqual(result.toJson(), expectedJsonResult, 'toJson output is correct');
});

test('it finds container tests', async function(assert) {
Expand Down Expand Up @@ -746,6 +756,16 @@ module('tests-task', function(hooks) {
assert.equal(unitData.moduleCount, 1, 'unit module count is correct');
assert.equal(unitData.skipCount, 1, 'unit skip count is correct');
assert.equal(unitData.testCount, 2, 'unit test count is correct');

// @TODO: Make this as a separate test once the test fixtures are in defined in a separate file
const expectedJsonResult = {
application: { moduleCount: 2, skipCount: 1, testCount: 2 },
container: { moduleCount: 1, skipCount: 0, testCount: 2 },
rendering: { moduleCount: 1, skipCount: 0, testCount: 1 },
unit: { moduleCount: 1, skipCount: 1, testCount: 2 },
};

assert.deepEqual(result.toJson(), expectedJsonResult, 'toJson output is correct');
});
});
});
34 changes: 34 additions & 0 deletions src/tests/unit/types-task-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,39 @@ module('types-task', function(hooks) {
assert.equal(typesTaskResult.types.routes.length, 2);
assert.equal(typesTaskResult.types.services.length, 2);
assert.equal(typesTaskResult.types.templates.length, 2);

// @TODO: Make this as a separate test once the test fixtures are in defined in a separate file
const expectedJsonResult = {
components: [
'addon/components/my-component.js',
'lib/ember-super-button/addon/components/my-component.js',
],
controllers: [
'addon/controllers/my-controller.js',
'lib/ember-super-button/addon/controllers/my-controller.js',
],
helpers: ['addon/helpers/my-helper.js', 'lib/ember-super-button/addon/helpers/my-helper.js'],
initializers: [
'addon/initializers/my-initializer.js',
'lib/ember-super-button/addon/initializers/my-initializer.js',
],
'instance-initializers': [
'addon/instance-initializers/my-helper.js',
'lib/ember-super-button/addon/instance-initializers/my-helper.js',
],
mixins: ['addon/mixins/my-mixin.js', 'lib/ember-super-button/addon/mixins/my-mixin.js'],
models: ['addon/models/my-model.js', 'lib/ember-super-button/addon/models/my-model.js'],
routes: ['addon/routes/my-route.js', 'lib/ember-super-button/addon/routes/my-route.js'],
services: [
'addon/services/my-service.js',
'lib/ember-super-button/addon/services/my-service.js',
],
templates: [
'addon/templates/my-component.hbs',
'lib/ember-super-button/addon/templates/my-component.hbs',
],
};

assert.deepEqual(typesTaskResult.toJson(), expectedJsonResult, 'toJson output is correct');
});
});
15 changes: 15 additions & 0 deletions src/tests/unit/utils/mock-console.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class MockConsole {
_buffer: string[];
log: (message: string) => void;

constructor() {
this._buffer = [];
this.log = message => {
this._buffer.push(message);
};
}

toString() {
return this._buffer.join('\n');
}
}
Loading

0 comments on commit be200ba

Please sign in to comment.