|
1 |
| -import { testBlock } from "bingo-stratum-testers"; |
2 |
| -import { describe, expect, test } from "vitest"; |
| 1 | +import { testBlock, testIntake } from "bingo-stratum-testers"; |
| 2 | +import jsYaml from "js-yaml"; |
| 3 | +import { describe, expect, it, test } from "vitest"; |
3 | 4 |
|
4 | 5 | import { blockCodecov } from "./blockCodecov.js";
|
5 | 6 | import { optionsBase } from "./options.fakes.js";
|
@@ -52,7 +53,7 @@ describe("blockCodecov", () => {
|
52 | 53 | `);
|
53 | 54 | });
|
54 | 55 |
|
55 |
| - test("transition mode", () => { |
| 56 | + test("transition mode without files", () => { |
56 | 57 | const creation = testBlock(blockCodecov, {
|
57 | 58 | mode: "transition",
|
58 | 59 | options: optionsBase,
|
@@ -163,4 +164,140 @@ describe("blockCodecov", () => {
|
163 | 164 | }
|
164 | 165 | `);
|
165 | 166 | });
|
| 167 | + |
| 168 | + describe("intake", () => { |
| 169 | + it("returns undefined when ci.yml does not exist", () => { |
| 170 | + const actual = testIntake(blockCodecov, { |
| 171 | + files: { |
| 172 | + ".github": { |
| 173 | + workflows: {}, |
| 174 | + }, |
| 175 | + }, |
| 176 | + }); |
| 177 | + |
| 178 | + expect(actual).toBeUndefined(); |
| 179 | + }); |
| 180 | + |
| 181 | + it("returns undefined when ci.yml contains invalid yml", () => { |
| 182 | + const actual = testIntake(blockCodecov, { |
| 183 | + files: { |
| 184 | + ".github": { |
| 185 | + workflows: { |
| 186 | + "ci.yml": ["invalid yml!"], |
| 187 | + }, |
| 188 | + }, |
| 189 | + }, |
| 190 | + }); |
| 191 | + |
| 192 | + expect(actual).toBeUndefined(); |
| 193 | + }); |
| 194 | + |
| 195 | + it("returns undefined when ci.yml does not contain a test job", () => { |
| 196 | + const actual = testIntake(blockCodecov, { |
| 197 | + files: { |
| 198 | + ".github": { |
| 199 | + workflows: { |
| 200 | + "ci.yml": [ |
| 201 | + jsYaml.dump({ |
| 202 | + jobs: { |
| 203 | + other: { |
| 204 | + name: "Other", |
| 205 | + steps: [], |
| 206 | + }, |
| 207 | + }, |
| 208 | + }), |
| 209 | + ], |
| 210 | + }, |
| 211 | + }, |
| 212 | + }, |
| 213 | + }); |
| 214 | + |
| 215 | + expect(actual).toBeUndefined(); |
| 216 | + }); |
| 217 | + |
| 218 | + it("returns undefined when ci.yml contains a test job with only non-string uses", () => { |
| 219 | + const actual = testIntake(blockCodecov, { |
| 220 | + files: { |
| 221 | + ".github": { |
| 222 | + workflows: { |
| 223 | + "ci.yml": [ |
| 224 | + jsYaml.dump({ |
| 225 | + jobs: { |
| 226 | + test: { |
| 227 | + name: "Test", |
| 228 | + steps: [ |
| 229 | + { |
| 230 | + uses: { not: "a string" }, |
| 231 | + }, |
| 232 | + ], |
| 233 | + }, |
| 234 | + }, |
| 235 | + }), |
| 236 | + ], |
| 237 | + }, |
| 238 | + }, |
| 239 | + }, |
| 240 | + }); |
| 241 | + |
| 242 | + expect(actual).toBeUndefined(); |
| 243 | + }); |
| 244 | + |
| 245 | + it("returns undefined env when ci.yml contains a test job with no env in its codecov step", () => { |
| 246 | + const actual = testIntake(blockCodecov, { |
| 247 | + files: { |
| 248 | + ".github": { |
| 249 | + workflows: { |
| 250 | + "ci.yml": [ |
| 251 | + jsYaml.dump({ |
| 252 | + jobs: { |
| 253 | + test: { |
| 254 | + name: "Test", |
| 255 | + steps: [ |
| 256 | + { |
| 257 | + uses: "codecov/codecov-action@v3", |
| 258 | + }, |
| 259 | + ], |
| 260 | + }, |
| 261 | + }, |
| 262 | + }), |
| 263 | + ], |
| 264 | + }, |
| 265 | + }, |
| 266 | + }, |
| 267 | + }); |
| 268 | + |
| 269 | + expect(actual).toEqual({ env: undefined }); |
| 270 | + }); |
| 271 | + |
| 272 | + it("returns env when ci.yml contains a test job with env in its codecov step", () => { |
| 273 | + const env = { |
| 274 | + CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}", |
| 275 | + }; |
| 276 | + const actual = testIntake(blockCodecov, { |
| 277 | + files: { |
| 278 | + ".github": { |
| 279 | + workflows: { |
| 280 | + "ci.yml": [ |
| 281 | + jsYaml.dump({ |
| 282 | + jobs: { |
| 283 | + test: { |
| 284 | + name: "Test", |
| 285 | + steps: [ |
| 286 | + { |
| 287 | + env, |
| 288 | + uses: "codecov/codecov-action@v3", |
| 289 | + }, |
| 290 | + ], |
| 291 | + }, |
| 292 | + }, |
| 293 | + }), |
| 294 | + ], |
| 295 | + }, |
| 296 | + }, |
| 297 | + }, |
| 298 | + }); |
| 299 | + |
| 300 | + expect(actual).toEqual({ env }); |
| 301 | + }); |
| 302 | + }); |
166 | 303 | });
|
0 commit comments