/
migrate-karma-conf.ts
58 lines (48 loc) · 1.67 KB
/
migrate-karma-conf.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
import type { Tree } from '@nrwl/devkit';
import {
addDependenciesToPackageJson,
joinPathFragments,
readProjectConfiguration,
formatFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
export default async function (tree: Tree) {
const executorName = '@angular-devkit/build-angular:karma';
forEachExecutorOptions(tree, executorName, ({ karmaConfig }, projectName) => {
const project = readProjectConfiguration(tree, projectName);
const pathToKarma = joinPathFragments(project.root, karmaConfig);
if (!tree.exists(pathToKarma)) {
return;
}
const karmaContents = tree.read(pathToKarma, 'utf-8');
const updatedKarmaContents = karmaContents.replace(
/coverageIstanbulReporter/g,
'coverageReporter'
);
tree.write(pathToKarma, updatedKarmaContents);
});
const pathToRootKarmaConf = 'karma.conf.js';
if (!tree.exists(pathToRootKarmaConf)) {
return;
}
const rootKarmaContents = tree.read(pathToRootKarmaConf, 'utf-8');
const updatedKarmaContents = rootKarmaContents
.replace(/coverageIstanbulReporter/g, 'coverageReporter')
.replace(/karma-coverage-istanbul-reporter/, 'karma-coverage')
.replace(
/reports: \[(.+)\]/,
`subdir: '.',\nreporters: [{ type: 'html' }, { type: 'text-summary' }]`
)
.replace(/'\.\.\/\.\.\/coverage'/, `'./coverage'`)
.replace(/fixWebpackSourcePaths: true,/, '');
tree.write(pathToRootKarmaConf, updatedKarmaContents);
const installPackages = addDependenciesToPackageJson(
tree,
{},
{
'karma-coverage': '~2.2.0',
}
);
await formatFiles(tree);
return installPackages;
}