-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathtest-initialization-service.ts
70 lines (61 loc) · 2.21 KB
/
test-initialization-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as path from "path";
import * as fs from "fs";
import { cache } from "../common/decorators";
import { ITestInitializationService } from "../definitions/project";
import {
IErrors,
IFileSystem,
IDependencyInformation,
} from "../common/declarations";
import * as _ from "lodash";
import { injector } from "../common/yok";
export class TestInitializationService implements ITestInitializationService {
private configsPath = path.join(__dirname, "..", "..", "config");
constructor(private $errors: IErrors, private $fs: IFileSystem) {}
@cache()
public getDependencies(selectedFramework: string): IDependencyInformation[] {
const dependenciesPath = path.join(
this.configsPath,
"test-dependencies.json"
);
const allDependencies: {
name: string;
framework?: string;
excludedPeerDependencies?: string[];
}[] = this.$fs.readJson(dependenciesPath);
const dependenciesVersionsPath = path.join(
this.configsPath,
"test-deps-versions-generated.json"
);
const dependenciesVersions = this.$fs.readJson(dependenciesVersionsPath);
const targetFrameworkDependencies: IDependencyInformation[] = allDependencies
.filter(
(dependency) =>
!dependency.framework || dependency.framework === selectedFramework
)
.map((dependency) => {
const dependencyVersion = dependenciesVersions[dependency.name];
if (!dependencyVersion) {
this.$errors.fail(`'${dependency}' is not a registered dependency.`);
}
return { ...dependency, version: dependencyVersion };
});
return targetFrameworkDependencies;
}
/**
* This method is used from test-init.md file so it is not allowed to use "this" inside the method's body.
*/
@cache()
public getFrameworkNames(): string[] {
const configsPath = path.join(__dirname, "..", "..", "config");
const dependenciesPath = path.join(configsPath, "test-dependencies.json");
const allDependencies: { name: string; framework?: string }[] = JSON.parse(
fs.readFileSync(dependenciesPath, { encoding: "utf-8" })
);
const frameworks = _.uniqBy(allDependencies, "framework")
.map((item) => item && item.framework)
.filter((item) => item);
return frameworks;
}
}
injector.register("testInitializationService", TestInitializationService);