Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fill in unit tests for most create Blocks #1777

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading