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

Add support for JSON output as well as a consolidated ResultWriter #161

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 12 additions & 2 deletions src/results/dependencies-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ 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 {
dependencies: {
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 { tests: 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 { types: 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
24 changes: 24 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,18 @@ 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 = {
tests: {
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 +758,18 @@ 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 = {
tests: {
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');
});
});
});
39 changes: 39 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,44 @@ 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 = {
types: {
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