1 | import KarmaConfigurationFactory from 'catela/test/karma/KarmaConfigurationFactory'
|
2 | import KarmaTestRunner from 'catela/test/karma/KarmaTestRunner'
|
3 | import path from 'path'
|
4 |
|
5 | class UnitTestSetup {
|
6 | constructor (options) {
|
7 | this._options = options
|
8 | this._application = options.application
|
9 | this._spec = options.spec
|
10 | this._rootProjectPath = options.projectPath
|
11 | this._rootApplicationPath = path.join(this._rootProjectPath, 'applications', this._application)
|
12 | this._testSpecFile = path.join(this._rootApplicationPath, this._spec)
|
13 | this._testServerPort = options.port
|
14 |
|
15 | let karmaConfigurationFactoryOptions = {
|
16 | rootProjectPath: this._rootProjectPath,
|
17 | rootApplicationPath: this._rootApplicationPath,
|
18 | application: this._application
|
19 | }
|
20 |
|
21 | this._karmaConfigurationFactory = new KarmaConfigurationFactory(karmaConfigurationFactoryOptions)
|
22 | this._karmaTestRunner = new KarmaTestRunner()
|
23 | }
|
24 |
|
25 | run () {
|
26 | console.log('=> rootProjectPath: ' + this._rootProjectPath)
|
27 | console.log('=> rootApplicationPath: ' + this._rootApplicationPath)
|
28 | console.log('=> testSpecFile: ' + this._testSpecFile)
|
29 |
|
30 | let testConfigurationSpec = {
|
31 | spec: this._testSpecFile,
|
32 | port: this._testServerPort
|
33 | }
|
34 | let configuration = this._karmaConfigurationFactory.createTestConfiguration(testConfigurationSpec)
|
35 | this._karmaTestRunner.run(configuration)
|
36 | }
|
37 | }
|
38 |
|
39 | export default UnitTestSetup
|