From 7ce9b96a5dbb9774f7c30467ce935876b15802a9 Mon Sep 17 00:00:00 2001 From: Damien Butt <22627489+damienbutt@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:10:49 +0000 Subject: [PATCH] refactor: further updates --- tests/c.test.ts | 103 ++++---- tests/helpers.ts | 17 ++ tests/html.test.ts | 516 ++++++++++++++++++++++++++++++++++----- tests/javascript.test.ts | 507 +++++++++++++++++++++++++++++++++----- tests/nodecli.test.ts | 507 +++++++++++++++++++++++++++++++++----- tests/python.test.ts | 262 ++++++++++++++++++-- tests/simpl.test.ts | 479 ++++++++++++++++++++++++++++++++---- tests/typescript.test.ts | 292 +++++++++------------- 8 files changed, 2189 insertions(+), 494 deletions(-) create mode 100644 tests/helpers.ts diff --git a/tests/c.test.ts b/tests/c.test.ts index dfbd4f3..a338c35 100644 --- a/tests/c.test.ts +++ b/tests/c.test.ts @@ -8,6 +8,7 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,9 +18,23 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; +const devDependencies = [ + "@commitlint/cli", + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "all-contributors-cli", + "commitizen", + "cz-conventional-changelog", + "doctoc", + "husky", + "lint-staged", + "prettier", + "semantic-release", +]; + const files = [ ".github/workflows/main.yml", ".github/dependabot.yml", @@ -140,26 +155,13 @@ describe("generator-norgate-av:c", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/cli": devDependencies!["@commitlint/cli"], - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), }); }); @@ -334,26 +336,13 @@ describe("generator-norgate-av:c", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/cli": devDependencies!["@commitlint/cli"], - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), }); }); @@ -444,6 +433,11 @@ describe("generator-norgate-av:c", () => { type: "c", yes: true, }, + { + destination: "Test Project", + type: "clang", + yes: true, + }, ])( "cli: using all defaults, skipping prompts", ({ destination, type, yes }) => { @@ -495,26 +489,13 @@ describe("generator-norgate-av:c", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/cli": devDependencies!["@commitlint/cli"], - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), }); }); diff --git a/tests/helpers.ts b/tests/helpers.ts new file mode 100644 index 0000000..6b18e97 --- /dev/null +++ b/tests/helpers.ts @@ -0,0 +1,17 @@ +export function getNodeDependencyObject( + dependencies: Array, + store: Record, +): Record { + return dependencies.reduce>((dependencies, key) => { + const value = store[key]; + + if (value === undefined) { + return dependencies; + } + + return { + ...dependencies, + [key]: value, + }; + }, {}); +} diff --git a/tests/html.test.ts b/tests/html.test.ts index 14638d3..d8f6ea6 100644 --- a/tests/html.test.ts +++ b/tests/html.test.ts @@ -7,7 +7,8 @@ import AppGenerator from "../src/app.js"; import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; -import { UnresolvedConfig } from "../src/@types/index.js"; +import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,10 +18,63 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies, dependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; -describe("generator-norgate-av:app", () => { +const devDependencies = [ + "@commitlint/cli", + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "@types/config", + "@types/live-server", + "@types/node", + "all-contributors-cli", + "commitizen", + "cz-conventional-changelog", + "doctoc", + "husky", + "lint-staged", + "live-server", + "prettier", + "semantic-release", +]; + +const dependencies = ["config", "dotenv", "envalid"]; + +const files = [ + ".github/workflows/main.yml", + ".github/dependabot.yml", + ".husky/commit-msg", + ".husky/pre-commit", + ".vscode/extensions.json", + ".vscode/settings.json", + "assets/css/styles.css", + "assets/img/favicon.ico", + "assets/img/yeoman-logo-svg-vector.svg", + "assets/js/app.js", + "public/index.html", + ".all-contributorsrc", + ".changelogrc.json", + ".commitlintrc.json", + ".czrc", + ".editorconfig", + ".gitattributes", + ".gitignore", + ".lintstagedrc.json", + ".npmignore", + ".npmrc", + ".nvmrc", + ".prettierignore", + ".prettierrc.json", + "CHANGELOG.md", + "CONTRIBUTING.md", + "GitVersion.yml", + "LICENSE", + "package.json", + "README.md", +]; + +describe("generator-norgate-av:html", () => { describe.each([ { type: "html", @@ -53,7 +107,7 @@ describe("generator-norgate-av:app", () => { openWith: "skip", }, ])( - 'html with type $type, package manager $pkg, and git "$git"', + "prompts: app --type $type --name $name --id $id --description $description --author $author --git $git --pkg $pkg --openWith $openWith", ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; @@ -78,43 +132,28 @@ describe("generator-norgate-av:app", () => { result?.cleanup(); }); + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + it(`should create a directory named '${name}' and CD into it`, () => { assert.equal(path.basename(process.cwd()), name); }); it("should create the correct files", () => { - assert.file([ - ".github/workflows/main.yml", - ".github/dependabot.yml", - ".husky/commit-msg", - ".husky/pre-commit", - ".vscode/extensions.json", - ".vscode/settings.json", - "assets/css/styles.css", - "assets/img/favicon.ico", - "assets/img/yeoman-logo-svg-vector.svg", - "assets/js/app.js", - "public/index.html", - ".all-contributorsrc", - ".changelogrc.json", - ".commitlintrc.json", - ".czrc", - ".editorconfig", - ".gitattributes", - ".gitignore", - ".lintstagedrc.json", - ".npmignore", - ".npmrc", - ".nvmrc", - ".prettierignore", - ".prettierrc.json", - "CHANGELOG.md", - "CONTRIBUTING.md", - "GitVersion.yml", - "LICENSE", - "package.json", - "README.md", - ]); + assert.file(files); }); it("should create the correct package.json", () => { @@ -125,36 +164,17 @@ describe("generator-norgate-av:app", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/cli": devDependencies!["@commitlint/cli"], - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/live-server": - devDependencies!["@types/live-server"], - "@types/node": devDependencies!["@types/node"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - "live-server": devDependencies!["live-server"], - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); }); @@ -242,4 +262,368 @@ describe("generator-norgate-av:app", () => { }); }, ); + + describe.each([ + { + destination: "test", + type: "html", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: false, + pkg: "pnpm", + yes: true, + }, + { + destination: "test", + type: "web", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "yarn", + yes: true, + }, + { + destination: "test", + type: "vanilla", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "npm", + yes: true, + }, + ])( + "cli: app $destination --type $type --id $id --description $description --author $author --git $git --pkg $pkg --yes $yes", + ({ destination, type, id, description, author, git, pkg, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.destination, destination); + assert.equal(result.generator.options.name, destination); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git || undefined); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: id, + displayName: destination, + description, + engines: { + node: `>=${engine}`, + }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent("README.md", `# ${id}`); + assert.fileContent( + "README.md", + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assert.fileContent("CONTRIBUTING.md", `${pkg} install`); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${pkg} commitlint --edit $1`, + ); + assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + git ? assert.file(".git") : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); + + describe.each([ + { + destination: "Test Project", + type: "html", + yes: true, + }, + { + destination: "Test Project", + type: "web", + yes: true, + }, + { + destination: "Test Project", + type: "vanilla", + yes: true, + }, + ])( + "cli: using all defaults, skipping prompts", + ({ destination, type, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct default values", () => { + assert.equal(result.generator.options.id, "test-project"); + assert.equal(result.generator.options.description, ""); + assert.equal(result.generator.options.author, ""); + assert.equal(result.generator.options.git, true); + assert.equal(result.generator.options.pkg, "pnpm"); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + "pnpm", + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: result.generator.options.id, + displayName: destination, + description: result.generator.options.description, + engines: { + node: `>=${engine}`, + }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent( + "README.md", + `# ${result.generator.options.id}`, + ); + assert.fileContent( + "README.md", + `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}/issues/new/choose`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}.git`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `cd ${result.generator.options.id}`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} install`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${result.generator.options.pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${result.generator.options.pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${result.generator.options.id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${result.generator.options.pkg} commitlint --edit $1`, + ); + assert.fileContent( + ".husky/pre-commit", + `${result.generator.options.pkg} lint-staged`, + ); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + result.generator.options.git + ? assert.file(".git") + : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); }); diff --git a/tests/javascript.test.ts b/tests/javascript.test.ts index 29f92aa..7e1cdce 100644 --- a/tests/javascript.test.ts +++ b/tests/javascript.test.ts @@ -7,7 +7,8 @@ import AppGenerator from "../src/app.js"; import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; -import { UnresolvedConfig } from "../src/@types/index.js"; +import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,10 +18,60 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies, dependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; -describe("generator-norgate-av:app", () => { +const devDependencies = [ + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "@types/config", + "@types/node", + "@types/nodemon", + "all-contributors-cli", + "commitizen", + "cross-env", + "cz-conventional-changelog", + "doctoc", + "husky", + "lint-staged", + "nodemon", + "prettier", + "semantic-release", +]; + +const dependencies = ["config", "dotenv", "envalid"]; + +const files = [ + ".github/workflows/main.yml", + ".github/dependabot.yml", + ".husky/commit-msg", + ".husky/pre-commit", + ".vscode/extensions.json", + ".vscode/settings.json", + "src/app.js", + ".all-contributorsrc", + ".changelogrc.json", + ".commitlintrc.json", + ".czrc", + ".editorconfig", + ".gitattributes", + ".gitignore", + ".lintstagedrc.json", + ".npmignore", + ".npmrc", + ".nvmrc", + ".prettierignore", + ".prettierrc.json", + ".releaserc.json", + "CHANGELOG.md", + "CONTRIBUTING.md", + "GitVersion.yml", + "LICENSE", + "package.json", + "README.md", +]; + +describe("generator-norgate-av:javascript", () => { describe.each([ { type: "javascript", @@ -53,7 +104,7 @@ describe("generator-norgate-av:app", () => { openWith: "skip", }, ])( - 'javascript with type $type, package manager $pkg, and git "$git"', + "prompts: app --type $type --name $name --id $id --description $description --author $author --git $git --pkg $pkg --openWith $openWith", ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; @@ -78,40 +129,28 @@ describe("generator-norgate-av:app", () => { result?.cleanup(); }); + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + it(`should create a directory named '${name}' and CD into it`, () => { assert.equal(path.basename(process.cwd()), name); }); it("should create the correct files", () => { - assert.file([ - ".github/workflows/main.yml", - ".github/dependabot.yml", - ".husky/commit-msg", - ".husky/pre-commit", - ".vscode/extensions.json", - ".vscode/settings.json", - "src/app.js", - ".all-contributorsrc", - ".changelogrc.json", - ".commitlintrc.json", - ".czrc", - ".editorconfig", - ".gitattributes", - ".gitignore", - ".lintstagedrc.json", - ".npmignore", - ".npmrc", - ".nvmrc", - ".prettierignore", - ".prettierrc.json", - ".releaserc.json", - "CHANGELOG.md", - "CONTRIBUTING.md", - "GitVersion.yml", - "LICENSE", - "package.json", - "README.md", - ]); + assert.file(files); }); it("should create the correct package.json", () => { @@ -122,35 +161,202 @@ describe("generator-norgate-av:app", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/node": devDependencies!["@types/node"], - "@types/nodemon": devDependencies!["@types/nodemon"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cross-env": devDependencies!["cross-env"], - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - nodemon: devDependencies!.nodemon, - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent("README.md", `# ${id}`); + assert.fileContent( + "README.md", + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assert.fileContent("CONTRIBUTING.md", `${pkg} install`); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${pkg} commitlint --edit $1`, + ); + assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + git ? assert.file(".git") : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); + + describe.each([ + { + destination: "test", + type: "javascript", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: false, + pkg: "pnpm", + yes: true, + }, + { + destination: "test", + type: "js", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "yarn", + yes: true, + }, + { + destination: "test", + type: "node-js", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "npm", + yes: true, + }, + ])( + "cli: app $destination --type $type --id $id --description $description --author $author --git $git --pkg $pkg --yes $yes", + ({ destination, type, id, description, author, git, pkg, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.destination, destination); + assert.equal(result.generator.options.name, destination); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git || undefined); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: id, + displayName: destination, + description, + engines: { + node: `>=${engine}`, }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); }); @@ -234,4 +440,183 @@ describe("generator-norgate-av:app", () => { }); }, ); + + describe.each([ + { + destination: "Test Project", + type: "javascript", + yes: true, + }, + { + destination: "Test Project", + type: "js", + yes: true, + }, + { + destination: "Test Project", + type: "node-js", + yes: true, + }, + ])( + "cli: using all defaults, skipping prompts", + ({ destination, type, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct default values", () => { + assert.equal(result.generator.options.id, "test-project"); + assert.equal(result.generator.options.description, ""); + assert.equal(result.generator.options.author, ""); + assert.equal(result.generator.options.git, true); + assert.equal(result.generator.options.pkg, "pnpm"); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + "pnpm", + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: result.generator.options.id, + displayName: destination, + description: result.generator.options.description, + engines: { + node: `>=${engine}`, + }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent( + "README.md", + `# ${result.generator.options.id}`, + ); + assert.fileContent( + "README.md", + `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}/issues/new/choose`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}.git`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `cd ${result.generator.options.id}`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} install`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${result.generator.options.pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${result.generator.options.pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${result.generator.options.id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${result.generator.options.pkg} commitlint --edit $1`, + ); + assert.fileContent( + ".husky/pre-commit", + `${result.generator.options.pkg} lint-staged`, + ); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + result.generator.options.git + ? assert.file(".git") + : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); }); diff --git a/tests/nodecli.test.ts b/tests/nodecli.test.ts index 99aef85..d8ea8be 100644 --- a/tests/nodecli.test.ts +++ b/tests/nodecli.test.ts @@ -7,7 +7,8 @@ import AppGenerator from "../src/app.js"; import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; -import { UnresolvedConfig } from "../src/@types/index.js"; +import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,10 +18,60 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies, dependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; -describe("generator-norgate-av:app", () => { +const devDependencies = [ + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "@types/config", + "@types/node", + "@types/nodemon", + "all-contributors-cli", + "commitizen", + "cross-env", + "cz-conventional-changelog", + "doctoc", + "husky", + "lint-staged", + "nodemon", + "prettier", + "semantic-release", +]; + +const dependencies = ["config", "dotenv", "envalid"]; + +const files = [ + ".github/workflows/main.yml", + ".github/dependabot.yml", + ".husky/commit-msg", + ".husky/pre-commit", + ".vscode/extensions.json", + ".vscode/settings.json", + "src/app.js", + ".all-contributorsrc", + ".changelogrc.json", + ".commitlintrc.json", + ".czrc", + ".editorconfig", + ".gitattributes", + ".gitignore", + ".lintstagedrc.json", + ".npmignore", + ".npmrc", + ".nvmrc", + ".prettierignore", + ".prettierrc.json", + ".releaserc.json", + "CHANGELOG.md", + "CONTRIBUTING.md", + "GitVersion.yml", + "LICENSE", + "package.json", + "README.md", +]; + +describe("generator-norgate-av:nodecli", () => { describe.each([ { type: "nodecli", @@ -53,7 +104,7 @@ describe("generator-norgate-av:app", () => { openWith: "skip", }, ])( - 'nodecli with type $type, package manager $pkg, and git "$git"', + "prompts: app --type $type --name $name --id $id --description $description --author $author --git $git --pkg $pkg --openWith $openWith", ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; @@ -78,40 +129,28 @@ describe("generator-norgate-av:app", () => { result?.cleanup(); }); + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + it(`should create a directory named '${name}' and CD into it`, () => { assert.equal(path.basename(process.cwd()), name); }); it("should create the correct files", () => { - assert.file([ - ".github/workflows/main.yml", - ".github/dependabot.yml", - ".husky/commit-msg", - ".husky/pre-commit", - ".vscode/extensions.json", - ".vscode/settings.json", - "src/app.js", - ".all-contributorsrc", - ".changelogrc.json", - ".commitlintrc.json", - ".czrc", - ".editorconfig", - ".gitattributes", - ".gitignore", - ".lintstagedrc.json", - ".npmignore", - ".npmrc", - ".nvmrc", - ".prettierignore", - ".prettierrc.json", - ".releaserc.json", - "CHANGELOG.md", - "CONTRIBUTING.md", - "GitVersion.yml", - "LICENSE", - "package.json", - "README.md", - ]); + assert.file(files); }); it("should create the correct package.json", () => { @@ -122,35 +161,202 @@ describe("generator-norgate-av:app", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/node": devDependencies!["@types/node"], - "@types/nodemon": devDependencies!["@types/nodemon"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cross-env": devDependencies!["cross-env"], - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - nodemon: devDependencies!.nodemon, - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent("README.md", `# ${id}`); + assert.fileContent( + "README.md", + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assert.fileContent("CONTRIBUTING.md", `${pkg} install`); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${pkg} commitlint --edit $1`, + ); + assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + git ? assert.file(".git") : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); + + describe.each([ + { + destination: "test", + type: "nodecli", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: false, + pkg: "pnpm", + yes: true, + }, + { + destination: "test", + type: "node-cli", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "yarn", + yes: true, + }, + { + destination: "test", + type: "cli-js", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "npm", + yes: true, + }, + ])( + "cli: app $destination --type $type --id $id --description $description --author $author --git $git --pkg $pkg --yes $yes", + ({ destination, type, id, description, author, git, pkg, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.destination, destination); + assert.equal(result.generator.options.name, destination); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git || undefined); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: id, + displayName: destination, + description, + engines: { + node: `>=${engine}`, }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); }); @@ -234,4 +440,183 @@ describe("generator-norgate-av:app", () => { }); }, ); + + describe.each([ + { + destination: "Test Project", + type: "nodecli", + yes: true, + }, + { + destination: "Test Project", + type: "node-cli", + yes: true, + }, + { + destination: "Test Project", + type: "cli-js", + yes: true, + }, + ])( + "cli: using all defaults, skipping prompts", + ({ destination, type, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct default values", () => { + assert.equal(result.generator.options.id, "test-project"); + assert.equal(result.generator.options.description, ""); + assert.equal(result.generator.options.author, ""); + assert.equal(result.generator.options.git, true); + assert.equal(result.generator.options.pkg, "pnpm"); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + "pnpm", + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: result.generator.options.id, + displayName: destination, + description: result.generator.options.description, + engines: { + node: `>=${engine}`, + }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent( + "README.md", + `# ${result.generator.options.id}`, + ); + assert.fileContent( + "README.md", + `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}/issues/new/choose`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}.git`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `cd ${result.generator.options.id}`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} install`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${result.generator.options.pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${result.generator.options.pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${result.generator.options.id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${result.generator.options.pkg} commitlint --edit $1`, + ); + assert.fileContent( + ".husky/pre-commit", + `${result.generator.options.pkg} lint-staged`, + ); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + result.generator.options.git + ? assert.file(".git") + : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); }); diff --git a/tests/python.test.ts b/tests/python.test.ts index b644ca6..52e9a1c 100644 --- a/tests/python.test.ts +++ b/tests/python.test.ts @@ -8,7 +8,23 @@ import AppGenerator from "../src/app.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); -describe("generator-norgate-av:app", () => { +const files = [ + ".github/workflows/main.yml", + ".github/dependabot.yml", + ".vscode/extensions.json", + ".vscode/settings.json", + "src/main.py", + ".editorconfig", + ".gitattributes", + ".gitignore", + "CONTRIBUTING.md", + "CHANGELOG.md", + "GitVersion.yml", + "LICENSE", + "README.md", +]; + +describe("generator-norgate-av:python", () => { describe.each([ { type: "python", @@ -29,7 +45,7 @@ describe("generator-norgate-av:app", () => { openWith: "skip", }, ])( - 'python using type "$type" and git "$git"', + "prompts: app --type $type --name $name --id $id --description $description --author $author --git $git --openWith $openWith", ({ type, name, id, description, author, git, openWith }) => { let result: RunResult; @@ -53,26 +69,128 @@ describe("generator-norgate-av:app", () => { result?.cleanup(); }); + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git); + }); + it(`should create a directory named '${name}' and CD into it`, () => { assert.equal(path.basename(process.cwd()), name); }); it("should create the correct files", () => { - assert.file([ - ".github/workflows/main.yml", - ".github/dependabot.yml", - ".vscode/extensions.json", - ".vscode/settings.json", - "src/main.py", - ".editorconfig", - ".gitattributes", - ".gitignore", - "CONTRIBUTING.md", - "CHANGELOG.md", - "GitVersion.yml", - "LICENSE", + assert.file(files); + }); + + it("should create the correct README.md", () => { + assert.fileContent("README.md", `# ${id}`); + assert.fileContent( "README.md", - ]); + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${id}" project will be documented in this file.`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + git ? assert.file(".git") : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); + + describe.each([ + { + destination: "test", + type: "python", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: false, + yes: true, + }, + { + destination: "test", + type: "py", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + yes: true, + }, + ])( + "cli: app $destination --type $type --id $id --description $description --author $author --git $git --pkg $pkg --yes $yes", + ({ destination, type, id, description, author, git, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + id, + description, + author, + git, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.destination, destination); + assert.equal(result.generator.options.name, destination); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git || undefined); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); }); it("should create the correct README.md", () => { @@ -91,6 +209,15 @@ describe("generator-norgate-av:app", () => { ); }); + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + }); + it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", @@ -110,4 +237,107 @@ describe("generator-norgate-av:app", () => { }); }, ); + + describe.each([ + { + destination: "Test Project", + type: "python", + yes: true, + }, + { + destination: "Test Project", + type: "py", + yes: true, + }, + ])( + "cli: using all defaults, skipping prompts", + ({ destination, type, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct default values", () => { + assert.equal(result.generator.options.id, "test-project"); + assert.equal(result.generator.options.description, ""); + assert.equal(result.generator.options.author, ""); + assert.equal(result.generator.options.git, true); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct README.md", () => { + assert.fileContent( + "README.md", + `# ${result.generator.options.id}`, + ); + assert.fileContent( + "README.md", + `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}/issues/new/choose`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}.git`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `cd ${result.generator.options.id}`, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, + ); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + result.generator.options.git + ? assert.file(".git") + : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); }); diff --git a/tests/simpl.test.ts b/tests/simpl.test.ts index d12aaec..468136c 100644 --- a/tests/simpl.test.ts +++ b/tests/simpl.test.ts @@ -7,7 +7,8 @@ import AppGenerator from "../src/app.js"; import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; -import { UnresolvedConfig } from "../src/@types/index.js"; +import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,10 +18,56 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; -describe("generator-norgate-av:app", () => { +const devDependencies = [ + "@commitlint/cli", + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "all-contributors-cli", + "commitizen", + "cz-conventional-changelog", + "doctoc", + "husky", + "lint-staged", + "prettier", + "semantic-release", +]; + +const files = [ + ".github/workflows/main.yml", + ".github/dependabot.yml", + ".husky/commit-msg", + ".husky/pre-commit", + ".vscode/extensions.json", + ".vscode/settings.json", + "config/config.txt", + "docs/.gitkeep", + "src/.gitkeep", + "ui/.gitkeep", + ".all-contributorsrc", + ".changelogrc.json", + ".commitlintrc.json", + ".czrc", + ".editorconfig", + ".gitattributes", + ".gitignore", + ".lintstagedrc.json", + ".npmignore", + ".npmrc", + ".nvmrc", + ".prettierignore", + ".prettierrc.json", + "CHANGELOG.md", + "CONTRIBUTING.md", + "GitVersion.yml", + "LICENSE", + "package.json", + "README.md", +]; + +describe("generator-norgate-av:simpl", () => { describe.each([ { type: "simpl", @@ -53,7 +100,7 @@ describe("generator-norgate-av:app", () => { openWith: "skip", }, ])( - 'crestron-simpl with type $type, package manager $pkg, and git "$git"', + "prompts: app --type $type --name $name --id $id --description $description --author $author --git $git --pkg $pkg --openWith $openWith", ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; @@ -78,42 +125,28 @@ describe("generator-norgate-av:app", () => { result?.cleanup(); }); + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + it(`should create a directory named '${name}' and CD into it`, () => { assert.equal(path.basename(process.cwd()), name); }); it("should create the correct files", () => { - assert.file([ - ".github/workflows/main.yml", - ".github/dependabot.yml", - ".husky/commit-msg", - ".husky/pre-commit", - ".vscode/extensions.json", - ".vscode/settings.json", - "config/config.txt", - "docs/.gitkeep", - "src/.gitkeep", - "ui/.gitkeep", - ".all-contributorsrc", - ".changelogrc.json", - ".commitlintrc.json", - ".czrc", - ".editorconfig", - ".gitattributes", - ".gitignore", - ".lintstagedrc.json", - ".npmignore", - ".npmrc", - ".nvmrc", - ".prettierignore", - ".prettierrc.json", - "CHANGELOG.md", - "CONTRIBUTING.md", - "GitVersion.yml", - "LICENSE", - "package.json", - "README.md", - ]); + assert.file(files); }); it("should create the correct package.json", () => { @@ -124,26 +157,194 @@ describe("generator-norgate-av:app", () => { engines: { node: `>=${engine}`, }, - devDependencies: { - "@commitlint/cli": devDependencies!["@commitlint/cli"], - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - prettier: devDependencies!.prettier, - "semantic-release": - devDependencies!["semantic-release"], + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent("README.md", `# ${id}`); + assert.fileContent( + "README.md", + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${id}/issues/new/choose`, + ); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assert.fileContent("CONTRIBUTING.md", `${pkg} install`); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${pkg} commitlint --edit $1`, + ); + assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + git ? assert.file(".git") : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); + + describe.each([ + { + destination: "test", + type: "simpl", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: false, + pkg: "pnpm", + yes: true, + }, + { + destination: "test", + type: "crestron-simpl", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "yarn", + yes: true, + }, + { + destination: "test", + type: "simpl", + id: "test-id", + description: "test-description", + author: "Yeoman", + git: true, + pkg: "npm", + yes: true, + }, + ])( + "cli: app $destination --type $type --id $id --description $description --author $author --git $git --pkg $pkg --yes $yes", + ({ destination, type, id, description, author, git, pkg, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct values", () => { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.destination, destination); + assert.equal(result.generator.options.name, destination); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + // assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, git || undefined); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: id, + displayName: destination, + description, + engines: { + node: `>=${engine}`, }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), }); }); @@ -227,4 +428,174 @@ describe("generator-norgate-av:app", () => { }); }, ); + + describe.each([ + { + destination: "Test Project", + type: "simpl", + yes: true, + }, + { + destination: "Test Project", + type: "crestron-simpl", + yes: true, + }, + ])( + "cli: using all defaults, skipping prompts", + ({ destination, type, yes }) => { + let result: RunResult; + + beforeAll(async () => { + result = await helpers + .create(generator) + .withArguments([destination]) + .withOptions({ + type, + yes, + }); + + process.chdir(destination); + }); + + afterAll(() => { + result?.cleanup(); + }); + + it("should assign the correct default values", () => { + assert.equal(result.generator.options.id, "test-project"); + assert.equal(result.generator.options.description, ""); + assert.equal(result.generator.options.author, ""); + assert.equal(result.generator.options.git, true); + assert.equal(result.generator.options.pkg, "pnpm"); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + "pnpm", + ); + }); + + it(`should create a directory named '${destination}' and CD into it`, () => { + assert.equal(path.basename(process.cwd()), destination); + }); + + it("should create the correct files", () => { + assert.file(files); + }); + + it("should create the correct package.json", () => { + assert.jsonFileContent("package.json", { + name: result.generator.options.id, + displayName: destination, + description: result.generator.options.description, + engines: { + node: `>=${engine}`, + }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + }); + }); + + it("should create the correct README.md", () => { + assert.fileContent( + "README.md", + `# ${result.generator.options.id}`, + ); + assert.fileContent( + "README.md", + `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + ); + }); + + it("should create the correct .nvmrc", () => { + assert.fileContent(".nvmrc", node.getNodeEngine()); + }); + + it("should create the correct LICENSE", () => { + assert.fileContent("LICENSE", "The MIT License (MIT)"); + assert.fileContent( + "LICENSE", + `Copyright (c) ${new Date().getFullYear()}`, + ); + }); + + it("should create the correct CONTRIBUTING.md", () => { + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}/issues/new/choose`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `/${result.generator.options.id}.git`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `cd ${result.generator.options.id}`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} install`, + ); + assert.fileContent( + "CONTRIBUTING.md", + `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Be sure to run \`${result.generator.options.pkg} test\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${result.generator.options.pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${result.generator.options.pkg} contrib:add `, + ); + }); + + it("should create the correct CHANGELOG.md", () => { + assert.fileContent( + "CHANGELOG.md", + `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, + ); + }); + + it("should create the correct .all-contributorsrc", () => { + assert.fileContent( + ".all-contributorsrc", + `"projectName": "${result.generator.options.id}"`, + ); + }); + + it("should create the correct husky git hooks", () => { + assert.fileContent( + ".husky/commit-msg", + `${result.generator.options.pkg} commitlint --edit $1`, + ); + assert.fileContent( + ".husky/pre-commit", + `${result.generator.options.pkg} lint-staged`, + ); + }); + + it.skipIf(process.env.CI)( + "should create a git repository if git is true", + () => { + result.generator.options.git + ? assert.file(".git") + : assert.noFile(".git"); + }, + ); + + it("should always pass", () => { + expect(1).toEqual(1); + }); + }, + ); }); diff --git a/tests/typescript.test.ts b/tests/typescript.test.ts index 951f0c9..b941d0d 100644 --- a/tests/typescript.test.ts +++ b/tests/typescript.test.ts @@ -8,6 +8,7 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; +import { getNodeDependencyObject } from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -17,9 +18,39 @@ await ConfigHelper.initialize(config as UnresolvedConfig); const node = new NodeEnvironment(); await node.initialize(); -const { devDependencies, dependencies } = node.packageJson; const engine = node.getNodeEngine().split(".")[0]; +const devDependencies = [ + "@commitlint/config-conventional", + "@semantic-release/changelog", + "@semantic-release/git", + "@types/config", + "@types/node", + "@types/nodemon", + "@typescript-eslint/eslint-plugin", + "@typescript-eslint/parser", + "all-contributors-cli", + "commitizen", + "cross-env", + "cz-conventional-changelog", + "doctoc", + "eslint", + "eslint-config-prettier", + "husky", + "lint-staged", + "nodemon", + "prettier", + "rimraf", + "semantic-release", + "terser", + "tsup", + "type-fest", + "typescript", + "vitest", +]; + +const dependencies = ["config", "dotenv", "envalid"]; + const files = [ ".github/workflows/main.yml", ".github/dependabot.yml", @@ -57,11 +88,11 @@ const files = [ "vitest.config.ts", ]; -const lock = { - pnpm: "pnpm-lock.yaml", - npm: "package-lock.json", - yarn: "yarn.lock", -}; +// const lock = { +// pnpm: "pnpm-lock.yaml", +// npm: "package-lock.json", +// yarn: "yarn.lock", +// }; describe("generator-norgate-av:typescript", () => { describe.each([ @@ -157,50 +188,17 @@ describe("generator-norgate-av:typescript", () => { prebuild: `${pkg} clean`, prestart: `${pkg} lint && ${pkg} build`, }, - devDependencies: { - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/node": devDependencies!["@types/node"], - "@types/nodemon": devDependencies!["@types/nodemon"], - "@typescript-eslint/eslint-plugin": - devDependencies![ - "@typescript-eslint/eslint-plugin" - ], - "@typescript-eslint/parser": - devDependencies!["@typescript-eslint/parser"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cross-env": devDependencies!["cross-env"], - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - eslint: devDependencies!.eslint, - "eslint-config-prettier": - devDependencies!["eslint-config-prettier"], - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - nodemon: devDependencies!.nodemon, - prettier: devDependencies!.prettier, - rimraf: devDependencies!.rimraf, - "semantic-release": - devDependencies!["semantic-release"], - terser: devDependencies!.terser, - tsup: devDependencies!.tsup, - "type-fest": devDependencies!["type-fest"], - typescript: devDependencies!.typescript, - vitest: devDependencies!.vitest, - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); }); @@ -285,43 +283,43 @@ describe("generator-norgate-av:typescript", () => { }, ); - describe.skip("typescript:install", () => { - let result: RunResult; - - const name = "test"; - const description = "test-description"; - const pkg = "pnpm"; - - beforeAll(async () => { - result = await helpers - .create(generator) - .withOptions({ - skipInstall: false, - }) - .withAnswers({ - type: "typescript", - name, - description, - git: false, - pkg, - openWith: "skip", - }); - - process.chdir(name); - }, 200000); - - afterAll(() => { - result?.cleanup(); - }); - - it("should install packages using the correct package manager", () => { - assert.file(lock[pkg]); - }); - - it("should always pass", () => { - expect(1).toEqual(1); - }); - }); + // describe.skip("typescript:install", () => { + // let result: RunResult; + + // const name = "test"; + // const description = "test-description"; + // const pkg = "pnpm"; + + // beforeAll(async () => { + // result = await helpers + // .create(generator) + // .withOptions({ + // skipInstall: false, + // }) + // .withAnswers({ + // type: "typescript", + // name, + // description, + // git: false, + // pkg, + // openWith: "skip", + // }); + + // process.chdir(name); + // }, 200000); + + // afterAll(() => { + // result?.cleanup(); + // }); + + // it("should install packages using the correct package manager", () => { + // assert.file(lock[pkg]); + // }); + + // it("should always pass", () => { + // expect(1).toEqual(1); + // }); + // }); describe.each([ { @@ -417,50 +415,17 @@ describe("generator-norgate-av:typescript", () => { prebuild: `${pkg} clean`, prestart: `${pkg} lint && ${pkg} build`, }, - devDependencies: { - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/node": devDependencies!["@types/node"], - "@types/nodemon": devDependencies!["@types/nodemon"], - "@typescript-eslint/eslint-plugin": - devDependencies![ - "@typescript-eslint/eslint-plugin" - ], - "@typescript-eslint/parser": - devDependencies!["@typescript-eslint/parser"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cross-env": devDependencies!["cross-env"], - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - eslint: devDependencies!.eslint, - "eslint-config-prettier": - devDependencies!["eslint-config-prettier"], - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - nodemon: devDependencies!.nodemon, - prettier: devDependencies!.prettier, - rimraf: devDependencies!.rimraf, - "semantic-release": - devDependencies!["semantic-release"], - terser: devDependencies!.terser, - tsup: devDependencies!.tsup, - "type-fest": devDependencies!["type-fest"], - typescript: devDependencies!.typescript, - vitest: devDependencies!.vitest, - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); }); @@ -551,6 +516,16 @@ describe("generator-norgate-av:typescript", () => { type: "typescript", yes: true, }, + { + destination: "Test Project", + type: "ts", + yes: true, + }, + { + destination: "Test Project", + type: "node-ts", + yes: true, + }, ])( "cli: using all defaults, skipping prompts", ({ destination, type, yes }) => { @@ -606,50 +581,17 @@ describe("generator-norgate-av:typescript", () => { prebuild: `${result.generator.options.pkg} clean`, prestart: `${result.generator.options.pkg} lint && ${result.generator.options.pkg} build`, }, - devDependencies: { - "@commitlint/config-conventional": - devDependencies!["@commitlint/config-conventional"], - "@semantic-release/changelog": - devDependencies!["@semantic-release/changelog"], - "@semantic-release/git": - devDependencies!["@semantic-release/git"], - "@types/config": devDependencies!["@types/config"], - "@types/node": devDependencies!["@types/node"], - "@types/nodemon": devDependencies!["@types/nodemon"], - "@typescript-eslint/eslint-plugin": - devDependencies![ - "@typescript-eslint/eslint-plugin" - ], - "@typescript-eslint/parser": - devDependencies!["@typescript-eslint/parser"], - "all-contributors-cli": - devDependencies!["all-contributors-cli"], - commitizen: devDependencies!.commitizen, - "cross-env": devDependencies!["cross-env"], - "cz-conventional-changelog": - devDependencies!["cz-conventional-changelog"], - doctoc: devDependencies!.doctoc, - eslint: devDependencies!.eslint, - "eslint-config-prettier": - devDependencies!["eslint-config-prettier"], - husky: devDependencies!.husky, - "lint-staged": devDependencies!["lint-staged"], - nodemon: devDependencies!.nodemon, - prettier: devDependencies!.prettier, - rimraf: devDependencies!.rimraf, - "semantic-release": - devDependencies!["semantic-release"], - terser: devDependencies!.terser, - tsup: devDependencies!.tsup, - "type-fest": devDependencies!["type-fest"], - typescript: devDependencies!.typescript, - vitest: devDependencies!.vitest, - }, - dependencies: { - config: dependencies!.config, - dotenv: dependencies!.dotenv, - envalid: dependencies!.envalid, - }, + devDependencies: getNodeDependencyObject( + devDependencies, + node.packageJson.devDependencies as Record< + string, + string + >, + ), + dependencies: getNodeDependencyObject( + dependencies, + node.packageJson.dependencies as Record, + ), }); });