@front10/danger-plugins 0.11.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/danger-plugins.cjs.development.js +5 -245
- package/dist/danger-plugins.cjs.development.js.map +1 -1
- package/dist/danger-plugins.cjs.production.min.js +1 -1
- package/dist/danger-plugins.cjs.production.min.js.map +1 -1
- package/dist/danger-plugins.esm.js +6 -243
- package/dist/danger-plugins.esm.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/package.json +1 -4
- package/src/index.ts +0 -2
- package/CHANGELOG.md +0 -13
- package/dist/plugin-eslint.d.ts +0 -5
- package/dist/plugin-jest.d.ts +0 -7
- package/src/plugin-eslint.ts +0 -53
- package/src/plugin-jest.ts +0 -202
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "1.0.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -21,11 +21,8 @@
|
|
|
21
21
|
"author": "Rainer Martínez Fraga",
|
|
22
22
|
"module": "dist/danger-plugins.esm.js",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/eslint": "^7.2.6",
|
|
25
|
-
"@types/jest": "^26.0.19",
|
|
26
24
|
"@types/node-fetch": "^2.5.7",
|
|
27
25
|
"danger": "^10.5.4",
|
|
28
|
-
"eslint": "^7.16.0",
|
|
29
26
|
"tsdx": "^0.14.1",
|
|
30
27
|
"tslib": "^2.0.3",
|
|
31
28
|
"typescript": "^4.1.3"
|
package/src/index.ts
CHANGED
package/CHANGELOG.md
DELETED
package/dist/plugin-eslint.d.ts
DELETED
package/dist/plugin-jest.d.ts
DELETED
package/src/plugin-eslint.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { CLIEngine } from "eslint";
|
|
2
|
-
import { DangerDSLType } from "danger";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
|
|
5
|
-
declare const danger: DangerDSLType;
|
|
6
|
-
declare function fail(message?: string): void;
|
|
7
|
-
declare function warn(message?: string): void;
|
|
8
|
-
|
|
9
|
-
function getFileContents(path: string) {
|
|
10
|
-
if (danger.gitlab) {
|
|
11
|
-
return danger.gitlab.utils.fileContents(path);
|
|
12
|
-
} else if (danger.github) {
|
|
13
|
-
return danger.github.utils.fileContents(path);
|
|
14
|
-
}
|
|
15
|
-
return fs.readFileSync(path, "utf8");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function lintFile(linter: CLIEngine, _config: any, path: string) {
|
|
19
|
-
const contents = await getFileContents(path);
|
|
20
|
-
const report = linter.executeOnText(contents, path);
|
|
21
|
-
|
|
22
|
-
if (report.results.length) {
|
|
23
|
-
report.results[0].messages.map((msg) => {
|
|
24
|
-
if (msg.fatal) {
|
|
25
|
-
fail(`Fatal error linting ${path} with eslint.`);
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
if (msg.severity === 1 || msg.severity === 2) {
|
|
29
|
-
const fn = { 1: warn, 2: fail }[msg.severity];
|
|
30
|
-
|
|
31
|
-
fn(`${path} line ${msg.line} – ${msg.message} (${msg.ruleId})`);
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Eslint your code with Danger
|
|
40
|
-
*/
|
|
41
|
-
export async function eslint(
|
|
42
|
-
config: CLIEngine.Options["baseConfig"],
|
|
43
|
-
extensions?: string[]
|
|
44
|
-
) {
|
|
45
|
-
const allFiles = danger.git.created_files.concat(danger.git.modified_files);
|
|
46
|
-
|
|
47
|
-
const cli = new CLIEngine({ baseConfig: config });
|
|
48
|
-
// let eslint filter down to non-ignored, matching the extensions expected
|
|
49
|
-
const filesToLint = allFiles.filter((f) => {
|
|
50
|
-
return !cli.isPathIgnored(f) && extensions?.some((ext) => f.endsWith(ext));
|
|
51
|
-
});
|
|
52
|
-
return Promise.all(filesToLint.map((f) => lintFile(cli, config, f)));
|
|
53
|
-
}
|
package/src/plugin-jest.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
|
-
import stripANSI from "strip-ansi";
|
|
5
|
-
|
|
6
|
-
import { run } from "jest";
|
|
7
|
-
import { DangerDSLType } from "danger";
|
|
8
|
-
|
|
9
|
-
declare const danger: DangerDSLType;
|
|
10
|
-
declare function fail(message?: string): void;
|
|
11
|
-
declare function message(message?: string): void;
|
|
12
|
-
|
|
13
|
-
interface Snapshot {
|
|
14
|
-
added: number;
|
|
15
|
-
didUpdate: boolean;
|
|
16
|
-
failure: boolean;
|
|
17
|
-
filesAdded: number;
|
|
18
|
-
filesRemoved: number;
|
|
19
|
-
filesUnmatched: number;
|
|
20
|
-
filesUpdated: number;
|
|
21
|
-
matched: number;
|
|
22
|
-
total: number;
|
|
23
|
-
unchecked: number;
|
|
24
|
-
uncheckedKeysByFile: any[];
|
|
25
|
-
unmatched: number;
|
|
26
|
-
updated: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface FileTestResult {
|
|
30
|
-
endTime: number;
|
|
31
|
-
message: string;
|
|
32
|
-
name: string;
|
|
33
|
-
startTime: number;
|
|
34
|
-
status: string;
|
|
35
|
-
summary: string;
|
|
36
|
-
assertionResults: AssertionResult[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface JestTestResults {
|
|
40
|
-
numFailedTestSuites: number;
|
|
41
|
-
numFailedTests: number;
|
|
42
|
-
numPassedTestSuites: number;
|
|
43
|
-
numPassedTests: number;
|
|
44
|
-
numPendingTestSuites: number;
|
|
45
|
-
numPendingTests: number;
|
|
46
|
-
numRuntimeErrorTestSuites: number;
|
|
47
|
-
numTotalTestSuites: number;
|
|
48
|
-
numTotalTests: number;
|
|
49
|
-
snapshot: Snapshot;
|
|
50
|
-
startTime: number;
|
|
51
|
-
success: boolean;
|
|
52
|
-
testResults: FileTestResult[];
|
|
53
|
-
wasInterrupted: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface AssertionResult {
|
|
57
|
-
ancestorTitles: string[];
|
|
58
|
-
failureMessages: string[];
|
|
59
|
-
fullName: string;
|
|
60
|
-
location: string | null;
|
|
61
|
-
status: string;
|
|
62
|
-
title: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const jestSuccessFeedback = (
|
|
66
|
-
jsonResults: JestTestResults,
|
|
67
|
-
showSuccessMessage: boolean
|
|
68
|
-
): void => {
|
|
69
|
-
if (!showSuccessMessage) {
|
|
70
|
-
// tslint:disable-next-line:no-console
|
|
71
|
-
console.log(":+1: Jest tests passed");
|
|
72
|
-
} else {
|
|
73
|
-
message(
|
|
74
|
-
`:+1: Jest tests passed: ${jsonResults.numPassedTests}/${jsonResults.numTotalTests} (${jsonResults.numPendingTests} skipped)`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
function getUrl(file: string, line: number | null) {
|
|
80
|
-
const gitlab = danger.gitlab;
|
|
81
|
-
if (gitlab) {
|
|
82
|
-
const headSha = danger.gitlab.mr.diff_refs.head_sha;
|
|
83
|
-
const repoSlug = gitlab.metadata.repoSlug;
|
|
84
|
-
const baseUrl = `https://gitlab.com/${repoSlug}/-/blob`;
|
|
85
|
-
return `${baseUrl}/${headSha}/${file}${line ? `#L${line}` : ""}`;
|
|
86
|
-
}
|
|
87
|
-
return "#";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const lineOfError = (msg: string, filePath: string): number | null => {
|
|
91
|
-
const filename = path.basename(filePath);
|
|
92
|
-
const restOfTrace = msg.split(filename, 2)[1];
|
|
93
|
-
return restOfTrace ? parseInt(restOfTrace.split(":")[1], 10) : null;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const sanitizeShortErrorMessage = (msg: string): string => {
|
|
97
|
-
if (msg.includes("does not match stored snapshot")) {
|
|
98
|
-
return "Snapshot has changed";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return msg
|
|
102
|
-
.split(" at", 1)[0]
|
|
103
|
-
.trim()
|
|
104
|
-
.split("\n")
|
|
105
|
-
.splice(2)
|
|
106
|
-
.join("")
|
|
107
|
-
.replace(/\s\s+/g, " ")
|
|
108
|
-
.replace("Received:", ", received:")
|
|
109
|
-
.replace("., received", ", received")
|
|
110
|
-
.split("Difference:")[0];
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// e.g. https://gitlab.com/carburo/danger/-/blob/802af5c0b057c4439ef465a75009f017423fbf98/simple.test.js#L6
|
|
114
|
-
const linkToTest = (file: string, msg: string, title: string) => {
|
|
115
|
-
const line = lineOfError(msg, file);
|
|
116
|
-
|
|
117
|
-
return `<a href='${getUrl(file, line)}'>${title}</a>`;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const assertionFailString = (file: string, status: AssertionResult): string => `
|
|
121
|
-
<li>
|
|
122
|
-
${linkToTest(
|
|
123
|
-
file,
|
|
124
|
-
status.failureMessages && status.failureMessages[0],
|
|
125
|
-
status.title
|
|
126
|
-
)}
|
|
127
|
-
<br/>
|
|
128
|
-
${sanitizeShortErrorMessage(
|
|
129
|
-
status.failureMessages && stripANSI(status.failureMessages[0])
|
|
130
|
-
)}
|
|
131
|
-
|
|
132
|
-
<details>
|
|
133
|
-
<summary>Full message</summary>
|
|
134
|
-
<pre><code>
|
|
135
|
-
${status.failureMessages && stripANSI(status.failureMessages.join("\n"))}
|
|
136
|
-
</code></pre>
|
|
137
|
-
</details>
|
|
138
|
-
</li>
|
|
139
|
-
<br/>
|
|
140
|
-
`;
|
|
141
|
-
|
|
142
|
-
const fileToFailString = (
|
|
143
|
-
// tslint:disable-next-line:no-shadowed-variable
|
|
144
|
-
path: string,
|
|
145
|
-
failedAssertions: AssertionResult[]
|
|
146
|
-
): string => `
|
|
147
|
-
<b>:black_joker: FAIL</b> in ${path}
|
|
148
|
-
|
|
149
|
-
${failedAssertions.map((a) => assertionFailString(path, a)).join("\n\n")}
|
|
150
|
-
`;
|
|
151
|
-
|
|
152
|
-
const presentErrors = (jsonResults: JestTestResults) => {
|
|
153
|
-
const failing = jsonResults.testResults.filter(
|
|
154
|
-
(tr) => tr.status === "failed"
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
failing.forEach((results) => {
|
|
158
|
-
const relativeFilePath = path.relative(process.cwd(), results.name);
|
|
159
|
-
const failedAssertions = results.assertionResults.filter(
|
|
160
|
-
(r) => r.status === "failed"
|
|
161
|
-
);
|
|
162
|
-
const failMessage = fileToFailString(relativeFilePath, failedAssertions);
|
|
163
|
-
fail(failMessage);
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
interface PluginConfig {
|
|
168
|
-
testResultsJsonPath: string;
|
|
169
|
-
showSuccessMessage: boolean;
|
|
170
|
-
runJest: boolean;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export async function jest(config: Partial<PluginConfig> = {}) {
|
|
174
|
-
const {
|
|
175
|
-
testResultsJsonPath = "test-results.json",
|
|
176
|
-
showSuccessMessage = true,
|
|
177
|
-
runJest = true,
|
|
178
|
-
} = config;
|
|
179
|
-
if (runJest) {
|
|
180
|
-
try {
|
|
181
|
-
await run(["--outputFile", "test-results.json", "--json"]);
|
|
182
|
-
} catch (e) {
|
|
183
|
-
console.error(e);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
try {
|
|
187
|
-
const jsonFileContents = fs.readFileSync(testResultsJsonPath, "utf8");
|
|
188
|
-
const jsonResults: JestTestResults = JSON.parse(jsonFileContents);
|
|
189
|
-
if (jsonResults.success) {
|
|
190
|
-
jestSuccessFeedback(jsonResults, showSuccessMessage);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
presentErrors(jsonResults);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
// tslint:disable-next-line:no-console
|
|
197
|
-
console.error(e);
|
|
198
|
-
fail(
|
|
199
|
-
"[danger-plugin-jest] Could not read test results. Danger cannot pass or fail the build."
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
}
|