Skip to content

Commit

Permalink
test: fill in unit tests for most create Blocks (#1777)
Browse files Browse the repository at this point in the history
## PR Checklist

- [x] Addresses an existing open issue: fixes #1775
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Fills in a whole bunch of snapshot tests.

Cleans up some unused code and fixes some hardcodings too. Nothing that
actually impacts the output creation.

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 17, 2024
1 parent 869c703 commit 54f0934
Show file tree
Hide file tree
Showing 25 changed files with 2,939 additions and 49 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"@clack/prompts": "^0.8.2",
"@prettier/sync": "^0.5.2",
"chalk": "^5.3.0",
"create": "0.1.0-alpha.5",
"create": "0.1.0-alpha.6",
"execa": "^9.5.1",
"git-remote-origin-url": "^4.0.0",
"git-url-parse": "^16.0.0",
"input-from-file": "0.1.0-alpha.0",
"input-from-file-json": "0.1.0-alpha.1",
"input-from-file": "0.1.0-alpha.2",
"input-from-file-json": "0.1.0-alpha.2",
"js-yaml": "^4.1.0",
"lazy-value": "^3.0.0",
"npm-user": "^6.1.1",
Expand Down Expand Up @@ -82,7 +82,7 @@
"all-contributors-cli": "6.26.1",
"c8": "10.1.2",
"console-fail-test": "0.5.0",
"create-testers": "0.1.0-alpha.5",
"create-testers": "0.1.0-alpha.6",
"cspell": "8.16.1",
"eslint": "9.16.0",
"eslint-plugin-jsdoc": "50.6.0",
Expand Down
65 changes: 38 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions src/next/blocks/blockAllContributors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { testBlock } from "create-testers";
import { describe, expect, it } from "vitest";

import { blockAllContributors } from "./blockAllContributors.js";
import { optionsBase } from "./options.fakes.js";

describe("blockAllContributors", () => {
it("defaults contributors to [] when not provided", () => {
const creation = testBlock(blockAllContributors, { options: optionsBase });

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
"/.all-contributorsrc",
],
},
"block": [Function],
},
],
"files": {
".all-contributorsrc": "{"badgeTemplate":"\\t<a href=\\"#contributors\\" target=\\"_blank\\"><img alt=\\"👪 All Contributors: <%= contributors.length %>\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" /></a>","commit":false,"commitConvention":"angular","commitType":"docs","contributors":[],"contributorsPerLine":7,"contributorsSortAlphabetically":true,"files":["README.md"],"imageSize":100,"projectName":"test-repository","projectOwner":"test-owner","repoHost":"https://github.com","repoType":"github"}",
".github": {
"workflows": {
"contributors.yml": "jobs:
contributors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/prepare
- env:
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0
name: Contributors
on:
push:
branches:
- main
",
},
},
},
"scripts": [
{
"commands": [
"npx -y all-contributors-cli generate",
"npx -y all-contributors-cli add test-owner code,content,docs,ideas,infra,maintenance,projectManagement,tool",
],
"phase": 2,
},
],
}
`);
});

it("includes contributors when not provided", () => {
const creation = testBlock(blockAllContributors, {
options: {
...optionsBase,
contributors: [
{
avatar_url: "https://avatars.githubusercontent.com/u/3335181?v=4",
contributions: ["bug", "ideas"],
login: "JoshuaKGoldberg",
name: "Josh Goldberg",
profile: "http://www.joshuakgoldberg.com",
},
],
},
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
"/.all-contributorsrc",
],
},
"block": [Function],
},
],
"files": {
".all-contributorsrc": "{"badgeTemplate":"\\t<a href=\\"#contributors\\" target=\\"_blank\\"><img alt=\\"👪 All Contributors: <%= contributors.length %>\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" /></a>","commit":false,"commitConvention":"angular","commitType":"docs","contributors":[{"avatar_url":"https://avatars.githubusercontent.com/u/3335181?v=4","contributions":["bug","ideas"],"login":"JoshuaKGoldberg","name":"Josh Goldberg","profile":"http://www.joshuakgoldberg.com"}],"contributorsPerLine":7,"contributorsSortAlphabetically":true,"files":["README.md"],"imageSize":100,"projectName":"test-repository","projectOwner":"test-owner","repoHost":"https://github.com","repoType":"github"}",
".github": {
"workflows": {
"contributors.yml": "jobs:
contributors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/prepare
- env:
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0
name: Contributors
on:
push:
branches:
- main
",
},
},
},
"scripts": [
{
"commands": [
"npx -y all-contributors-cli generate",
"npx -y all-contributors-cli add test-owner code,content,docs,ideas,infra,maintenance,projectManagement,tool",
],
"phase": 2,
},
],
}
`);
});
});
35 changes: 35 additions & 0 deletions src/next/blocks/blockAreTheTypesWrong.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { testBlock } from "create-testers";
import { describe, expect, test } from "vitest";

import { blockAreTheTypesWrong } from "./blockAreTheTypesWrong.js";
import { optionsBase } from "./options.fakes.js";

describe("blockAreTheTypesWrong", () => {
test("production", () => {
const creation = testBlock(blockAreTheTypesWrong, {
options: optionsBase,
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"jobs": [
{
"name": "Are The Types Wrong?",
"steps": [
{
"run": "npx --yes @arethetypeswrong/cli --pack . --ignore-rules cjs-resolves-to-esm",
},
],
},
],
},
"block": [Function],
},
],
}
`);
});
});
Loading

0 comments on commit 54f0934

Please sign in to comment.