-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(html-reporter): Remove side effects from html reporter (#1314)
Remove use of `ReporterFactory.instance().register()` from html-reporter, instead exporting it in `strykerPlugins` array.
- Loading branch information
Showing
14 changed files
with
110 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { ReporterFactory } from 'stryker-api/report'; | ||
import HtmlReporter from './HtmlReporter'; | ||
import { PluginKind, declareClassPlugin } from 'stryker-api/plugin'; | ||
|
||
ReporterFactory.instance().register('html', HtmlReporter); | ||
export const strykerPlugins = [ | ||
declareClassPlugin(PluginKind.Reporter, 'html', HtmlReporter) | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as sinon from 'sinon'; | ||
import { testInjector } from '@stryker-mutator/test-helpers'; | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
testInjector.reset(); | ||
}); |
30 changes: 0 additions & 30 deletions
30
packages/stryker-html-reporter/test/helpers/loggingMock.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...ter/test/integration/StrykerReportSpec.ts → ...test/integration/StrykerReport.it.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...est/integration/singleFileInFolderSpec.ts → ...integration/singleFileInFolder.it.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 6 additions & 10 deletions
16
packages/stryker-html-reporter/test/unit/HtmlReporter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
"references": [ | ||
{ | ||
"path": "./tsconfig.src.json" | ||
}, | ||
{ | ||
"path": "../stryker-test-helpers/tsconfig.src.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Plugin, PluginKind, PluginContexts, Plugins, PluginInterfaces, FactoryPlugin, ClassPlugin } from 'stryker-api/plugin'; | ||
import { Injector, InjectionToken } from 'typed-inject'; | ||
|
||
export function createPlugin<TPluginKind extends PluginKind>(kind: TPluginKind, plugin: Plugins[TPluginKind], injector: Injector<PluginContexts[TPluginKind]>): | ||
PluginInterfaces[TPluginKind] { | ||
if (isFactoryPlugin(plugin)) { | ||
return injector.injectFunction(plugin.factory); | ||
} else if (isClassPlugin(plugin)) { | ||
return injector.injectClass(plugin.injectableClass); | ||
} else { | ||
throw new Error(`Plugin "${kind}:${plugin.name}" could not be created, missing "factory" or "injectableClass" property.`); | ||
} | ||
} | ||
|
||
function isFactoryPlugin<TPluginKind extends PluginKind>(plugin: Plugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]>): | ||
plugin is FactoryPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]> { | ||
return !!(plugin as FactoryPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]>).factory; | ||
} | ||
function isClassPlugin<TPluginKind extends PluginKind>(plugin: Plugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]>): | ||
plugin is ClassPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]> { | ||
return !!(plugin as ClassPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]>).injectableClass; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createPlugin } from '../../../src/di/createPlugin'; | ||
import { PluginKind, FactoryPlugin, ClassPlugin } from 'stryker-api/plugin'; | ||
import { factory, testInjector } from '@stryker-mutator/test-helpers'; | ||
import { expect } from 'chai'; | ||
|
||
describe('createPlugin', () => { | ||
it('should create a FactoryPlugin using it\'s factory method', () => { | ||
const expectedReporter = factory.reporter(); | ||
const plugin: FactoryPlugin<PluginKind.Reporter, []> = { | ||
kind: PluginKind.Reporter, | ||
name: 'fooReporter', | ||
factory() { | ||
return expectedReporter; | ||
} | ||
}; | ||
const actualReporter = createPlugin(PluginKind.Reporter, plugin, testInjector.injector); | ||
expect(actualReporter).eq(expectedReporter); | ||
}); | ||
|
||
it('should create a ClassPlugin using it\'s constructor', () => { | ||
class FooReporter { | ||
} | ||
const plugin: ClassPlugin<PluginKind.Reporter, []> = { | ||
injectableClass: FooReporter, | ||
kind: PluginKind.Reporter, | ||
name: 'fooReporter' | ||
}; | ||
const actualReporter = createPlugin(PluginKind.Reporter, plugin, testInjector.injector); | ||
expect(actualReporter).instanceOf(FooReporter); | ||
}); | ||
|
||
it('should throw if plugin is not recognized', () => { | ||
expect(() => createPlugin(PluginKind.Reporter, { name: 'foo' } as any, testInjector.injector)) | ||
.throws('Plugin "Reporter:foo" could not be created, missing "factory" or "injectableClass" property.'); | ||
}); | ||
}); |